Signed-off-by: Xiao YongBiao <xyb4638@gmail.com>
| ... | ... |
@@ -57,37 +57,35 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite |
| 57 | 57 |
} |
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 |
- if err == nil {
|
|
| 61 |
- if image != "" { //pull
|
|
| 62 |
- metaHeaders := map[string][]string{}
|
|
| 63 |
- for k, v := range r.Header {
|
|
| 64 |
- if strings.HasPrefix(k, "X-Meta-") {
|
|
| 65 |
- metaHeaders[k] = v |
|
| 66 |
- } |
|
| 60 |
+ if image != "" { //pull
|
|
| 61 |
+ metaHeaders := map[string][]string{}
|
|
| 62 |
+ for k, v := range r.Header {
|
|
| 63 |
+ if strings.HasPrefix(k, "X-Meta-") {
|
|
| 64 |
+ metaHeaders[k] = v |
|
| 67 | 65 |
} |
| 66 |
+ } |
|
| 68 | 67 |
|
| 69 |
- authEncoded := r.Header.Get("X-Registry-Auth")
|
|
| 70 |
- authConfig := &types.AuthConfig{}
|
|
| 71 |
- if authEncoded != "" {
|
|
| 72 |
- authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) |
|
| 73 |
- if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
|
|
| 74 |
- // for a pull it is not an error if no auth was given |
|
| 75 |
- // to increase compatibility with the existing api it is defaulting to be empty |
|
| 76 |
- authConfig = &types.AuthConfig{}
|
|
| 77 |
- } |
|
| 78 |
- } |
|
| 79 |
- err = s.backend.PullImage(ctx, image, tag, platform, metaHeaders, authConfig, output) |
|
| 80 |
- } else { //import
|
|
| 81 |
- src := r.Form.Get("fromSrc")
|
|
| 82 |
- // 'err' MUST NOT be defined within this block, we need any error |
|
| 83 |
- // generated from the download to be available to the output |
|
| 84 |
- // stream processing below |
|
| 85 |
- os := "" |
|
| 86 |
- if platform != nil {
|
|
| 87 |
- os = platform.OS |
|
| 68 |
+ authEncoded := r.Header.Get("X-Registry-Auth")
|
|
| 69 |
+ authConfig := &types.AuthConfig{}
|
|
| 70 |
+ if authEncoded != "" {
|
|
| 71 |
+ authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) |
|
| 72 |
+ if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
|
|
| 73 |
+ // for a pull it is not an error if no auth was given |
|
| 74 |
+ // to increase compatibility with the existing api it is defaulting to be empty |
|
| 75 |
+ authConfig = &types.AuthConfig{}
|
|
| 88 | 76 |
} |
| 89 |
- err = s.backend.ImportImage(src, repo, os, tag, message, r.Body, output, r.Form["changes"]) |
|
| 90 | 77 |
} |
| 78 |
+ err = s.backend.PullImage(ctx, image, tag, platform, metaHeaders, authConfig, output) |
|
| 79 |
+ } else { //import
|
|
| 80 |
+ src := r.Form.Get("fromSrc")
|
|
| 81 |
+ // 'err' MUST NOT be defined within this block, we need any error |
|
| 82 |
+ // generated from the download to be available to the output |
|
| 83 |
+ // stream processing below |
|
| 84 |
+ os := "" |
|
| 85 |
+ if platform != nil {
|
|
| 86 |
+ os = platform.OS |
|
| 87 |
+ } |
|
| 88 |
+ err = s.backend.ImportImage(src, repo, os, tag, message, r.Body, output, r.Form["changes"]) |
|
| 91 | 89 |
} |
| 92 | 90 |
if err != nil {
|
| 93 | 91 |
if !output.Flushed() {
|