def edit(kctx: kitipy.Context, secret_name): """Edit secrets stored by AWS Secrets Manager.""" stack = kctx.config['stacks'][kctx.stack.name] secret_arn = stack['secret_arn_resolver'](kctx=kctx, secret_name=secret_name) client = sm.new_client() secret = sm.describe_secret_with_current_value(client, secret_arn) if secret == None: kctx.fail("Secret \"%s\" not found." % (secret_name)) value = click.edit(text=secret['SecretString']) if value == None: kctx.info("Secret value was not changed. Aborting.") raise click.exceptions.Abort() trim_question = ("Your secret value ends with a new line. This is " + "generally abnormal. Would you want to trim it " + "automatically?") if value.endswith("\n") and click.confirm(trim_question, default=True): value = value.rstrip("\n") kctx.echo(("NOTE: Secret values end with %s. This is here to help you " + "see invisible characters (e.g. whitespace, line breaks, " + "etc...).\n") % (secret_delimiter)) kctx.echo("ID: %s" % (secret["ARN"])) kctx.echo("Name: %s" % (secret["Name"])) kctx.echo("Previous value: %s" % (format_secret_value(secret["SecretString"], True))) kctx.echo("New value: %s" % (format_secret_value(value, True))) click.confirm("\nDo you confirm this change?", abort=True) sm.put_secret_value(client, secret["ARN"], value)
def show(kctx: kitipy.Context, show_values: bool): """Show secrets stored by AWS Secrets Manager.""" # @TODO: kctx.stack should be the raw config dict stack = kctx.config['stacks'][kctx.stack.name] secrets = stack['secrets_resolver'](kctx) kctx.echo(("NOTE: Secret values end with %s. This is here to help you " + "see invisible characters (e.g. whitespace, line breaks, " + "etc...).\n") % (secret_delimiter)) client = sm.new_client() for secret_arn in secrets: secret = sm.describe_secret_with_current_value(client, secret_arn) kctx.echo("=================================") kctx.echo("ID: %s" % (secret["ARN"])) kctx.echo("Name: %s" % (secret["Name"])) kctx.echo("Value: %s\n" % (format_secret_value(secret["SecretString"], show_values)))
def show_failed_containers(kctx: kitipy.Context, task: mypy_boto3_ecs.type_defs.TaskTypeDef): containers = list(filter(lambda c: c["exitCode"] > 0, task["containers"])) if len(containers) == 0: kctx.echo("Containers with nonzero exit code: (None)") return kctx.echo("Containers with nonzero exit code:") for container in task["containers"]: if container["exitCode"] == 0: continue reason = "exit code: {0}".format(container["exitCode"]) + ( " - " + container['reason'] if 'reason' in container else '') kctx.echo(" * {name}: {reason}".format(name=container["name"], reason=reason))
def show_task(kctx: kitipy.Context, task: mypy_boto3_ecs.type_defs.TaskTypeDef, image_tag: Optional[str] = None): kctx.echo("=================================") kctx.echo("Task ID: {0}".format(task_id_from_arn(task["taskArn"]))) kctx.echo("Task definition: {0}".format( task_def_from_arn(task["taskDefinitionArn"]))) if image_tag: kctx.echo("Image tag: {0}".format(image_tag)) kctx.echo("CPU / Memory: {0} / {1}".format(task["cpu"], task["memory"])) kctx.echo("Last status / Desired status: {0} / {1}".format( task["lastStatus"], task["desiredStatus"])) if task["lastStatus"] == "RUNNING": kctx.echo("Started at: {0}".format(task["startedAt"].isoformat())) if task["lastStatus"] == "STOPPED": kctx.echo("Stopped at: {0}".format(task["stoppedAt"].isoformat())) kctx.echo("Reason: {0}".format(task["stoppedReason"])) show_failed_containers(kctx, task) kctx.echo("") # Put an empty line between each task