Skip to content
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

add duration-seconds option #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 4 additions & 2 deletions awscli_saml_sso/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
help=f"Configure python log level to print (default: {default_log_level})")
@click.option("--endpoint-url", envvar="ASS_ENDPOINT_URL",
help="Override AWS API endpoint url (mainly for testing purpose)")
@click.option("--duration-seconds", default=3600, show_default=True,
help="Configure the expiration time of the token where the value can range from 900 seconds (15 minutes) to 129600 seconds (36 hours)")
@click.version_option()
def main(log_level, endpoint_url):
def main(log_level, endpoint_url, duration_seconds):
os.environ["WDM_LOG_LEVEL"] = str(logging.getLevelName(log_level))
fileConfig(resource_filename("awscli_saml_sso", "logger.cfg"), disable_existing_loggers=False, defaults={
"log_level": log_level,
Expand Down Expand Up @@ -115,7 +117,7 @@ def main(log_level, endpoint_url):

# Use the assertion to get an AWS STS token using Assume Role with SAML
client = boto3.client("sts", endpoint_url=endpoint_url)
sts_response = client.assume_role_with_saml(RoleArn=role_arn, PrincipalArn=principal_arn, SAMLAssertion=assertion)
sts_response = client.assume_role_with_saml(RoleArn=role_arn, PrincipalArn=principal_arn, SAMLAssertion=assertion, DurationSeconds=duration_seconds)

# Write the AWS STS token into the AWS credential file
aws_credentials_path = Path.home() / ".aws" / "credentials"
Expand Down