Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IoT Pre-provisioning hook Request and Response structs #483

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions events/iot_preprovision_hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package events

// IoTPreProvisionHookRequest contains the request parameters for the IoT Pre-Provisioning Hook.
// See https://docs.aws.amazon.com/iot/latest/developerguide/pre-provisioning-hook.html
type IoTPreProvisionHookRequest struct {
ClaimCertificateID string `json:"claimCertificateId"`
CertificateID string `json:"certificateId"`
CertificatePEM string `json:"certificatePem"`
TemplateARN string `json:"templateArn"`
ClientID string `json:"clientId"`
Parameters map[string]string `json:"parameters"`
}

// IoTPreProvisionHookResponse contains the response parameters for the IoT Pre-Provisioning Hook.
// See https://docs.aws.amazon.com/iot/latest/developerguide/pre-provisioning-hook.html
type IoTPreProvisionHookResponse struct {
AllowProvisioning bool `json:"allowProvisioning"`
ParameterOverrides map[string]string `json:"parameterOverrides"`
}
63 changes: 63 additions & 0 deletions events/iot_preprovision_hook_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package events

import (
"encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

"github.com/aws/aws-lambda-go/events/test"
)

func TestIoTPreProvisionHookRequest(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/iot-preprovision-hook-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

// de-serialize into Go object
var inputEvent IoTPreProvisionHookRequest
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// serialize to json
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

test.AssertJsonsEqual(t, inputJSON, outputJSON)
}

func TestIoTPreProvisionHookRequestMalformedJson(t *testing.T) {
test.TestMalformedJson(t, IoTPreProvisionHookRequest{})
}

func TestIoTPreProvisionHookResponseMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/iot-preprovision-hook-response.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

// de-serialize into Go object
var inputEvent IoTPreProvisionHookResponse
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// serialize to json
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

test.AssertJsonsEqual(t, inputJSON, outputJSON)
}

func TestIoTPreProvisionHookResponseMalformedJson(t *testing.T) {
test.TestMalformedJson(t, IoTPreProvisionHookResponse{})
}
11 changes: 11 additions & 0 deletions events/testdata/iot-preprovision-hook-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"claimCertificateId" : "string",
"certificateId" : "string",
"certificatePem" : "string",
"templateArn" : "arn:aws:iot:us-east-1:1234567890:provisioningtemplate/MyTemplate",
"clientId" : "221a6d10-9c7f-42f1-9153-e52e6fc869c1",
"parameters" : {
"param1" : "parma1value",
"param2" : "param2value"
}
}
7 changes: 7 additions & 0 deletions events/testdata/iot-preprovision-hook-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"allowProvisioning": true,
"parameterOverrides" : {
"Key1": "newCustomValue1",
"Key2": "newCustomValue2"
}
}