Skip to content

Commit 025f73c

Browse files
committed
Move bearerToken.readFromJSONBlob closer to its callers
Only moves unchanged code, should not change behavior. Signed-off-by: Miloslav Trmač <[email protected]>
1 parent 97bf204 commit 025f73c

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

docker/docker_client.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,6 @@ const (
141141
noAuth
142142
)
143143

144-
// readFromJSONBlob sets token data in dest from the provided JSON.
145-
func (bt *bearerToken) readFromJSONBlob(blob []byte) error {
146-
var token struct {
147-
Token string `json:"token"`
148-
AccessToken string `json:"access_token"`
149-
ExpiresIn int `json:"expires_in"`
150-
IssuedAt time.Time `json:"issued_at"`
151-
expirationTime time.Time
152-
}
153-
if err := json.Unmarshal(blob, &token); err != nil {
154-
return err
155-
}
156-
157-
bt.token = token.Token
158-
if bt.token == "" {
159-
bt.token = token.AccessToken
160-
}
161-
162-
if token.ExpiresIn < minimumTokenLifetimeSeconds {
163-
token.ExpiresIn = minimumTokenLifetimeSeconds
164-
logrus.Debugf("Increasing token expiration to: %d seconds", token.ExpiresIn)
165-
}
166-
if token.IssuedAt.IsZero() {
167-
token.IssuedAt = time.Now().UTC()
168-
}
169-
bt.expirationTime = token.IssuedAt.Add(time.Duration(token.ExpiresIn) * time.Second)
170-
return nil
171-
}
172-
173144
// this is cloned from docker/go-connections because upstream docker has changed
174145
// it and make deps here fails otherwise.
175146
// We'll drop this once we upgrade to docker 1.13.x deps.
@@ -838,6 +809,35 @@ func (c *dockerClient) getBearerToken(ctx context.Context, dest *bearerToken, ch
838809
return dest.readFromJSONBlob(tokenBlob)
839810
}
840811

812+
// readFromJSONBlob sets token data in dest from the provided JSON.
813+
func (bt *bearerToken) readFromJSONBlob(blob []byte) error {
814+
var token struct {
815+
Token string `json:"token"`
816+
AccessToken string `json:"access_token"`
817+
ExpiresIn int `json:"expires_in"`
818+
IssuedAt time.Time `json:"issued_at"`
819+
expirationTime time.Time
820+
}
821+
if err := json.Unmarshal(blob, &token); err != nil {
822+
return err
823+
}
824+
825+
bt.token = token.Token
826+
if bt.token == "" {
827+
bt.token = token.AccessToken
828+
}
829+
830+
if token.ExpiresIn < minimumTokenLifetimeSeconds {
831+
token.ExpiresIn = minimumTokenLifetimeSeconds
832+
logrus.Debugf("Increasing token expiration to: %d seconds", token.ExpiresIn)
833+
}
834+
if token.IssuedAt.IsZero() {
835+
token.IssuedAt = time.Now().UTC()
836+
}
837+
bt.expirationTime = token.IssuedAt.Add(time.Duration(token.ExpiresIn) * time.Second)
838+
return nil
839+
}
840+
841841
// detectPropertiesHelper performs the work of detectProperties which executes
842842
// it at most once.
843843
func (c *dockerClient) detectPropertiesHelper(ctx context.Context) error {

0 commit comments

Comments
 (0)