#!/usr/bin/env python3 # Copyright 2010-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of # the License is located at # # http://aws.amazon.com/apache2.0/ # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. """ Returns the HTML form for the user to input the properties to configure the IoT Thing and Greengrass provisioning. """ # Import the helper functions from the layer import os import boto3 from ggi_lambda_utils import * # S3 bucket containing the template documents THING_S3_BUCKET = os.environ.get("S3_BUCKET_THING_TEMPLATES") if not THING_S3_BUCKET: raise Exception("Environment variable S3_BUCKET_THING_TEMPLATES missing") # S3 bucket containing the greengrass configuration files GG_S3_BUCKET = os.environ.get("S3_BUCKET_GG_CONFIGS") if not GG_S3_BUCKET: raise Exception("Environment variable S3_BUCKET_GG_CONFIGS missing") S3_RESOURCES = os.environ.get("S3_RESOURCES_BUCKET") if not S3_RESOURCES: raise Exception("Environment variable S3_RESOURCES_BUCKET missing") def make_html_dropdown(item_id: str, label: str, choices: list[str]): dropdown = '\n'.format(item_id, label) dropdown += '' return dropdown def get_form_html(resource_path: str, code: str, thing_name: str = "", serial: str = "", message: str = "", install_scripts: list[str] = [], prov_tplts: list[str] = [], gg_configs: list[str] = []) -> str: """ :param install_scripts: A list of provisioning templates to build a dropdown from :param gg_configs: A list of configuration files to build a dropdown from :param prov_tplts: A list of provisioning templates to build a dropdown from :param resource_path: API Gateway URL to POST the form when submitted :param code: Authorisation code to be exchanged later for a token :param thing_name: AWS IoT Thing name to be created :param serial: A string for identifying the Device, like a serial number :param message: Message to be displayed on the form :return: HTML document as a string """ install_scripts_dropdown = make_html_dropdown(item_id="installScript", label="Select the Installation Script:", choices=install_scripts) gg_configs_dropdown = make_html_dropdown(item_id="greengrasConfigFile", label="Select the Greengrass Configuration File:", choices=gg_configs ) prov_tplts_dropdown = make_html_dropdown(item_id="thingProvisioningTemplate", label="Select the Thing Provisioning Template:", choices=prov_tplts ) action = "{}?code={}".format(resource_path, code) html = '''
{3}