@@ -32,7 +32,7 @@ type CredentialProcessJson struct {
3232 AccessKeyID string `json:"AccessKeyId"`
3333 SecretAccessKey string `json:"SecretAccessKey"`
3434 SessionToken string `json:"SessionToken"`
35- Expiration time. Time `json:"Expiration"`
35+ Expiration AWSTime `json:"Expiration"`
3636}
3737
3838type Profile struct {
@@ -46,16 +46,20 @@ type AWSTime struct {
4646 time.Time
4747}
4848
49- func (t * AWSTime ) UnmarshalJSON (buf []byte ) error {
50-
51- tt , err := time .Parse (time .RFC3339 , strings .Trim (strings .Replace (string (buf ), "UTC" , "Z" , 1 ), `"` ))
52- if err != nil {
53- return err
49+ func (it * AWSTime ) UnmarshalJSON (data []byte ) error {
50+ t , err := time .Parse ("2006-01-02T15:04:05Z07:00" , strings .Trim (strings .Replace (string (data ), "UTC" , "Z" , 1 ), `"` ))
51+ if err == nil {
52+ * it = AWSTime {t }
5453 }
55- t .Time = tt
56- return nil
54+
55+ return err
56+ }
57+
58+ func (it AWSTime ) MarshalJSON () ([]byte , error ) {
59+ return []byte (fmt .Sprintf ("\" %sZ\" " , it .Time .UTC ().Format ("2006-01-02T15:04:05" ))), nil
5760}
5861
62+
5963func main (){
6064 zerolog .SetGlobalLevel (zerolog .InfoLevel )
6165 _ , ok := os .LookupEnv ("DEBUG" )
@@ -152,7 +156,7 @@ func getCachedFile(awsSsoCachePath, awsSSOProfileName string) (*CredentialProces
152156 if err != nil {
153157 return nil , err
154158 }
155- if time .Now ().After (credentialProcessJson .Expiration ) {
159+ if time .Now ().After (credentialProcessJson .Expiration . Time ) {
156160 log .Debug ().Str ("expire" , credentialProcessJson .Expiration .String ()).Msg ("credentials expired" )
157161 return nil , nil
158162 }
@@ -197,7 +201,7 @@ func getSsoRoleCredentials(profile Profile, awsSSOCredential AWSSSOCredential) (
197201 AccessKeyID : * resp .RoleCredentials .AccessKeyId ,
198202 SecretAccessKey : * resp .RoleCredentials .SecretAccessKey ,
199203 SessionToken : * resp .RoleCredentials .SessionToken ,
200- Expiration : aws .MillisecondsTimeValue (resp .RoleCredentials .Expiration ),
204+ Expiration : AWSTime { aws .MillisecondsTimeValue (resp .RoleCredentials .Expiration )} ,
201205 }, nil
202206}
203207
0 commit comments