Skip to content

Feature: Added export of Expiration time to Env#98

Merged
mbarneyjr merged 3 commits intotrek10inc:masterfrom
parkeyparker:feature/export-expiry-time
Apr 9, 2020
Merged

Feature: Added export of Expiration time to Env#98
mbarneyjr merged 3 commits intotrek10inc:masterfrom
parkeyparker:feature/export-expiry-time

Conversation

@parkeyparker
Copy link
Contributor

In order to calculate time remaining before expiry of a session this will export an extra environment variable: AWSUME_EXPIRATION. With this the remaining time can be calculated and displayed in the prompt in order to determine whether you need to renew the session.

Example usage within .zshrc:

_timeremaining() {
  secs_future=$(date -j -f "%Y-%m-%dT%H:%M:%S" $1 +%s)
  secs_now=$(date +%s)
  secs_remaining=$(( $secs_future - $secs_now ))
  if [ "$secs_remaining" -lt "0" ]; then
  	echo "00:00"
  elif [ "$secs_remaining" -lt "3600" ]; then
  	gdate -d@$secs_remaining -u +%M:%S
  else
    gdate -d@$secs_remaining -u +%H:%M:%S
  fi
}

alias awsenvtimeremain='_awsenvtimeremain'
_awsenvtimeremain() {
  if [[ -v AWSUME_PROFILE ]]; then
    time_remain=$(_timeremaining $AWSUME_EXPIRATION)
    echo "$time_remain"
  fi
}

Then just call awsenvtimeremain() in your prompt definition.

Screenshot 2020-04-08 at 13 13 47

In order to calculate time remaining before expiry of a session this will export an extra environment variable: AWSUME_EXPIRATION. With this the remaining time can be calculated and displayed in the prompt in order to determine whether you need to renew the session.
@mbarneyjr
Copy link
Member

Hi @parkeyparker,

This looks great! Thanks for the PR! We'll take a look 😄

@mbarneyjr mbarneyjr merged commit 6e83f7b into trek10inc:master Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants