Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6707866

Browse files
committedSep 5, 2023
Move bearerToken.readFromJSONBlob closer to its callers
Only moves unchanged code, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent ec19983 commit 6707866

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed
 

‎docker/docker_client.go

+29-29
Original file line numberDiff line numberDiff line change
@@ -144,35 +144,6 @@ const (
144144
noAuth
145145
)
146146

147-
// readFromJSONBlob sets token data in dest from the provided JSON.
148-
func (bt *bearerToken) readFromJSONBlob(blob []byte) error {
149-
var token struct {
150-
Token string `json:"token"`
151-
AccessToken string `json:"access_token"`
152-
ExpiresIn int `json:"expires_in"`
153-
IssuedAt time.Time `json:"issued_at"`
154-
expirationTime time.Time
155-
}
156-
if err := json.Unmarshal(blob, &token); err != nil {
157-
return err
158-
}
159-
160-
bt.token = token.Token
161-
if bt.token == "" {
162-
bt.token = token.AccessToken
163-
}
164-
165-
if token.ExpiresIn < minimumTokenLifetimeSeconds {
166-
token.ExpiresIn = minimumTokenLifetimeSeconds
167-
logrus.Debugf("Increasing token expiration to: %d seconds", token.ExpiresIn)
168-
}
169-
if token.IssuedAt.IsZero() {
170-
token.IssuedAt = time.Now().UTC()
171-
}
172-
bt.expirationTime = token.IssuedAt.Add(time.Duration(token.ExpiresIn) * time.Second)
173-
return nil
174-
}
175-
176147
// dockerCertDir returns a path to a directory to be consumed by tlsclientconfig.SetupCertificates() depending on ctx and hostPort.
177148
func dockerCertDir(sys *types.SystemContext, hostPort string) (string, error) {
178149
if sys != nil && sys.DockerCertPath != "" {
@@ -900,6 +871,35 @@ func (c *dockerClient) getBearerToken(ctx context.Context, dest *bearerToken, ch
900871
return dest.readFromJSONBlob(tokenBlob)
901872
}
902873

874+
// readFromJSONBlob sets token data in dest from the provided JSON.
875+
func (bt *bearerToken) readFromJSONBlob(blob []byte) error {
876+
var token struct {
877+
Token string `json:"token"`
878+
AccessToken string `json:"access_token"`
879+
ExpiresIn int `json:"expires_in"`
880+
IssuedAt time.Time `json:"issued_at"`
881+
expirationTime time.Time
882+
}
883+
if err := json.Unmarshal(blob, &token); err != nil {
884+
return err
885+
}
886+
887+
bt.token = token.Token
888+
if bt.token == "" {
889+
bt.token = token.AccessToken
890+
}
891+
892+
if token.ExpiresIn < minimumTokenLifetimeSeconds {
893+
token.ExpiresIn = minimumTokenLifetimeSeconds
894+
logrus.Debugf("Increasing token expiration to: %d seconds", token.ExpiresIn)
895+
}
896+
if token.IssuedAt.IsZero() {
897+
token.IssuedAt = time.Now().UTC()
898+
}
899+
bt.expirationTime = token.IssuedAt.Add(time.Duration(token.ExpiresIn) * time.Second)
900+
return nil
901+
}
902+
903903
// detectPropertiesHelper performs the work of detectProperties which executes
904904
// it at most once.
905905
func (c *dockerClient) detectPropertiesHelper(ctx context.Context) error {

0 commit comments

Comments
 (0)
Please sign in to comment.