Skip to content

refactor: remove duplicate code and fix indentation #8011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions samcli/commands/deploy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from samcli.commands.deploy.core.command import DeployCommand
from samcli.commands.deploy.utils import sanitize_parameter_overrides
from samcli.lib.bootstrap.bootstrap import manage_stack
from samcli.lib.bootstrap.bootstrap import manage_stack, print_managed_s3_bucket_info
from samcli.lib.bootstrap.companion_stack.companion_stack_manager import sync_ecr_stack
from samcli.lib.cli_validation.image_repository_validation import image_repository_validation
from samcli.lib.telemetry.metric import track_command
Expand Down Expand Up @@ -307,9 +307,7 @@ def do_cli(
if bool(s3_bucket):
raise DeployResolveS3AndS3SetError()
s3_bucket = manage_stack(profile=profile, region=region)
click.echo(f"\n\t\tManaged S3 bucket: {s3_bucket}")
click.echo("\t\tA different default S3 bucket can be set in samconfig.toml")
click.echo("\t\tOr by specifying --s3-bucket explicitly.")
print_managed_s3_bucket_info(s3_bucket)

# TODO Refactor resolve-s3 and resolve-image-repos into one place
# after we figure out how to enable resolve-images-repos in package
Expand Down
8 changes: 2 additions & 6 deletions samcli/commands/deploy/guided_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from samcli.commands.deploy.exceptions import GuidedDeployFailedError
from samcli.commands.deploy.guided_config import GuidedConfig
from samcli.commands.deploy.utils import sanitize_parameter_overrides
from samcli.lib.bootstrap.bootstrap import manage_stack
from samcli.lib.bootstrap.bootstrap import manage_stack, print_managed_s3_bucket_info
from samcli.lib.bootstrap.companion_stack.companion_stack_manager import CompanionStackManager, sync_ecr_stack
from samcli.lib.config.samconfig import DEFAULT_CONFIG_FILE_NAME, DEFAULT_ENV
from samcli.lib.intrinsic_resolver.intrinsics_symbol_table import IntrinsicsSymbolTable
Expand Down Expand Up @@ -182,11 +182,7 @@ def guided_prompts(self, parameter_override_keys):

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

image_repositories = (
sync_ecr_stack(
Expand Down
6 changes: 2 additions & 4 deletions samcli/commands/package/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use_json_option,
)
from samcli.commands.package.core.command import PackageCommand
from samcli.lib.bootstrap.bootstrap import manage_stack
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
Expand Down Expand Up @@ -168,9 +168,7 @@ def do_cli(

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

with PackageContext(
template_file=template_file,
Expand Down
17 changes: 17 additions & 0 deletions samcli/lib/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Optional

import boto3
import click
from botocore.exceptions import ClientError

from samcli import __version__
Expand Down Expand Up @@ -35,6 +36,22 @@ def manage_stack(profile, region):
return bucket_name


def print_managed_s3_bucket_info(s3_bucket: str):
"""
Print information about the managed S3 bucket.

Parameters
----------
s3_bucket : str
The name of the managed S3 bucket
"""
message = f"\n\tManaged S3 bucket: {s3_bucket}"
click.secho(message, bold=True)
click.echo("\tAuto resolution of buckets can be turned off by setting resolve_s3=False")
click.echo("\tTo use a specific S3 bucket, set --s3-bucket=<bucket_name>")
click.echo("\tAbove settings can be stored in samconfig.toml")


def get_current_account_id(profile: Optional[str] = None):
"""Returns account ID based on used AWS credentials."""
session = boto3.Session(profile_name=profile)
Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/package/s3_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def upload(self, file_name: str, remote_path: str) -> str:

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

try:
Expand Down
Loading