Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/codedeploy/locationargs.py
1567 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
from awscli.argprocess import unpack_cli_arg
15
from awscli.arguments import CustomArgument
16
from awscli.arguments import create_argument_model_from_schema
17
18
S3_LOCATION_ARG_DESCRIPTION = {
19
'name': 's3-location',
20
'required': False,
21
'help_text': (
22
'Information about the location of the application revision in Amazon '
23
'S3. You must specify the bucket, the key, and bundleType. '
24
'Optionally, you can also specify an eTag and version.'
25
)
26
}
27
28
S3_LOCATION_SCHEMA = {
29
"type": "object",
30
"properties": {
31
"bucket": {
32
"type": "string",
33
"description": "The Amazon S3 bucket name.",
34
"required": True
35
},
36
"key": {
37
"type": "string",
38
"description": "The Amazon S3 object key name.",
39
"required": True
40
},
41
"bundleType": {
42
"type": "string",
43
"description": "The format of the bundle stored in Amazon S3.",
44
"enum": ["tar", "tgz", "zip"],
45
"required": True
46
},
47
"eTag": {
48
"type": "string",
49
"description": "The Amazon S3 object eTag.",
50
"required": False
51
},
52
"version": {
53
"type": "string",
54
"description": "The Amazon S3 object version.",
55
"required": False
56
}
57
}
58
}
59
60
GITHUB_LOCATION_ARG_DESCRIPTION = {
61
'name': 'github-location',
62
'required': False,
63
'help_text': (
64
'Information about the location of the application revision in '
65
'GitHub. You must specify the repository and commit ID that '
66
'references the application revision. For the repository, use the '
67
'format GitHub-account/repository-name or GitHub-org/repository-name. '
68
'For the commit ID, use the SHA1 Git commit reference.'
69
)
70
}
71
72
GITHUB_LOCATION_SCHEMA = {
73
"type": "object",
74
"properties": {
75
"repository": {
76
"type": "string",
77
"description": (
78
"The GitHub account or organization and repository. Specify "
79
"as GitHub-account/repository or GitHub-org/repository."
80
),
81
"required": True
82
},
83
"commitId": {
84
"type": "string",
85
"description": "The SHA1 Git commit reference.",
86
"required": True
87
}
88
}
89
}
90
91
92
def modify_revision_arguments(argument_table, session, **kwargs):
93
s3_model = create_argument_model_from_schema(S3_LOCATION_SCHEMA)
94
argument_table[S3_LOCATION_ARG_DESCRIPTION['name']] = (
95
S3LocationArgument(
96
argument_model=s3_model,
97
session=session,
98
**S3_LOCATION_ARG_DESCRIPTION
99
)
100
)
101
github_model = create_argument_model_from_schema(GITHUB_LOCATION_SCHEMA)
102
argument_table[GITHUB_LOCATION_ARG_DESCRIPTION['name']] = (
103
GitHubLocationArgument(
104
argument_model=github_model,
105
session=session,
106
**GITHUB_LOCATION_ARG_DESCRIPTION
107
)
108
)
109
argument_table['revision'].required = False
110
111
112
class LocationArgument(CustomArgument):
113
def __init__(self, session, *args, **kwargs):
114
super(LocationArgument, self).__init__(*args, **kwargs)
115
self._session = session
116
117
def add_to_params(self, parameters, value):
118
if value is None:
119
return
120
parsed = self._session.emit_first_non_none_response(
121
'process-cli-arg.codedeploy.%s' % self.name,
122
param=self.argument_model,
123
cli_argument=self,
124
value=value,
125
operation=None
126
)
127
if parsed is None:
128
parsed = unpack_cli_arg(self, value)
129
parameters['revision'] = self.build_revision_location(parsed)
130
131
def build_revision_location(self, value_dict):
132
"""
133
Repack the input structure into a revisionLocation.
134
"""
135
raise NotImplementedError("build_revision_location")
136
137
138
class S3LocationArgument(LocationArgument):
139
def build_revision_location(self, value_dict):
140
required = ['bucket', 'key', 'bundleType']
141
valid = lambda k: value_dict.get(k, False)
142
if not all(map(valid, required)):
143
raise RuntimeError(
144
'--s3-location must specify bucket, key and bundleType.'
145
)
146
revision = {
147
"revisionType": "S3",
148
"s3Location": {
149
"bucket": value_dict['bucket'],
150
"key": value_dict['key'],
151
"bundleType": value_dict['bundleType']
152
}
153
}
154
if 'eTag' in value_dict:
155
revision['s3Location']['eTag'] = value_dict['eTag']
156
if 'version' in value_dict:
157
revision['s3Location']['version'] = value_dict['version']
158
return revision
159
160
161
class GitHubLocationArgument(LocationArgument):
162
def build_revision_location(self, value_dict):
163
required = ['repository', 'commitId']
164
valid = lambda k: value_dict.get(k, False)
165
if not all(map(valid, required)):
166
raise RuntimeError(
167
'--github-location must specify repository and commitId.'
168
)
169
return {
170
"revisionType": "GitHub",
171
"gitHubLocation": {
172
"repository": value_dict['repository'],
173
"commitId": value_dict['commitId']
174
}
175
}
176
177