...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package cache
15
16 import (
17 "time"
18 )
19
20 type CredentialsCache interface {
21 Get(registry string) *AuthEntry
22 GetPublic() *AuthEntry
23 Set(registry string, entry *AuthEntry)
24 List() []*AuthEntry
25 Clear()
26 }
27
28 type Service string
29
30 const (
31 ServiceECR Service = "ecr"
32 ServiceECRPublic Service = "ecr-public"
33 )
34
35 type AuthEntry struct {
36 AuthorizationToken string
37 RequestedAt time.Time
38 ExpiresAt time.Time
39 ProxyEndpoint string
40 Service Service
41 }
42
43
44
45 func (authEntry *AuthEntry) IsValid(testTime time.Time) bool {
46 validWindow := authEntry.ExpiresAt.Sub(authEntry.RequestedAt)
47 refreshTime := authEntry.ExpiresAt.Add(-1 * validWindow / time.Duration(2))
48 return testTime.Before(refreshTime)
49 }
50
View as plain text