Skip to content

Commit

Permalink
Revert "feat: Add --s3-bucket and --s3-prefix to sam delete (#3915)" (#…
Browse files Browse the repository at this point in the history
…3954)

This reverts commit eda6089.
  • Loading branch information
mndeveci authored Jun 9, 2022
1 parent c2822ba commit 616e06b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 238 deletions.
32 changes: 2 additions & 30 deletions samcli/commands/delete/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import logging

from typing import Optional
import click
from samcli.cli.main import aws_creds_options, common_options, pass_context, print_cmdline_args

Expand Down Expand Up @@ -64,26 +63,12 @@
is_flag=True,
required=False,
)
@click.option(
"--s3-bucket",
help=("The S3 bucket path you want to delete."),
type=click.STRING,
default=None,
required=False,
)
@click.option(
"--s3-prefix",
help=("The S3 prefix you want to delete"),
type=click.STRING,
default=None,
required=False,
)
@aws_creds_options
@common_options
@pass_context
@check_newer_version
@print_cmdline_args
def cli(ctx, stack_name: str, config_file: str, config_env: str, no_prompts: bool, s3_bucket: str, s3_prefix: str):
def cli(ctx, stack_name: str, config_file: str, config_env: str, no_prompts: bool):
"""
`sam delete` command entry point
"""
Expand All @@ -96,21 +81,10 @@ def cli(ctx, stack_name: str, config_file: str, config_env: str, no_prompts: boo
config_env=config_env,
profile=ctx.profile,
no_prompts=no_prompts,
s3_bucket=s3_bucket,
s3_prefix=s3_prefix,
) # pragma: no cover


def do_cli(
stack_name: str,
region: str,
config_file: str,
config_env: str,
profile: str,
no_prompts: bool,
s3_bucket: Optional[str],
s3_prefix: Optional[str],
):
def do_cli(stack_name: str, region: str, config_file: str, config_env: str, profile: str, no_prompts: bool):
"""
Implementation of the ``cli`` method
"""
Expand All @@ -123,7 +97,5 @@ def do_cli(
config_file=config_file,
config_env=config_env,
no_prompts=no_prompts,
s3_bucket=s3_bucket,
s3_prefix=s3_prefix,
) as delete_context:
delete_context.run()
41 changes: 12 additions & 29 deletions samcli/commands/delete/delete_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import logging

import json

from typing import Optional

import boto3


import click
from click import confirm
from click import prompt
Expand Down Expand Up @@ -38,25 +36,15 @@

class DeleteContext:
# TODO: Separate this context into 2 separate contexts guided and non-guided, just like deploy.
def __init__(
self,
stack_name: str,
region: str,
profile: str,
config_file: str,
config_env: str,
no_prompts: bool,
s3_bucket: Optional[str],
s3_prefix: Optional[str],
):
def __init__(self, stack_name: str, region: str, profile: str, config_file: str, config_env: str, no_prompts: bool):
self.stack_name = stack_name
self.region = region
self.profile = profile
self.config_file = config_file
self.config_env = config_env
self.no_prompts = no_prompts
self.s3_bucket = s3_bucket
self.s3_prefix = s3_prefix
self.s3_bucket = None
self.s3_prefix = None
self.cf_utils = None
self.s3_uploader = None
self.ecr_uploader = None
Expand Down Expand Up @@ -107,10 +95,8 @@ def parse_config_file(self):
self.region = config_options.get("region", None)
if not self.profile:
self.profile = config_options.get("profile", None)
if not self.s3_bucket:
self.s3_bucket = config_options.get("s3_bucket", None)
if not self.s3_prefix:
self.s3_prefix = config_options.get("s3_prefix", None)
self.s3_bucket = config_options.get("s3_bucket", None)
self.s3_prefix = config_options.get("s3_prefix", None)

def init_clients(self):
"""
Expand Down Expand Up @@ -156,9 +142,8 @@ def s3_prompts(self):
Guided prompts asking user to delete s3 artifacts
"""
# Note: s3_bucket and s3_prefix information is only
# available if it is provided as an option flag, a
# local toml file or if this information is obtained
# from the template resources and so if this
# available if a local toml file is present or if
# this information is obtained from the template resources and so if this
# information is not found, warn the user that S3 artifacts
# will need to be manually deleted.

Expand Down Expand Up @@ -334,14 +319,12 @@ def delete(self):
self.cf_utils.delete_stack(stack_name=self.stack_name, retain_resources=retain_resources)
self.cf_utils.wait_for_delete(self.stack_name)

# Warn the user that s3 information is missing and to use --s3 options
# If s3_bucket information is not available, warn the user
if not self.s3_bucket:
LOG.debug("Cannot delete s3 objects as bucket is missing")
LOG.debug("Cannot delete s3 files as no s3_bucket found")
click.secho(
"\nWarning: Cannot resolve s3 bucket information from command options"
" , local config file or cloudformation template. Please use"
" --s3-bucket next time and"
" delete s3 files manually if required.",
"\nWarning: s3_bucket and s3_prefix information could not be obtained from local config file"
" or cloudformation template, delete the s3 files manually if required",
fg="yellow",
)

Expand Down
25 changes: 6 additions & 19 deletions tests/integration/delete/delete_integ_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from pathlib import Path
from typing import Optional
from unittest import TestCase


Expand All @@ -23,33 +22,21 @@ def base_command(self):
return command

def get_delete_command_list(
self,
stack_name: Optional[str] = None,
region: Optional[str] = None,
config_file: Optional[str] = None,
config_env: Optional[str] = None,
profile: Optional[str] = None,
no_prompts: Optional[bool] = None,
s3_bucket: Optional[str] = None,
s3_prefix: Optional[str] = None,
self, stack_name=None, region=None, config_file=None, config_env=None, profile=None, no_prompts=None
):
command_list = [self.base_command(), "delete"]

if stack_name:
command_list += ["--stack-name", stack_name]
command_list += ["--stack-name", str(stack_name)]
if region:
command_list += ["--region", region]
command_list += ["--region", str(region)]
if config_file:
command_list += ["--config-file", config_file]
command_list += ["--config-file", str(config_file)]
if config_env:
command_list += ["--config-env", config_env]
command_list += ["--config-env", str(config_env)]
if profile:
command_list += ["--profile", profile]
command_list += ["--profile", str(profile)]
if no_prompts:
command_list += ["--no-prompts"]
if s3_bucket:
command_list += ["--s3-bucket", s3_bucket]
if s3_prefix:
command_list += ["--s3-prefix", s3_prefix]

return command_list
Loading

0 comments on commit 616e06b

Please sign in to comment.