@@ -3,15 +3,20 @@ package cmd
33import (
44 "context"
55 "fmt"
6+ "os"
7+ "time"
68
9+ "github.com/charmbracelet/lipgloss"
10+ "github.com/charmbracelet/lipgloss/table"
711 "github.com/spf13/cobra"
812
913 "github.com/cloudposse/atmos/pkg/auth"
1014 "github.com/cloudposse/atmos/pkg/auth/credentials"
15+ authTypes "github.com/cloudposse/atmos/pkg/auth/types"
1116 "github.com/cloudposse/atmos/pkg/auth/validation"
1217 cfg "github.com/cloudposse/atmos/pkg/config"
1318 "github.com/cloudposse/atmos/pkg/schema"
14- u "github.com/cloudposse/atmos/pkg/utils "
19+ "github.com/cloudposse/atmos/pkg/ui/theme "
1520)
1621
1722// authLoginCmd logs in using a configured identity.
@@ -50,19 +55,8 @@ func executeAuthLoginCommand(cmd *cobra.Command, args []string) error {
5055 return fmt .Errorf ("authentication failed: %w" , err )
5156 }
5257
53- // Display success message
54- u .PrintfMessageToTUI ("**Authentication successful!**\n " )
55- u .PrintfMessageToTUI ("Provider: %s\n " , whoami .Provider )
56- u .PrintfMessageToTUI ("Identity: %s\n " , whoami .Identity )
57- if whoami .Account != "" {
58- u .PrintfMessageToTUI ("Account: %s\n " , whoami .Account )
59- }
60- if whoami .Region != "" {
61- u .PrintfMessageToTUI ("Region: %s\n " , whoami .Region )
62- }
63- if whoami .Expiration != nil {
64- u .PrintfMessageToTUI ("Expires: %s\n " , whoami .Expiration .Format ("2006-01-02 15:04:05 MST" ))
65- }
58+ // Display success message using Atmos theme.
59+ displayAuthSuccess (whoami )
6660
6761 return nil
6862}
@@ -75,6 +69,81 @@ func createAuthManager(authConfig *schema.AuthConfig) (auth.AuthManager, error)
7569 return auth .NewAuthManager (authConfig , credStore , validator , nil )
7670}
7771
72+ const (
73+ secondsPerMinute = 60
74+ minutesPerHour = 60
75+ )
76+
77+ // formatDuration formats a duration into a human-readable string.
78+ func formatDuration (d time.Duration ) string {
79+ if d < 0 {
80+ return "expired"
81+ }
82+
83+ hours := int (d .Hours ())
84+ minutes := int (d .Minutes ()) % minutesPerHour
85+ seconds := int (d .Seconds ()) % secondsPerMinute
86+
87+ if hours > 0 {
88+ return fmt .Sprintf ("%dh %dm" , hours , minutes )
89+ }
90+ if minutes > 0 {
91+ return fmt .Sprintf ("%dm %ds" , minutes , seconds )
92+ }
93+ return fmt .Sprintf ("%ds" , seconds )
94+ }
95+
96+ // displayAuthSuccess displays a styled success message with authentication details.
97+ func displayAuthSuccess (whoami * authTypes.WhoamiInfo ) {
98+ // Display checkmark with success message.
99+ checkMark := theme .Styles .Checkmark
100+ fmt .Fprintf (os .Stderr , "\n %s Authentication successful!\n \n " , checkMark )
101+
102+ // Build table rows.
103+ var rows [][]string
104+ rows = append (rows , []string {"Provider" , whoami .Provider })
105+ rows = append (rows , []string {"Identity" , whoami .Identity })
106+
107+ if whoami .Account != "" {
108+ rows = append (rows , []string {"Account" , whoami .Account })
109+ }
110+
111+ if whoami .Region != "" {
112+ rows = append (rows , []string {"Region" , whoami .Region })
113+ }
114+
115+ if whoami .Expiration != nil {
116+ expiresStr := whoami .Expiration .Format ("2006-01-02 15:04:05 MST" )
117+ duration := formatDuration (time .Until (* whoami .Expiration ))
118+ // Style duration with darker gray.
119+ durationStyle := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#808080" ))
120+ expiresStr = fmt .Sprintf ("%s %s" , expiresStr , durationStyle .Render (fmt .Sprintf ("(%s)" , duration )))
121+ rows = append (rows , []string {"Expires" , expiresStr })
122+ }
123+
124+ // Create minimal charmbracelet table.
125+ t := table .New ().
126+ Rows (rows ... ).
127+ BorderTop (false ).
128+ BorderBottom (false ).
129+ BorderLeft (false ).
130+ BorderRight (false ).
131+ BorderRow (false ).
132+ BorderColumn (false ).
133+ StyleFunc (func (row , col int ) lipgloss.Style {
134+ if col == 0 {
135+ // Key column - use cyan color.
136+ return lipgloss .NewStyle ().
137+ Foreground (lipgloss .Color (theme .ColorCyan )).
138+ Padding (0 , 1 , 0 , 2 )
139+ }
140+ // Value column - default color with padding.
141+ return lipgloss .NewStyle ().Padding (0 , 1 )
142+ })
143+
144+ fmt .Fprintf (os .Stderr , "%s\n \n " , t )
145+ }
146+
78147func init () {
79148 authCmd .AddCommand (authLoginCmd )
80149}
0 commit comments