mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-05 06:01:56 -04:00
Our requirements for discovering credentials for OCI registries include automatic discovery or manual specification of Docker CLI-style auth configuration files, which is a nontrivial amount of logic in itself, along with an OpenTofu-specific version of that configuration model embedded in the CLI configuration. To avoid incorporating all of this extra scope into package cliconfig, this new package ociauthconfig helps with modeling the overall OCI registry authentication policy and with the Docker-CLI-style auth config format. In a future commit, package cliconfig will drive this package's behavior based on the operator's CLI configuration settings, eventually returning an ociauthconfig.CredentialsConfigs representing the configured auth policy, which package main can then deliver to other components as part of an OCI client. This ultimately yields the ORAS Go library's credentials type, since that module has a relatively narrow indirect dependency surface area and will avoid us needlessly implementing and maintaining our own OCI registry client implementations. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package ociauthconfig
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
// NewCredentialsNotFoundError wraps the given error in an error value that would
|
|
// cause [IsCredentialsNotFoundError] to return true.
|
|
func NewCredentialsNotFoundError(inner error) error {
|
|
if inner == nil {
|
|
panic("wrapping nil error as 'credentials not found' error")
|
|
}
|
|
return credentialsNotFoundError{inner}
|
|
}
|
|
|
|
// IsCredentialsNotFoundError returns true if the given error is (or wraps)
|
|
// an error representing that a Docker credential helper lookup failed due
|
|
// to there being no credentials available for the requested server URL.
|
|
func IsCredentialsNotFoundError(err error) bool {
|
|
var target credentialsNotFoundError
|
|
return errors.As(err, &target)
|
|
}
|
|
|
|
type credentialsNotFoundError struct {
|
|
inner error
|
|
}
|
|
|
|
func (e credentialsNotFoundError) Error() string {
|
|
return e.inner.Error()
|
|
}
|
|
|
|
func (e credentialsNotFoundError) Unwrap() error {
|
|
return e.inner
|
|
}
|