Skip to content

Commit

Permalink
api/types: move RequestPrivilegeFunc to api/types/registry
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
thaJeztah committed Aug 30, 2024
1 parent 04b0e61 commit bb899c6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
25 changes: 12 additions & 13 deletions api/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,6 @@ type ImageBuildResponse struct {
OSType string
}

// RequestPrivilegeFunc is a function interface that
// clients can supply to retry operations after
// getting an authorization error.
// This function returns the registry authentication
// header value in base 64 format, or an error
// if the privilege request fails.
type RequestPrivilegeFunc func(context.Context) (string, error)

// NodeListOptions holds parameters to list nodes with.
type NodeListOptions struct {
Filters filters.Args
Expand Down Expand Up @@ -235,11 +227,18 @@ type PluginDisableOptions struct {

// PluginInstallOptions holds parameters to install a plugin.
type PluginInstallOptions struct {
Disabled bool
AcceptAllPermissions bool
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
RemoteRef string // RemoteRef is the plugin name on the registry
PrivilegeFunc RequestPrivilegeFunc
Disabled bool
AcceptAllPermissions bool
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
RemoteRef string // RemoteRef is the plugin name on the registry

// PrivilegeFunc is a function that clients can supply to retry operations
// after getting an authorization error. This function returns the registry
// authentication header value in base64 encoded format, or an error if the
// privilege request fails.
//
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
PrivilegeFunc func(context.Context) (string, error)
AcceptPermissionsFunc func(context.Context, PluginPrivileges) (bool, error)
Args []string
}
Expand Down
4 changes: 2 additions & 2 deletions api/types/image/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type PullOptions struct {
// authentication header value in base64 encoded format, or an error if the
// privilege request fails.
//
// Also see [github.com/docker/docker/api/types.RequestPrivilegeFunc].
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
PrivilegeFunc func(context.Context) (string, error)
Platform string
}
Expand All @@ -53,7 +53,7 @@ type PushOptions struct {
// authentication header value in base64 encoded format, or an error if the
// privilege request fails.
//
// Also see [github.com/docker/docker/api/types.RequestPrivilegeFunc].
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
PrivilegeFunc func(context.Context) (string, error)

// Platform is an optional field that selects a specific platform to push
Expand Down
13 changes: 13 additions & 0 deletions api/types/registry/authconfig.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package registry // import "github.com/docker/docker/api/types/registry"
import (
"context"
"encoding/base64"
"encoding/json"
"io"
Expand All @@ -12,6 +13,18 @@ import (
// authorization credentials for registry operations (push/pull).
const AuthHeader = "X-Registry-Auth"

// RequestAuthConfig is a function interface that clients can supply
// to retry operations after getting an authorization error.
//
// The function must return the [AuthHeader] value ([AuthConfig]), encoded
// in base64url format ([RFC4648, section 5]), which can be decoded by
// [DecodeAuthConfig].
//
// It must return an error if the privilege request fails.
//
// [RFC4648, section 5]: https://tools.ietf.org/html/rfc4648#section-5
type RequestAuthConfig func(context.Context) (string, error)

// AuthConfig contains authorization information for connecting to a Registry.
type AuthConfig struct {
Username string `json:"username,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions api/types/registry/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
type SearchOptions struct {
RegistryAuth string

// PrivilegeFunc is a [types.RequestPrivilegeFunc] the client can
// supply to retry operations after getting an authorization error.
// PrivilegeFunc is a function that clients can supply to retry operations
// after getting an authorization error. This function returns the registry
// authentication header value in base64 encoded format, or an error if the
// privilege request fails.
//
// It must return the registry authentication header value in base64
// format, or an error if the privilege request fails.
// For details, refer to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
PrivilegeFunc func(context.Context) (string, error)
Filters filters.Args
Limit int
Expand Down
10 changes: 10 additions & 0 deletions api/types/types_deprecated.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"context"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/storage"
Expand Down Expand Up @@ -97,3 +99,11 @@ type RootFS = image.RootFS
//
// Deprecated: use [image.InspectResponse].
type ImageInspect = image.InspectResponse

// RequestPrivilegeFunc is a function interface that clients can supply to
// retry operations after getting an authorization error.
// This function returns the registry authentication header value in base64
// format, or an error if the privilege request fails.
//
// Deprecated: moved to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
type RequestPrivilegeFunc func(context.Context) (string, error)

0 comments on commit bb899c6

Please sign in to comment.