diff --git a/schema/samcli.json b/schema/samcli.json index cda45947bf..74ac8d6eca 100644 --- a/schema/samcli.json +++ b/schema/samcli.json @@ -143,9 +143,169 @@ "properties": { "parameters": { "title": "Parameters for the deploy command", - "description": "Available parameters for the deploy command:\n", + "description": "Available parameters for the deploy command:\n* guided:\nSpecify this flag to allow SAM CLI to guide you through the deployment using guided prompts.\n* template_file:\nAWS SAM template which references built artifacts for resources in the template. (if applicable)\n* no_execute_changeset:\nIndicates whether to execute the change set. Specify this flag to view stack changes before executing the change set.\n* fail_on_empty_changeset:\nSpecify whether AWS SAM CLI should return a non-zero exit code if there are no changes to be made to the stack. Defaults to a non-zero exit code.\n* confirm_changeset:\nPrompt to confirm if the computed changeset is to be deployed by SAM CLI.\n* disable_rollback:\nPreserves the state of previously provisioned resources when an operation fails.\n* on_failure:\nProvide an action to determine what will happen when a stack fails to create. Three actions are available:\n\n- ROLLBACK: This will rollback a stack to a previous known good state.\n\n- DELETE: The stack will rollback to a previous state if one exists, otherwise the stack will be deleted.\n\n- DO_NOTHING: The stack will not rollback or delete, this is the same as disabling rollback.\n\nDefault behaviour is ROLLBACK.\n\n\n\nThis option is mutually exclusive with --disable-rollback/--no-disable-rollback. You can provide\n--on-failure or --disable-rollback/--no-disable-rollback but not both at the same time.\n* stack_name:\nName of the AWS CloudFormation stack.\n* s3_bucket:\nAWS S3 bucket where artifacts referenced in the template are uploaded.\n* image_repository:\nAWS ECR repository URI where artifacts referenced in the template are uploaded.\n* image_repositories:\nMapping of Function Logical ID to AWS ECR Repository URI.\n\nExample: Function_Logical_ID=ECR_Repo_Uri\nThis option can be specified multiple times.\n* force_upload:\nIndicates whether to override existing files in the S3 bucket. Specify this flag to upload artifacts even if they match existing artifacts in the S3 bucket.\n* s3_prefix:\nPrefix name that is added to the artifact's name when it is uploaded to the AWS S3 bucket.\n* kms_key_id:\nThe ID of an AWS KMS key that is used to encrypt artifacts that are at rest in the AWS S3 bucket.\n* role_arn:\nARN of an IAM role that AWS Cloudformation assumes when executing a deployment change set.\n* use_json:\nIndicates whether to use JSON as the format for the output AWS CloudFormation template. YAML is used by default.\n* resolve_s3:\nAutomatically resolve AWS S3 bucket for non-guided deployments. Enabling this option will also create a managed default AWS S3 bucket for you. If one does not provide a --s3-bucket value, the managed bucket will be used. Do not use --guided with this option.\n* resolve_image_repos:\nAutomatically create and delete ECR repositories for image-based functions in non-guided deployments. A companion stack containing ECR repos for each function will be deployed along with the template stack. Automatically created image repositories will be deleted if the corresponding functions are removed.\n* metadata:\nMap of metadata to attach to ALL the artifacts that are referenced in the template.\n* notification_arns:\nARNs of SNS topics that AWS Cloudformation associates with the stack.\n* tags:\nList of tags to associate with the stack.\n* parameter_overrides:\nString that contains AWS CloudFormation parameter overrides encoded as key=value pairs.\n* signing_profiles:\nA string that contains Code Sign configuration parameters as FunctionOrLayerNameToSign=SigningProfileName:SigningProfileOwner Since signing profile owner is optional, it could also be written as FunctionOrLayerNameToSign=SigningProfileName\n* no_progressbar:\nDoes not showcase a progress bar when uploading artifacts to S3 and pushing docker images to ECR\n* capabilities:\nList of capabilities that one must specify before AWS Cloudformation can create certain stacks.\n\nAccepted Values: CAPABILITY_IAM, CAPABILITY_NAMED_IAM, CAPABILITY_RESOURCE_POLICY, CAPABILITY_AUTO_EXPAND.\n\nLearn more at: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/acknowledging-application-capabilities.html\n* profile:\nSelect a specific profile from your credential file to get AWS credentials.\n* region:\nSet the AWS Region of the service. (e.g. us-east-1)\n* beta_features:\nEnable/Disable beta features.\n* debug:\nTurn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.", "type": "object", - "properties": {} + "properties": { + "guided": { + "title": "guided", + "type": "boolean", + "description": "Specify this flag to allow SAM CLI to guide you through the deployment using guided prompts." + }, + "template_file": { + "title": "template_file", + "type": "string", + "description": "AWS SAM template which references built artifacts for resources in the template. (if applicable)", + "default": "template.[yaml|yml|json]" + }, + "no_execute_changeset": { + "title": "no_execute_changeset", + "type": "boolean", + "description": "Indicates whether to execute the change set. Specify this flag to view stack changes before executing the change set." + }, + "fail_on_empty_changeset": { + "title": "fail_on_empty_changeset", + "type": "boolean", + "description": "Specify whether AWS SAM CLI should return a non-zero exit code if there are no changes to be made to the stack. Defaults to a non-zero exit code.", + "default": true + }, + "confirm_changeset": { + "title": "confirm_changeset", + "type": "boolean", + "description": "Prompt to confirm if the computed changeset is to be deployed by SAM CLI." + }, + "disable_rollback": { + "title": "disable_rollback", + "type": "boolean", + "description": "Preserves the state of previously provisioned resources when an operation fails." + }, + "on_failure": { + "title": "on_failure", + "type": "string", + "description": "Provide an action to determine what will happen when a stack fails to create. Three actions are available:\n\n- ROLLBACK: This will rollback a stack to a previous known good state.\n\n- DELETE: The stack will rollback to a previous state if one exists, otherwise the stack will be deleted.\n\n- DO_NOTHING: The stack will not rollback or delete, this is the same as disabling rollback.\n\nDefault behaviour is ROLLBACK.\n\n\n\nThis option is mutually exclusive with --disable-rollback/--no-disable-rollback. You can provide\n--on-failure or --disable-rollback/--no-disable-rollback but not both at the same time.", + "default": "ROLLBACK", + "enum": [ + "ROLLBACK", + "DELETE", + "DO_NOTHING" + ] + }, + "stack_name": { + "title": "stack_name", + "type": "string", + "description": "Name of the AWS CloudFormation stack." + }, + "s3_bucket": { + "title": "s3_bucket", + "type": "string", + "description": "AWS S3 bucket where artifacts referenced in the template are uploaded." + }, + "image_repository": { + "title": "image_repository", + "type": "string", + "description": "AWS ECR repository URI where artifacts referenced in the template are uploaded." + }, + "image_repositories": { + "title": "image_repositories", + "type": "string", + "description": "Mapping of Function Logical ID to AWS ECR Repository URI.\n\nExample: Function_Logical_ID=ECR_Repo_Uri\nThis option can be specified multiple times." + }, + "force_upload": { + "title": "force_upload", + "type": "boolean", + "description": "Indicates whether to override existing files in the S3 bucket. Specify this flag to upload artifacts even if they match existing artifacts in the S3 bucket." + }, + "s3_prefix": { + "title": "s3_prefix", + "type": "string", + "description": "Prefix name that is added to the artifact's name when it is uploaded to the AWS S3 bucket." + }, + "kms_key_id": { + "title": "kms_key_id", + "type": "string", + "description": "The ID of an AWS KMS key that is used to encrypt artifacts that are at rest in the AWS S3 bucket." + }, + "role_arn": { + "title": "role_arn", + "type": "string", + "description": "ARN of an IAM role that AWS Cloudformation assumes when executing a deployment change set." + }, + "use_json": { + "title": "use_json", + "type": "boolean", + "description": "Indicates whether to use JSON as the format for the output AWS CloudFormation template. YAML is used by default." + }, + "resolve_s3": { + "title": "resolve_s3", + "type": "boolean", + "description": "Automatically resolve AWS S3 bucket for non-guided deployments. Enabling this option will also create a managed default AWS S3 bucket for you. If one does not provide a --s3-bucket value, the managed bucket will be used. Do not use --guided with this option." + }, + "resolve_image_repos": { + "title": "resolve_image_repos", + "type": "boolean", + "description": "Automatically create and delete ECR repositories for image-based functions in non-guided deployments. A companion stack containing ECR repos for each function will be deployed along with the template stack. Automatically created image repositories will be deleted if the corresponding functions are removed." + }, + "metadata": { + "title": "metadata", + "type": "string", + "description": "Map of metadata to attach to ALL the artifacts that are referenced in the template." + }, + "notification_arns": { + "title": "notification_arns", + "type": "array", + "description": "ARNs of SNS topics that AWS Cloudformation associates with the stack.", + "items": { + "type": "string" + } + }, + "tags": { + "title": "tags", + "type": "string", + "description": "List of tags to associate with the stack." + }, + "parameter_overrides": { + "title": "parameter_overrides", + "type": "string", + "description": "String that contains AWS CloudFormation parameter overrides encoded as key=value pairs." + }, + "signing_profiles": { + "title": "signing_profiles", + "type": "string", + "description": "A string that contains Code Sign configuration parameters as FunctionOrLayerNameToSign=SigningProfileName:SigningProfileOwner Since signing profile owner is optional, it could also be written as FunctionOrLayerNameToSign=SigningProfileName" + }, + "no_progressbar": { + "title": "no_progressbar", + "type": "boolean", + "description": "Does not showcase a progress bar when uploading artifacts to S3 and pushing docker images to ECR" + }, + "capabilities": { + "title": "capabilities", + "type": "array", + "description": "List of capabilities that one must specify before AWS Cloudformation can create certain stacks.\n\nAccepted Values: CAPABILITY_IAM, CAPABILITY_NAMED_IAM, CAPABILITY_RESOURCE_POLICY, CAPABILITY_AUTO_EXPAND.\n\nLearn more at: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/acknowledging-application-capabilities.html", + "items": { + "type": "string" + } + }, + "profile": { + "title": "profile", + "type": "string", + "description": "Select a specific profile from your credential file to get AWS credentials." + }, + "region": { + "title": "region", + "type": "string", + "description": "Set the AWS Region of the service. (e.g. us-east-1)" + }, + "beta_features": { + "title": "beta_features", + "type": "boolean", + "description": "Enable/Disable beta features." + }, + "debug": { + "title": "debug", + "type": "boolean", + "description": "Turn on debug logging to print debug message generated by AWS SAM CLI and display timestamps." + } + } } }, "required": [ diff --git a/schema/schema.py b/schema/schema.py index 9741f21db6..02f909cd75 100644 --- a/schema/schema.py +++ b/schema/schema.py @@ -32,14 +32,17 @@ class SamCliParameterSchema: type: str description: str = "" default: Optional[Any] = None + items: Optional[str] = None choices: Optional[Any] = None def to_schema(self) -> Dict[str, Any]: """Return the JSON schema representation of the SAM CLI parameter.""" - param = {} + param: Dict[str, Any] = {} param.update({"title": self.name, "type": self.type, "description": self.description}) if self.default: param.update({"default": self.default}) + if self.items: + param.update({"items": {"type": self.items}}) if self.choices: param.update({"enum": self.choices}) return param @@ -136,7 +139,10 @@ def format_param(param: click.core.Option) -> SamCliParameterSchema: formatted_param_type = param_type or "string" formatted_param: SamCliParameterSchema = SamCliParameterSchema( - param.name or "", formatted_param_type, clean_text(param.help or "") + param.name or "", + formatted_param_type, + clean_text(param.help or ""), + items="string" if formatted_param_type == "array" else None, ) if param.default: @@ -150,7 +156,15 @@ def format_param(param: click.core.Option) -> SamCliParameterSchema: def get_params_from_command(cli) -> List[SamCliParameterSchema]: """Given a CLI object, return a list of all parameters in that CLI, formatted as SamCliParameterSchema objects.""" - return [format_param(param) for param in cli.params if param.name and isinstance(param, click.core.Option)] + params_to_exclude = [ + "config_env", # shouldn't allow different environment from where the config is being read from + "config_file", # shouldn't allow reading another file within current file + ] + return [ + format_param(param) + for param in cli.params + if param.name and isinstance(param, click.core.Option) and param.name not in params_to_exclude + ] def retrieve_command_structure(package_name: str) -> List[SamCliCommandSchema]: