forked from aws/aws-sam-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
199 lines (182 loc) · 5.64 KB
/
Copy pathcommand.py
File metadata and controls
199 lines (182 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"""
CLI command for "package" command
"""
import click
from samcli.cli.cli_config_file import ConfigProvider, configuration_option, save_params_option
from samcli.cli.main import aws_creds_options, common_options, pass_context, print_cmdline_args
from samcli.commands._utils.cdk_support_decorators import unsupported_command_cdk
from samcli.commands._utils.command_exception_handler import command_exception_handler
from samcli.commands._utils.options import (
force_upload_option,
image_repositories_option,
image_repository_option,
kms_key_id_option,
metadata_option,
no_progressbar_option,
resolve_image_repos_option,
resolve_s3_option,
s3_bucket_option,
s3_prefix_option,
signing_profiles_option,
template_click_option,
use_json_option,
)
from samcli.commands.package.core.command import PackageCommand
from samcli.lib.bootstrap.bootstrap import manage_stack, print_managed_s3_bucket_info
from samcli.lib.cli_validation.image_repository_validation import image_repository_validation
from samcli.lib.telemetry.metric import track_command, track_template_warnings
from samcli.lib.utils.resources import resources_generator
from samcli.lib.utils.version_checker import check_newer_version
from samcli.lib.warnings.sam_cli_warning import CodeDeployConditionWarning, CodeDeployWarning
SHORT_HELP = "Package an AWS SAM application."
def resources_and_properties_help_string():
"""
Total list of resources and their property locations that are supported for `sam package`
:return: str
"""
return "".join(
f"\nResource : {resource} | Location : {location}\n".format(resource=resource, location=location)
for resource, location in resources_generator()
)
DESCRIPTION = """
Creates and uploads artifacts based on the package type of a given resource.
It uploads local images to ECR for `Image` package types.
It creates a zip of code and dependencies and uploads it to S3 for `Zip` package types.
A new template is returned which replaces references to local artifacts
with the AWS location where the command uploaded the artifacts.
"""
@click.command(
"package",
short_help=SHORT_HELP,
context_settings={
"ignore_unknown_options": False,
"allow_interspersed_args": True,
"allow_extra_args": True,
"max_content_width": 120,
},
cls=PackageCommand,
help=SHORT_HELP,
description=DESCRIPTION,
requires_credentials=True,
)
@configuration_option(provider=ConfigProvider(section="parameters"))
@template_click_option(include_build=True)
@click.option(
"--output-template-file",
required=False,
type=click.Path(),
help="The path to the file where the command "
"writes the output AWS CloudFormation template. If you don't specify a "
"path, the command writes the template to the standard output.",
)
@s3_bucket_option
@image_repository_option
@image_repositories_option
@s3_prefix_option
@kms_key_id_option
@use_json_option
@force_upload_option
@resolve_s3_option
@resolve_image_repos_option
@metadata_option
@signing_profiles_option
@no_progressbar_option
@common_options
@aws_creds_options
@save_params_option
@image_repository_validation(support_resolve_image_repos=True)
@pass_context
@track_command
@check_newer_version
@track_template_warnings([CodeDeployWarning.__name__, CodeDeployConditionWarning.__name__])
@print_cmdline_args
@unsupported_command_cdk(alternative_command="cdk deploy")
@command_exception_handler
def cli(
ctx,
template_file,
s3_bucket,
image_repository,
image_repositories,
s3_prefix,
kms_key_id,
output_template_file,
use_json,
force_upload,
no_progressbar,
metadata,
signing_profiles,
resolve_s3,
resolve_image_repos,
save_params,
config_file,
config_env,
):
"""
`sam package` command entry point
"""
# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing
do_cli(
template_file,
s3_bucket,
image_repository,
image_repositories,
s3_prefix,
kms_key_id,
output_template_file,
use_json,
force_upload,
no_progressbar,
metadata,
signing_profiles,
ctx.region,
ctx.profile,
resolve_s3,
resolve_image_repos,
) # pragma: no cover
def do_cli(
template_file,
s3_bucket,
image_repository,
image_repositories,
s3_prefix,
kms_key_id,
output_template_file,
use_json,
force_upload,
no_progressbar,
metadata,
signing_profiles,
region,
profile,
resolve_s3,
resolve_image_repos,
):
"""
Implementation of the ``cli`` method
"""
from samcli.commands.package.exceptions import PackageResolveS3AndS3NotSetError
from samcli.commands.package.package_context import PackageContext
if resolve_s3:
s3_bucket = manage_stack(profile=profile, region=region)
print_managed_s3_bucket_info(s3_bucket)
if resolve_image_repos and not s3_bucket:
raise PackageResolveS3AndS3NotSetError()
with PackageContext(
template_file=template_file,
s3_bucket=s3_bucket,
image_repository=image_repository,
image_repositories=image_repositories,
s3_prefix=s3_prefix,
kms_key_id=kms_key_id,
output_template_file=output_template_file,
use_json=use_json,
force_upload=force_upload,
no_progressbar=no_progressbar,
metadata=metadata,
region=region,
profile=profile,
signing_profiles=signing_profiles,
resolve_image_repos=resolve_image_repos,
) as package_context:
package_context.run()