trek10inc / awsume

A utility for easily assuming AWS IAM roles from the command line.
https://awsu.me
MIT License
487 stars 90 forks source link

Expiry date #160

Open andymac4182 opened 3 years ago

andymac4182 commented 3 years ago

When getting some integration with Starship (https://github.com/starship/starship/pull/2464) going we noticed a difference in the format between awsvault and awsume.

Not sure if this is an easy change or if this will impact on other people but it would be great if awsume could include the timezone information in the expiry.

Not sure which is the "right" answer here was just trying to get the extra info added if it isn't too hard.

It looks like it would require a few updates to the places where the expiration is written out and checked against for autoawsume.

Happy to give this a go and write up a PR if you are happy for that.

felddy commented 1 year ago

As a workaround I added this function to my bash environment:

awsume() {
    source "$(pyenv which awsume)"
    # Add the local time zone to AWSUME_EXPIRATION if it is missing
    # See: https://github.com/trek10inc/awsume/issues/160

    # If a time zone is not specified, add the local time zone
    if [[ $AWSUME_EXPIRATION =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})$ ]]; then
        # Calulate the local tz offset in hours and minutes separated by a colon
        local tz_offset=$(date +%z | sed -E 's/([0-9]{2})([0-9]{2})/\1:\2/')
        export AWSUME_EXPIRATION="${AWSUME_EXPIRATION}${tz_offset}"
    fi
}
andymac4182 commented 1 year ago

I ended up moving to http://granted.dev which handles this.