瀏覽代碼

postImagesCreate: move auth config decode when it's needed

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Antonio Murdaca 9 年之前
父節點
當前提交
a7d1aeceec
共有 2 個文件被更改,包括 14 次插入16 次删除
  1. 13 15
      api/server/router/local/image.go
  2. 1 1
      runconfig/opts/parse.go

+ 13 - 15
api/server/router/local/image.go

@@ -89,21 +89,8 @@ func (s *router) postImagesCreate(ctx context.Context, w http.ResponseWriter, r
 		repo    = r.Form.Get("repo")
 		repo    = r.Form.Get("repo")
 		tag     = r.Form.Get("tag")
 		tag     = r.Form.Get("tag")
 		message = r.Form.Get("message")
 		message = r.Form.Get("message")
-	)
-	authEncoded := r.Header.Get("X-Registry-Auth")
-	authConfig := &types.AuthConfig{}
-	if authEncoded != "" {
-		authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
-		if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
-			// for a pull it is not an error if no auth was given
-			// to increase compatibility with the existing api it is defaulting to be empty
-			authConfig = &types.AuthConfig{}
-		}
-	}
-
-	var (
-		err    error
-		output = ioutils.NewWriteFlusher(w)
+		err     error
+		output  = ioutils.NewWriteFlusher(w)
 	)
 	)
 	defer output.Close()
 	defer output.Close()
 
 
@@ -136,6 +123,17 @@ func (s *router) postImagesCreate(ctx context.Context, w http.ResponseWriter, r
 					}
 					}
 				}
 				}
 
 
+				authEncoded := r.Header.Get("X-Registry-Auth")
+				authConfig := &types.AuthConfig{}
+				if authEncoded != "" {
+					authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
+					if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
+						// for a pull it is not an error if no auth was given
+						// to increase compatibility with the existing api it is defaulting to be empty
+						authConfig = &types.AuthConfig{}
+					}
+				}
+
 				err = s.daemon.PullImage(ref, metaHeaders, authConfig, output)
 				err = s.daemon.PullImage(ref, metaHeaders, authConfig, output)
 			}
 			}
 		}
 		}

+ 1 - 1
runconfig/opts/parse.go

@@ -690,7 +690,7 @@ func validatePath(val string, validator func(string) bool) (string, error) {
 	return val, nil
 	return val, nil
 }
 }
 
 
-// SplitN splits raw into a maximum of n parts, separated by a separator colon.
+// volumeSplitN splits raw into a maximum of n parts, separated by a separator colon.
 // A separator colon is the last `:` character in the regex `[/:\\]?[a-zA-Z]:` (note `\\` is `\` escaped).
 // A separator colon is the last `:` character in the regex `[/:\\]?[a-zA-Z]:` (note `\\` is `\` escaped).
 // This allows to correctly split strings such as `C:\foo:D:\:rw`.
 // This allows to correctly split strings such as `C:\foo:D:\:rw`.
 func volumeSplitN(raw string, n int) []string {
 func volumeSplitN(raw string, n int) []string {