Skip to content

Commit

Permalink
Use standard approach to passing aws profiles to boto3.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Sep 25, 2023
1 parent b770c8e commit 60111c2
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
log = logging.getLogger("core.cli")


def create_quicksight_client(aws_profile: str):
boto3.setup_default_session(profile_name=aws_profile)
def create_quicksight_client():
boto3.setup_default_session()
return boto3.client("quicksight")


Expand All @@ -30,7 +30,6 @@ def cli():


@click.command()
@click.option("--aws-profile", required=True, help="The AWS account profile")
@click.option("--aws-account-id", required=True, help="The ID of the AWS account")
@click.option(
"--analysis-id", required=True, help="The ID of the Analysis to be exported"
Expand All @@ -40,19 +39,16 @@ def cli():
required=True,
help="The path to the output directory to which resources will be exported",
)
def export_analysis(
aws_profile: str, aws_account_id: str, analysis_id: str, output_dir: str
):
def export_analysis(aws_account_id: str, analysis_id: str, output_dir: str):
"""
Exports a template and dependent data sets based on the specified analysis to JSON files.
"""
log.info(f"Create version")
log.info(f"aws_profile = {aws_profile}")
log.info(f"analysis_id= {analysis_id}")
log.info(f"aws_account_id={aws_account_id}")
log.info(f"output_dir={output_dir}")
result = ExportAnalysisOperation(
qs_client=create_quicksight_client(aws_profile=aws_profile),
qs_client=create_quicksight_client(),
aws_account_id=aws_account_id,
analysis_id=analysis_id,
output_dir=output_dir,
Expand All @@ -64,7 +60,6 @@ def export_analysis(


@click.command
@click.option("--aws-profile", required=True, help="The AWS account profile")
@click.option("--aws-account-id", required=True, help="The ID of the AWS account")
@click.option(
"--template-name", required=True, help="The name of the template to be restored"
Expand All @@ -85,7 +80,6 @@ def export_analysis(
help="The path to the input directory from which resources will be imported",
)
def import_template(
aws_profile: str,
aws_account_id: str,
template_name: str,
data_source_arn: str,
Expand All @@ -97,14 +91,13 @@ def import_template(
"""

log.info(f"import_from_json")
log.info(f"aws_profile = {aws_profile}")
log.info(f"aws_account_id = {aws_account_id}")
log.info(f"template_name = {template_name}")
log.info(f"data_source_arn = {data_source_arn}")
log.info(f"input_dir= {input_dir}")

result = ImportFromJsonOperation(
qs_client=create_quicksight_client(aws_profile),
qs_client=create_quicksight_client(),
aws_account_id=aws_account_id,
template_name=template_name,
target_namespace=target_namespace,
Expand All @@ -118,7 +111,6 @@ def import_template(


@click.command
@click.option("--aws-profile", required=True, help="The AWS account profile")
@click.option("--aws-account-id", required=True, help="The ID of the AWS account")
@click.option(
"--template-id", required=True, help="The ID of the template to be restored"
Expand All @@ -130,7 +122,6 @@ def import_template(
)
@click.option("--group-name", required=True, help="Name of the Quicksight User Group")
def publish_dashboard(
aws_profile: str,
aws_account_id: str,
template_id: str,
target_namespace: str,
Expand All @@ -141,12 +132,11 @@ def publish_dashboard(
"""

log.info(f"publish dashboard from template")
log.info(f"aws_profile = {aws_profile}")
log.info(f"aws_account_id = {aws_account_id}")
log.info(f"template_id = {template_id}")
log.info(f"group_name = {group_name}")
result = PublishDashboardFromTemplateOperation(
qs_client=create_quicksight_client(aws_profile),
qs_client=create_quicksight_client(),
aws_account_id=aws_account_id,
template_id=template_id,
target_namespace=target_namespace,
Expand Down

0 comments on commit 60111c2

Please sign in to comment.