@@ -32,7 +32,7 @@ type CredentialProcessJson struct {
32
32
AccessKeyID string `json:"AccessKeyId"`
33
33
SecretAccessKey string `json:"SecretAccessKey"`
34
34
SessionToken string `json:"SessionToken"`
35
- Expiration time. Time `json:"Expiration"`
35
+ Expiration AWSTime `json:"Expiration"`
36
36
}
37
37
38
38
type Profile struct {
@@ -46,16 +46,20 @@ type AWSTime struct {
46
46
time.Time
47
47
}
48
48
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 }
54
53
}
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
57
60
}
58
61
62
+
59
63
func main (){
60
64
zerolog .SetGlobalLevel (zerolog .InfoLevel )
61
65
_ , ok := os .LookupEnv ("DEBUG" )
@@ -152,7 +156,7 @@ func getCachedFile(awsSsoCachePath, awsSSOProfileName string) (*CredentialProces
152
156
if err != nil {
153
157
return nil , err
154
158
}
155
- if time .Now ().After (credentialProcessJson .Expiration ) {
159
+ if time .Now ().After (credentialProcessJson .Expiration . Time ) {
156
160
log .Debug ().Str ("expire" , credentialProcessJson .Expiration .String ()).Msg ("credentials expired" )
157
161
return nil , nil
158
162
}
@@ -197,7 +201,7 @@ func getSsoRoleCredentials(profile Profile, awsSSOCredential AWSSSOCredential) (
197
201
AccessKeyID : * resp .RoleCredentials .AccessKeyId ,
198
202
SecretAccessKey : * resp .RoleCredentials .SecretAccessKey ,
199
203
SessionToken : * resp .RoleCredentials .SessionToken ,
200
- Expiration : aws .MillisecondsTimeValue (resp .RoleCredentials .Expiration ),
204
+ Expiration : AWSTime { aws .MillisecondsTimeValue (resp .RoleCredentials .Expiration )} ,
201
205
}, nil
202
206
}
203
207
0 commit comments