Skip to content

Commit 0cc1aea

Browse files
authored
refactor: remove duplicate code and fix indentation (#8011)
* 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. * black: run `make black` * fix: state how auto resolution of buckets is turned off. * fix: remove branching and explicit wording on s3
1 parent 418305f commit 0cc1aea

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

samcli/commands/deploy/command.py

+2-4
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

+2-6
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,7 @@ 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)
190186

191187
image_repositories = (
192188
sync_ecr_stack(

samcli/commands/package/command.py

+2-4
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

+17
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__
@@ -35,6 +36,22 @@ def manage_stack(profile, region):
3536
return bucket_name
3637

3738

39+
def print_managed_s3_bucket_info(s3_bucket: str):
40+
"""
41+
Print information about the managed S3 bucket.
42+
43+
Parameters
44+
----------
45+
s3_bucket : str
46+
The name of the managed S3 bucket
47+
"""
48+
message = f"\n\tManaged S3 bucket: {s3_bucket}"
49+
click.secho(message, bold=True)
50+
click.echo("\tAuto resolution of buckets can be turned off by setting resolve_s3=False")
51+
click.echo("\tTo use a specific S3 bucket, set --s3-bucket=<bucket_name>")
52+
click.echo("\tAbove settings can be stored in samconfig.toml")
53+
54+
3855
def get_current_account_id(profile: Optional[str] = None):
3956
"""Returns account ID based on used AWS credentials."""
4057
session = boto3.Session(profile_name=profile)

samcli/lib/package/s3_uploader.py

+1-1
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)