Files
opentf/internal/command/cliconfig/ociauthconfig/errors.go
Martin Atkins 44f171c270 ociauthconfig: Policy layer for OCI registry authentication
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>
2025-03-13 08:19:57 -07:00

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
}