Directly accept a privilege-func, and set the auth-header optionally.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -26,15 +26,23 @@ func (cli *Client) ImageCreate(ctx context.Context, parentReference string, opti |
| 26 | 26 |
if options.Platform != "" {
|
| 27 | 27 |
query.Set("platform", strings.ToLower(options.Platform))
|
| 28 | 28 |
} |
| 29 |
- resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth) |
|
| 29 |
+ resp, err := cli.tryImageCreate(ctx, query, staticAuth(options.RegistryAuth)) |
|
| 30 | 30 |
if err != nil {
|
| 31 | 31 |
return nil, err |
| 32 | 32 |
} |
| 33 | 33 |
return resp.Body, nil |
| 34 | 34 |
} |
| 35 | 35 |
|
| 36 |
-func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (*http.Response, error) {
|
|
| 37 |
- return cli.post(ctx, "/images/create", query, nil, http.Header{
|
|
| 38 |
- registry.AuthHeader: {registryAuth},
|
|
| 39 |
- }) |
|
| 36 |
+func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, resolveAuth registry.RequestAuthConfig) (*http.Response, error) {
|
|
| 37 |
+ hdr := http.Header{}
|
|
| 38 |
+ if resolveAuth != nil {
|
|
| 39 |
+ registryAuth, err := resolveAuth(ctx) |
|
| 40 |
+ if err != nil {
|
|
| 41 |
+ return nil, err |
|
| 42 |
+ } |
|
| 43 |
+ if registryAuth != "" {
|
|
| 44 |
+ hdr.Set(registry.AuthHeader, registryAuth) |
|
| 45 |
+ } |
|
| 46 |
+ } |
|
| 47 |
+ return cli.post(ctx, "/images/create", query, nil, hdr) |
|
| 40 | 48 |
} |
| ... | ... |
@@ -34,13 +34,9 @@ func (cli *Client) ImagePull(ctx context.Context, refStr string, options image.P |
| 34 | 34 |
query.Set("platform", strings.ToLower(options.Platform))
|
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
- resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth) |
|
| 37 |
+ resp, err := cli.tryImageCreate(ctx, query, staticAuth(options.RegistryAuth)) |
|
| 38 | 38 |
if cerrdefs.IsUnauthorized(err) && options.PrivilegeFunc != nil {
|
| 39 |
- newAuthHeader, privilegeErr := options.PrivilegeFunc(ctx) |
|
| 40 |
- if privilegeErr != nil {
|
|
| 41 |
- return nil, privilegeErr |
|
| 42 |
- } |
|
| 43 |
- resp, err = cli.tryImageCreate(ctx, query, newAuthHeader) |
|
| 39 |
+ resp, err = cli.tryImageCreate(ctx, query, options.PrivilegeFunc) |
|
| 44 | 40 |
} |
| 45 | 41 |
if err != nil {
|
| 46 | 42 |
return nil, err |