-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IoT Pre-provisioning hook Request and Reponse structs (#483)
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"allowProvisioning": true, | ||
"parameterOverrides" : { | ||
"Key1": "newCustomValue1", | ||
"Key2": "newCustomValue2" | ||
} | ||
} |