Skip to content

Commit 3dedc32

Browse files
authored
Add IoT Pre-provisioning hook Request and Reponse structs (#483)
1 parent 0d45ea2 commit 3dedc32

4 files changed

+100
-0
lines changed

events/iot_preprovision_hook.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package events
2+
3+
// IoTPreProvisionHookRequest contains the request parameters for the IoT Pre-Provisioning Hook.
4+
// See https://docs.aws.amazon.com/iot/latest/developerguide/pre-provisioning-hook.html
5+
type IoTPreProvisionHookRequest struct {
6+
ClaimCertificateID string `json:"claimCertificateId"`
7+
CertificateID string `json:"certificateId"`
8+
CertificatePEM string `json:"certificatePem"`
9+
TemplateARN string `json:"templateArn"`
10+
ClientID string `json:"clientId"`
11+
Parameters map[string]string `json:"parameters"`
12+
}
13+
14+
// IoTPreProvisionHookResponse contains the response parameters for the IoT Pre-Provisioning Hook.
15+
// See https://docs.aws.amazon.com/iot/latest/developerguide/pre-provisioning-hook.html
16+
type IoTPreProvisionHookResponse struct {
17+
AllowProvisioning bool `json:"allowProvisioning"`
18+
ParameterOverrides map[string]string `json:"parameterOverrides"`
19+
}

events/iot_preprovision_hook_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package events
2+
3+
import (
4+
"encoding/json"
5+
"io/ioutil" //nolint: staticcheck
6+
"testing"
7+
8+
"github.com/aws/aws-lambda-go/events/test"
9+
)
10+
11+
func TestIoTPreProvisionHookRequest(t *testing.T) {
12+
13+
// read json from file
14+
inputJSON, err := ioutil.ReadFile("./testdata/iot-preprovision-hook-request.json")
15+
if err != nil {
16+
t.Errorf("could not open test file. details: %v", err)
17+
}
18+
19+
// de-serialize into Go object
20+
var inputEvent IoTPreProvisionHookRequest
21+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
22+
t.Errorf("could not unmarshal event. details: %v", err)
23+
}
24+
25+
// serialize to json
26+
outputJSON, err := json.Marshal(inputEvent)
27+
if err != nil {
28+
t.Errorf("could not marshal event. details: %v", err)
29+
}
30+
31+
test.AssertJsonsEqual(t, inputJSON, outputJSON)
32+
}
33+
34+
func TestIoTPreProvisionHookRequestMalformedJson(t *testing.T) {
35+
test.TestMalformedJson(t, IoTPreProvisionHookRequest{})
36+
}
37+
38+
func TestIoTPreProvisionHookResponseMarshaling(t *testing.T) {
39+
40+
// read json from file
41+
inputJSON, err := ioutil.ReadFile("./testdata/iot-preprovision-hook-response.json")
42+
if err != nil {
43+
t.Errorf("could not open test file. details: %v", err)
44+
}
45+
46+
// de-serialize into Go object
47+
var inputEvent IoTPreProvisionHookResponse
48+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
49+
t.Errorf("could not unmarshal event. details: %v", err)
50+
}
51+
52+
// serialize to json
53+
outputJSON, err := json.Marshal(inputEvent)
54+
if err != nil {
55+
t.Errorf("could not marshal event. details: %v", err)
56+
}
57+
58+
test.AssertJsonsEqual(t, inputJSON, outputJSON)
59+
}
60+
61+
func TestIoTPreProvisionHookResponseMalformedJson(t *testing.T) {
62+
test.TestMalformedJson(t, IoTPreProvisionHookResponse{})
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"claimCertificateId" : "string",
3+
"certificateId" : "string",
4+
"certificatePem" : "string",
5+
"templateArn" : "arn:aws:iot:us-east-1:1234567890:provisioningtemplate/MyTemplate",
6+
"clientId" : "221a6d10-9c7f-42f1-9153-e52e6fc869c1",
7+
"parameters" : {
8+
"param1" : "parma1value",
9+
"param2" : "param2value"
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"allowProvisioning": true,
3+
"parameterOverrides" : {
4+
"Key1": "newCustomValue1",
5+
"Key2": "newCustomValue2"
6+
}
7+
}

0 commit comments

Comments
 (0)