From f34c6a505f62056f774cecc259d9ab10acb1c1c2 Mon Sep 17 00:00:00 2001 From: Thomas Roos Date: Tue, 9 Jul 2024 12:31:08 +0000 Subject: [PATCH] aws-iot-device-sdk-cpp-v2: add fleet provisoning example --- ...ce-sdk-cpp-v2-samples-fleet-provisoning.bb | 25 +++++++++++++ .../run-ptest | 35 +++++++++++++++++++ .../aws-iot-device-sdk-cpp-v2_1.32.6.bb | 13 ++++--- 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning.bb create mode 100644 recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning/run-ptest diff --git a/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning.bb b/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning.bb new file mode 100644 index 000000000..d33603459 --- /dev/null +++ b/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning.bb @@ -0,0 +1,25 @@ +# nooelint: oelint.file.underscores +require aws-iot-device-sdk-cpp-v2-samples.inc + +S = "${WORKDIR}/git/samples/fleet_provisioning/fleet_provisioning" + +SRC_URI:append = " \ + file://run-ptest \ +" + +RDEPENDS:${PN}-ptest += "python3 aws-cli" + +do_install() { + install -d ${D}${bindir} + install ${B}/fleet-provisioning ${D}${bindir} +} + +inherit ptest pkgconfig + +do_install_ptest() { + install -d ${D}${PTEST_PATH}/tests + + install -m 0755 ${S}/../../../utils/parse_cert_set_result.py ${D}${PTEST_PATH}/ + + install -m 0755 ${WORKDIR}/run-ptest ${D}${PTEST_PATH}/ +} diff --git a/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning/run-ptest b/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning/run-ptest new file mode 100644 index 000000000..54d15d193 --- /dev/null +++ b/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning/run-ptest @@ -0,0 +1,35 @@ +#!/bin/sh +set -euxo pipefail +echo "nameserver 8.8.8.8" > /etc/resolv.conf + +DATE=$(date "+%F_%H-%M-%S") +ROLE="fprole_$DATE" +TEMPLATE="fptemplate_$DATE" +AWS_ACCOUNT_NUMBER=$(aws sts get-caller-identity --query "Account" --output text) +TEMPLATE_JSON='{"Parameters":{"DeviceLocation":{"Type":"String"},"AWS::IoT::Certificate::Id":{"Type":"String"},"SerialNumber":{"Type":"String"}},"Mappings":{"LocationTable":{"Seattle":{"LocationUrl":"https://example.aws"}}},"Resources":{"thing":{"Type":"AWS::IoT::Thing","Properties":{"ThingName":{"Fn::Join":["",["ThingPrefix_",{"Ref":"SerialNumber"}]]},"AttributePayload":{"version":"v1","serialNumber":"serialNumber"}},"OverrideSettings":{"AttributePayload":"MERGE","ThingTypeName":"REPLACE","ThingGroups":"DO_NOTHING"}},"certificate":{"Type":"AWS::IoT::Certificate","Properties":{"CertificateId":{"Ref":"AWS::IoT::Certificate::Id"},"Status":"Active"},"OverrideSettings":{"Status":"REPLACE"}},"policy":{"Type":"AWS::IoT::Policy","Properties":{"PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["iot:Connect","iot:Subscribe","iot:Publish","iot:Receive"],"Resource":"*"}]}}}},"DeviceConfiguration":{"FallbackUrl":"https://www.example.com/test-site","LocationUrl":{"Fn::FindInMap":["LocationTable",{"Ref":"DeviceLocation"},"LocationUrl"]}}}' +IOT_DATA_ENDPOINT=`aws --output text iot describe-endpoint --endpoint-type iot:Data-ATS` + +aws iam create-role \ + --role-name $ROLE \ + --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Action":"sts:AssumeRole","Effect":"Allow","Principal":{"Service":"iot.amazonaws.com"}}]}' + +aws iam attach-role-policy \ + --role-name $ROLE \ + --policy-arn arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration + +# wait for role to be populated +sleep 10 + +aws iot create-provisioning-template \ + --template-name $TEMPLATE \ + --provisioning-role-arn arn:aws:iam::$AWS_ACCOUNT_NUMBER:role/$ROLE \ + --template-body $TEMPLATE_JSON \ + --enabled + +aws iot create-provisioning-claim \ + --template-name $TEMPLATE \ + | python3 ./parse_cert_set_result.py \ + --path ./tmp \ + --filename provision + +fleet-provisioning --endpoint $IOT_DATA_ENDPOINT --cert ./tmp/provision.cert.pem --key ./tmp/provision.private.key --template_name $TEMPLATE --template_parameters '{"SerialNumber":"'$DATE'","DeviceLocation":"Seattle"}' diff --git a/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2_1.32.6.bb b/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2_1.32.6.bb index 542421628..07c58171a 100644 --- a/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2_1.32.6.bb +++ b/recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2_1.32.6.bb @@ -36,16 +36,15 @@ FILES_SOLIBSDEV = "" # enable PACKAGECONFIG = "static" to build static instead of shared libs PACKAGECONFIG[static] = "-DBUILD_SHARED_LIBS=OFF,-DBUILD_SHARED_LIBS=ON,," -# this does not work because: https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues/393 -# PACKAGECONFIG ??= "\ -# ${@bb.utils.contains('PTEST_ENABLED', '1', 'with-tests', '', d)} \ -# " -# PACKAGECONFIG[with-tests] = "-DBUILD_TESTING=ON,-DBUILD_TESTING=OFF," +PACKAGECONFIG ??= "\ + ${@bb.utils.contains('PTEST_ENABLED', '1', 'with-tests', '', d)} \ + " +PACKAGECONFIG[with-tests] = "-DBUILD_TESTING=ON,-DBUILD_TESTING=OFF," FILES:${PN}-dev += "${libdir}/*/cmake" -RDEPENDS:${PN}-ptest:prepend = "\ +RDEPENDS:${PN}-ptest += "\ aws-iot-device-sdk-cpp-v2-samples-mqtt5-pubsub \ - " +" BBCLASSEXTEND = "native nativesdk"