Path: blob/develop/awscli/customizations/codedeploy/locationargs.py
1567 views
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.1213from awscli.argprocess import unpack_cli_arg14from awscli.arguments import CustomArgument15from awscli.arguments import create_argument_model_from_schema1617S3_LOCATION_ARG_DESCRIPTION = {18'name': 's3-location',19'required': False,20'help_text': (21'Information about the location of the application revision in Amazon '22'S3. You must specify the bucket, the key, and bundleType. '23'Optionally, you can also specify an eTag and version.'24)25}2627S3_LOCATION_SCHEMA = {28"type": "object",29"properties": {30"bucket": {31"type": "string",32"description": "The Amazon S3 bucket name.",33"required": True34},35"key": {36"type": "string",37"description": "The Amazon S3 object key name.",38"required": True39},40"bundleType": {41"type": "string",42"description": "The format of the bundle stored in Amazon S3.",43"enum": ["tar", "tgz", "zip"],44"required": True45},46"eTag": {47"type": "string",48"description": "The Amazon S3 object eTag.",49"required": False50},51"version": {52"type": "string",53"description": "The Amazon S3 object version.",54"required": False55}56}57}5859GITHUB_LOCATION_ARG_DESCRIPTION = {60'name': 'github-location',61'required': False,62'help_text': (63'Information about the location of the application revision in '64'GitHub. You must specify the repository and commit ID that '65'references the application revision. For the repository, use the '66'format GitHub-account/repository-name or GitHub-org/repository-name. '67'For the commit ID, use the SHA1 Git commit reference.'68)69}7071GITHUB_LOCATION_SCHEMA = {72"type": "object",73"properties": {74"repository": {75"type": "string",76"description": (77"The GitHub account or organization and repository. Specify "78"as GitHub-account/repository or GitHub-org/repository."79),80"required": True81},82"commitId": {83"type": "string",84"description": "The SHA1 Git commit reference.",85"required": True86}87}88}899091def modify_revision_arguments(argument_table, session, **kwargs):92s3_model = create_argument_model_from_schema(S3_LOCATION_SCHEMA)93argument_table[S3_LOCATION_ARG_DESCRIPTION['name']] = (94S3LocationArgument(95argument_model=s3_model,96session=session,97**S3_LOCATION_ARG_DESCRIPTION98)99)100github_model = create_argument_model_from_schema(GITHUB_LOCATION_SCHEMA)101argument_table[GITHUB_LOCATION_ARG_DESCRIPTION['name']] = (102GitHubLocationArgument(103argument_model=github_model,104session=session,105**GITHUB_LOCATION_ARG_DESCRIPTION106)107)108argument_table['revision'].required = False109110111class LocationArgument(CustomArgument):112def __init__(self, session, *args, **kwargs):113super(LocationArgument, self).__init__(*args, **kwargs)114self._session = session115116def add_to_params(self, parameters, value):117if value is None:118return119parsed = self._session.emit_first_non_none_response(120'process-cli-arg.codedeploy.%s' % self.name,121param=self.argument_model,122cli_argument=self,123value=value,124operation=None125)126if parsed is None:127parsed = unpack_cli_arg(self, value)128parameters['revision'] = self.build_revision_location(parsed)129130def build_revision_location(self, value_dict):131"""132Repack the input structure into a revisionLocation.133"""134raise NotImplementedError("build_revision_location")135136137class S3LocationArgument(LocationArgument):138def build_revision_location(self, value_dict):139required = ['bucket', 'key', 'bundleType']140valid = lambda k: value_dict.get(k, False)141if not all(map(valid, required)):142raise RuntimeError(143'--s3-location must specify bucket, key and bundleType.'144)145revision = {146"revisionType": "S3",147"s3Location": {148"bucket": value_dict['bucket'],149"key": value_dict['key'],150"bundleType": value_dict['bundleType']151}152}153if 'eTag' in value_dict:154revision['s3Location']['eTag'] = value_dict['eTag']155if 'version' in value_dict:156revision['s3Location']['version'] = value_dict['version']157return revision158159160class GitHubLocationArgument(LocationArgument):161def build_revision_location(self, value_dict):162required = ['repository', 'commitId']163valid = lambda k: value_dict.get(k, False)164if not all(map(valid, required)):165raise RuntimeError(166'--github-location must specify repository and commitId.'167)168return {169"revisionType": "GitHub",170"gitHubLocation": {171"repository": value_dict['repository'],172"commitId": value_dict['commitId']173}174}175176177