creds

package
v0.0.0-...-a4cc684 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCredentialsNotFound = errors.New("credentials not found")
View Source
var ErrUnauthorized = errors.New("bad credentials")

Functions

func CheckAuth

func CheckAuth(ctx context.Context, image string, credentials docker.Credentials, trans http.RoundTripper) error

CheckAuth verifies that credentials can be used for image push

func NewCredentialsProvider

func NewCredentialsProvider(configPath string, opts ...Opt) docker.CredentialsProvider

NewCredentialsProvider returns new CredentialsProvider that tries to get credentials from docker/func config files.

In case getting credentials from the config files fails the caller provided callback (see WithPromptForCredentials) will be invoked to obtain credentials. The callback may be called multiple times in case the returned credentials are not correct (see WithVerifyCredentials).

When the callback succeeds the credentials will be saved by using helper defined in the func config. If the helper is not defined in the config file it may be picked by provided callback (see WithPromptForCredentialStore). The picked value will be saved in the func config.

To verify that credentials are correct custom callback can be used (see WithVerifyCredentials).

func RegistryEquals

func RegistryEquals(regA, regB string) bool

RegistryEquals checks whether registry matches in host and port with exception where empty port matches standard ports (80,443)

Types

type ChooseCredentialHelperCallback

type ChooseCredentialHelperCallback func(available []string) (string, error)

type CredentialsCallback

type CredentialsCallback func(registry string) (docker.Credentials, error)

type Opt

type Opt func(opts *credentialsProvider)

func WithAdditionalCredentialLoaders

func WithAdditionalCredentialLoaders(loaders ...CredentialsCallback) Opt

WithAdditionalCredentialLoaders adds custom callbacks for credential retrieval. The callbacks shall return ErrCredentialsNotFound if the credentials are not found. The callbacks are supposed to be non-interactive as opposed to WithPromptForCredentials.

This might be useful when credentials are shared with some other service.

Example: OpenShift builtin registry shares credentials with the cluster (k8s) credentials.

func WithPromptForCredentialStore

func WithPromptForCredentialStore(cbk ChooseCredentialHelperCallback) Opt

WithPromptForCredentialStore sets custom callback that is supposed to interactively ask user which credentials store/helper is used to store credentials obtained from user.

func WithPromptForCredentials

func WithPromptForCredentials(cbk CredentialsCallback) Opt

WithPromptForCredentials sets custom callback that is supposed to interactively ask for credentials in case the credentials cannot be found in configuration files. The callback may be called multiple times in case incorrect credentials were returned before.

func WithTransport

func WithTransport(transport http.RoundTripper) Opt

func WithVerifyCredentials

func WithVerifyCredentials(cbk VerifyCredentialsCallback) Opt

WithVerifyCredentials sets custom callback for credentials validation.

type VerifyCredentialsCallback

type VerifyCredentialsCallback func(ctx context.Context, image string, credentials docker.Credentials) error

VerifyCredentialsCallback checks if credentials are authorized for image push. If credentials are incorrect this callback shall return ErrUnauthorized.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL