Skip to content

Commit bf934ec

Browse files
committed
Added refreshable date to sso credentials
1 parent 4f20618 commit bf934ec

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

sdk/credentials/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (s *Session) RegisterClient() error {
268268
s.ClientCredentials = &ClientCredentials{
269269
ClientId: *register.ClientId,
270270
ClientSecret: *register.ClientSecret,
271-
ExpiresAt: time.Now().Add(time.Duration(register.ClientSecretExpiresAt) * time.Second).UTC(),
271+
ExpiresAt: time.Unix(register.ClientSecretExpiresAt, 0).UTC(),
272272
Scopes: s.Scopes,
273273
}
274274
return nil

sdk/tui/tui.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,25 @@ func SelectSession(sessions credentials.Sessions) (string, string, error) {
6565
p.WithMaxHeight(MaxItemsToShow)
6666
p.WithEmptyMessage("No SSO Sessions Found")
6767
p.WithTitle("Pick SSO Session")
68-
p.WithHeaders("SSO Session", "Region", "SSO Start URL", "Expires In")
68+
p.WithHeaders("SSO Session", "Region", "SSO Start URL", "Refreshable", "Expires In")
6969
p.AddAction(keys.Tab, "tab", "view cached")
7070
for _, session := range sessions {
7171
expires := "-"
72+
refreshable := "-"
7273
if session.ClientToken != nil && !session.ClientToken.IsExpired() {
7374
expires = fmt.Sprintf("%.f mins", session.ClientToken.ExpiresAt.Sub(now).Minutes())
7475
}
75-
p.AddOption(session.Name, session.Name, session.Region, session.StartUrl, expires)
76+
if session.ClientCredentials != nil && !session.ClientCredentials.IsExpired() {
77+
hours := session.ClientCredentials.ExpiresAt.Sub(now).Hours()
78+
if hours < 1 {
79+
refreshable = fmt.Sprintf("%.f mins", hours * 60)
80+
} else if hours < 24 {
81+
refreshable = fmt.Sprintf("%.f hours", hours)
82+
} else {
83+
refreshable = fmt.Sprintf("%.f days", hours / 24)
84+
}
85+
}
86+
p.AddOption(session.Name, session.Name, session.Region, session.StartUrl, refreshable, expires)
7687
}
7788
selection, firedKeyCode := p.Pick()
7889
if firedKeyCode != nil && *firedKeyCode == keys.Tab {

0 commit comments

Comments
 (0)