Skip to content

Commit bb899c6

Browse files
committed
api/types: move RequestPrivilegeFunc to api/types/registry
Move the definition, but mostly keep it for documentation purposes, to prevent having to import the registry package in all places. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 04b0e61 commit bb899c6

5 files changed

Lines changed: 42 additions & 19 deletions

File tree

api/types/client.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ type ImageBuildResponse struct {
129129
OSType string
130130
}
131131

132-
// RequestPrivilegeFunc is a function interface that
133-
// clients can supply to retry operations after
134-
// getting an authorization error.
135-
// This function returns the registry authentication
136-
// header value in base 64 format, or an error
137-
// if the privilege request fails.
138-
type RequestPrivilegeFunc func(context.Context) (string, error)
139-
140132
// NodeListOptions holds parameters to list nodes with.
141133
type NodeListOptions struct {
142134
Filters filters.Args
@@ -235,11 +227,18 @@ type PluginDisableOptions struct {
235227

236228
// PluginInstallOptions holds parameters to install a plugin.
237229
type PluginInstallOptions struct {
238-
Disabled bool
239-
AcceptAllPermissions bool
240-
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
241-
RemoteRef string // RemoteRef is the plugin name on the registry
242-
PrivilegeFunc RequestPrivilegeFunc
230+
Disabled bool
231+
AcceptAllPermissions bool
232+
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
233+
RemoteRef string // RemoteRef is the plugin name on the registry
234+
235+
// PrivilegeFunc is a function that clients can supply to retry operations
236+
// after getting an authorization error. This function returns the registry
237+
// authentication header value in base64 encoded format, or an error if the
238+
// privilege request fails.
239+
//
240+
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
241+
PrivilegeFunc func(context.Context) (string, error)
243242
AcceptPermissionsFunc func(context.Context, PluginPrivileges) (bool, error)
244243
Args []string
245244
}

api/types/image/opts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type PullOptions struct {
3838
// authentication header value in base64 encoded format, or an error if the
3939
// privilege request fails.
4040
//
41-
// Also see [github.com/docker/docker/api/types.RequestPrivilegeFunc].
41+
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
4242
PrivilegeFunc func(context.Context) (string, error)
4343
Platform string
4444
}
@@ -53,7 +53,7 @@ type PushOptions struct {
5353
// authentication header value in base64 encoded format, or an error if the
5454
// privilege request fails.
5555
//
56-
// Also see [github.com/docker/docker/api/types.RequestPrivilegeFunc].
56+
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
5757
PrivilegeFunc func(context.Context) (string, error)
5858

5959
// Platform is an optional field that selects a specific platform to push

api/types/registry/authconfig.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package registry // import "github.com/docker/docker/api/types/registry"
22
import (
3+
"context"
34
"encoding/base64"
45
"encoding/json"
56
"io"
@@ -12,6 +13,18 @@ import (
1213
// authorization credentials for registry operations (push/pull).
1314
const AuthHeader = "X-Registry-Auth"
1415

16+
// RequestAuthConfig is a function interface that clients can supply
17+
// to retry operations after getting an authorization error.
18+
//
19+
// The function must return the [AuthHeader] value ([AuthConfig]), encoded
20+
// in base64url format ([RFC4648, section 5]), which can be decoded by
21+
// [DecodeAuthConfig].
22+
//
23+
// It must return an error if the privilege request fails.
24+
//
25+
// [RFC4648, section 5]: https://tools.ietf.org/html/rfc4648#section-5
26+
type RequestAuthConfig func(context.Context) (string, error)
27+
1528
// AuthConfig contains authorization information for connecting to a Registry.
1629
type AuthConfig struct {
1730
Username string `json:"username,omitempty"`

api/types/registry/search.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
type SearchOptions struct {
1111
RegistryAuth string
1212

13-
// PrivilegeFunc is a [types.RequestPrivilegeFunc] the client can
14-
// supply to retry operations after getting an authorization error.
13+
// PrivilegeFunc is a function that clients can supply to retry operations
14+
// after getting an authorization error. This function returns the registry
15+
// authentication header value in base64 encoded format, or an error if the
16+
// privilege request fails.
1517
//
16-
// It must return the registry authentication header value in base64
17-
// format, or an error if the privilege request fails.
18+
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
1819
PrivilegeFunc func(context.Context) (string, error)
1920
Filters filters.Args
2021
Limit int

api/types/types_deprecated.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package types
22

33
import (
4+
"context"
5+
46
"github.com/docker/docker/api/types/container"
57
"github.com/docker/docker/api/types/image"
68
"github.com/docker/docker/api/types/storage"
@@ -97,3 +99,11 @@ type RootFS = image.RootFS
9799
//
98100
// Deprecated: use [image.InspectResponse].
99101
type ImageInspect = image.InspectResponse
102+
103+
// RequestPrivilegeFunc is a function interface that clients can supply to
104+
// retry operations after getting an authorization error.
105+
// This function returns the registry authentication header value in base64
106+
// format, or an error if the privilege request fails.
107+
//
108+
// Deprecated: moved to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
109+
type RequestPrivilegeFunc func(context.Context) (string, error)

0 commit comments

Comments
 (0)