Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit a7d1aec

Browse files
committed
postImagesCreate: move auth config decode when it's needed
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
1 parent 505a56d commit a7d1aec

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

api/server/router/local/image.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,8 @@ func (s *router) postImagesCreate(ctx context.Context, w http.ResponseWriter, r
8989
repo = r.Form.Get("repo")
9090
tag = r.Form.Get("tag")
9191
message = r.Form.Get("message")
92-
)
93-
authEncoded := r.Header.Get("X-Registry-Auth")
94-
authConfig := &types.AuthConfig{}
95-
if authEncoded != "" {
96-
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
97-
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
98-
// for a pull it is not an error if no auth was given
99-
// to increase compatibility with the existing api it is defaulting to be empty
100-
authConfig = &types.AuthConfig{}
101-
}
102-
}
103-
104-
var (
105-
err error
106-
output = ioutils.NewWriteFlusher(w)
92+
err error
93+
output = ioutils.NewWriteFlusher(w)
10794
)
10895
defer output.Close()
10996

@@ -136,6 +123,17 @@ func (s *router) postImagesCreate(ctx context.Context, w http.ResponseWriter, r
136123
}
137124
}
138125

126+
authEncoded := r.Header.Get("X-Registry-Auth")
127+
authConfig := &types.AuthConfig{}
128+
if authEncoded != "" {
129+
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
130+
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
131+
// for a pull it is not an error if no auth was given
132+
// to increase compatibility with the existing api it is defaulting to be empty
133+
authConfig = &types.AuthConfig{}
134+
}
135+
}
136+
139137
err = s.daemon.PullImage(ref, metaHeaders, authConfig, output)
140138
}
141139
}

runconfig/opts/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ func validatePath(val string, validator func(string) bool) (string, error) {
690690
return val, nil
691691
}
692692

693-
// SplitN splits raw into a maximum of n parts, separated by a separator colon.
693+
// volumeSplitN splits raw into a maximum of n parts, separated by a separator colon.
694694
// A separator colon is the last `:` character in the regex `[/:\\]?[a-zA-Z]:` (note `\\` is `\` escaped).
695695
// This allows to correctly split strings such as `C:\foo:D:\:rw`.
696696
func volumeSplitN(raw string, n int) []string {

0 commit comments

Comments
 (0)