diff --git a/events/iot_preprovision_hook.go b/events/iot_preprovision_hook.go new file mode 100644 index 00000000..fb115699 --- /dev/null +++ b/events/iot_preprovision_hook.go @@ -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"` +} diff --git a/events/iot_preprovision_hook_test.go b/events/iot_preprovision_hook_test.go new file mode 100644 index 00000000..09d7e490 --- /dev/null +++ b/events/iot_preprovision_hook_test.go @@ -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{}) +} diff --git a/events/testdata/iot-preprovision-hook-request.json b/events/testdata/iot-preprovision-hook-request.json new file mode 100644 index 00000000..96f40cf1 --- /dev/null +++ b/events/testdata/iot-preprovision-hook-request.json @@ -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" + } +} \ No newline at end of file diff --git a/events/testdata/iot-preprovision-hook-response.json b/events/testdata/iot-preprovision-hook-response.json new file mode 100644 index 00000000..2b803580 --- /dev/null +++ b/events/testdata/iot-preprovision-hook-response.json @@ -0,0 +1,7 @@ +{ + "allowProvisioning": true, + "parameterOverrides" : { + "Key1": "newCustomValue1", + "Key2": "newCustomValue2" + } +} \ No newline at end of file