Skip to content

Commit 850a48b

Browse files
committed
refactor: remove duplicate code and fix indentation
* Set the right indentation across `package`, `deploy`, `package/deploy --resolve-s3` & `deploy --guided` * Set the right indentation on `Skipping upload` to S3.
1 parent 418305f commit 850a48b

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

samcli/commands/deploy/command.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
)
3737
from samcli.commands.deploy.core.command import DeployCommand
3838
from samcli.commands.deploy.utils import sanitize_parameter_overrides
39-
from samcli.lib.bootstrap.bootstrap import manage_stack
39+
from samcli.lib.bootstrap.bootstrap import manage_stack, print_managed_s3_bucket_info
4040
from samcli.lib.bootstrap.companion_stack.companion_stack_manager import sync_ecr_stack
4141
from samcli.lib.cli_validation.image_repository_validation import image_repository_validation
4242
from samcli.lib.telemetry.metric import track_command
@@ -307,9 +307,7 @@ def do_cli(
307307
if bool(s3_bucket):
308308
raise DeployResolveS3AndS3SetError()
309309
s3_bucket = manage_stack(profile=profile, region=region)
310-
click.echo(f"\n\t\tManaged S3 bucket: {s3_bucket}")
311-
click.echo("\t\tA different default S3 bucket can be set in samconfig.toml")
312-
click.echo("\t\tOr by specifying --s3-bucket explicitly.")
310+
print_managed_s3_bucket_info(s3_bucket)
313311

314312
# TODO Refactor resolve-s3 and resolve-image-repos into one place
315313
# after we figure out how to enable resolve-images-repos in package

samcli/commands/deploy/guided_context.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from samcli.commands.deploy.exceptions import GuidedDeployFailedError
2424
from samcli.commands.deploy.guided_config import GuidedConfig
2525
from samcli.commands.deploy.utils import sanitize_parameter_overrides
26-
from samcli.lib.bootstrap.bootstrap import manage_stack
26+
from samcli.lib.bootstrap.bootstrap import manage_stack, print_managed_s3_bucket_info
2727
from samcli.lib.bootstrap.companion_stack.companion_stack_manager import CompanionStackManager, sync_ecr_stack
2828
from samcli.lib.config.samconfig import DEFAULT_CONFIG_FILE_NAME, DEFAULT_ENV
2929
from samcli.lib.intrinsic_resolver.intrinsics_symbol_table import IntrinsicsSymbolTable
@@ -182,11 +182,8 @@ def guided_prompts(self, parameter_override_keys):
182182

183183
click.echo("\n\tLooking for resources needed for deployment:")
184184
managed_s3_bucket = manage_stack(profile=self.profile, region=region)
185-
click.secho(f"\n\tManaged S3 bucket: {managed_s3_bucket}", bold=True)
186-
click.echo(
187-
"\tA different default S3 bucket can be set in samconfig.toml"
188-
" and auto resolution of buckets turned off by setting resolve_s3=False"
189-
)
185+
print_managed_s3_bucket_info(managed_s3_bucket, bold=True, show_s3_bucket_option=False)
186+
click.echo("\tAuto resolution of buckets turned off by setting resolve_s3=False")
190187

191188
image_repositories = (
192189
sync_ecr_stack(

samcli/commands/package/command.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use_json_option,
2424
)
2525
from samcli.commands.package.core.command import PackageCommand
26-
from samcli.lib.bootstrap.bootstrap import manage_stack
26+
from samcli.lib.bootstrap.bootstrap import manage_stack, print_managed_s3_bucket_info
2727
from samcli.lib.cli_validation.image_repository_validation import image_repository_validation
2828
from samcli.lib.telemetry.metric import track_command, track_template_warnings
2929
from samcli.lib.utils.resources import resources_generator
@@ -168,9 +168,7 @@ def do_cli(
168168

169169
if resolve_s3:
170170
s3_bucket = manage_stack(profile=profile, region=region)
171-
click.echo(f"\n\t\tManaged S3 bucket: {s3_bucket}")
172-
click.echo("\t\tA different default S3 bucket can be set in samconfig.toml")
173-
click.echo("\t\tOr by specifying --s3-bucket explicitly.")
171+
print_managed_s3_bucket_info(s3_bucket)
174172

175173
with PackageContext(
176174
template_file=template_file,

samcli/lib/bootstrap/bootstrap.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Optional
88

99
import boto3
10+
import click
1011
from botocore.exceptions import ClientError
1112

1213
from samcli import __version__
@@ -34,6 +35,25 @@ def manage_stack(profile, region):
3435
# This bucket name is what we would write to a config file
3536
return bucket_name
3637

38+
def print_managed_s3_bucket_info(s3_bucket, bold=False, show_s3_bucket_option=True):
39+
"""
40+
Print information about the managed S3 bucket.
41+
42+
Parameters
43+
----------
44+
s3_bucket : str
45+
The name of the managed S3 bucket
46+
bold : bool, optional
47+
Whether to print the message in bold, by default False
48+
show_s3_bucket_option : bool, optional
49+
Whether to show the s3-bucket option message, by default True
50+
"""
51+
message = f"\n\tManaged S3 bucket: {s3_bucket}"
52+
click.secho(message, bold=bold)
53+
click.echo("\tA different default S3 bucket can be set in samconfig.toml")
54+
if show_s3_bucket_option:
55+
click.echo("\tOr by specifying --s3-bucket explicitly.")
56+
3757

3858
def get_current_account_id(profile: Optional[str] = None):
3959
"""Returns account ID based on used AWS credentials."""

samcli/lib/package/s3_uploader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def upload(self, file_name: str, remote_path: str) -> str:
8585

8686
# Check if a file with same data exists
8787
if not self.force_upload and self.file_exists(remote_path):
88-
LOG.info("File with same data already exists at %s, skipping upload", remote_path)
88+
LOG.info("\n\tFile with same data already exists at %s, skipping upload", remote_path)
8989
return self.make_url(remote_path)
9090

9191
try:

0 commit comments

Comments
 (0)