opentofu/svchost/auth/static.go
Martin Atkins d5b0beac01 svchost/auth: static credentials source
This uses an in-memory table of credentials keyed on hostname. This is
the simplest possible credentials source that can actually return
credentials, and is suitable for representing statically-configured
credentials from configuration.
2017-10-19 11:18:43 -07:00

29 lines
767 B
Go

package auth
import (
"github.com/hashicorp/terraform/svchost"
)
// StaticCredentialsSource is a credentials source that retrieves credentials
// from the provided map. It returns nil if a requested hostname is not
// present in the map.
//
// The caller should not modify the given map after passing it to this function.
func StaticCredentialsSource(creds map[svchost.Hostname]map[string]interface{}) CredentialsSource {
return staticCredentialsSource(creds)
}
type staticCredentialsSource map[svchost.Hostname]map[string]interface{}
func (s staticCredentialsSource) ForHost(host svchost.Hostname) (HostCredentials, error) {
if s == nil {
return nil, nil
}
if m, exists := s[host]; exists {
return HostCredentialsFromMap(m), nil
}
return nil, nil
}