You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
terraform/internal/rpcapi/credentials_source.go

41 lines
979 B

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package rpcapi
import (
svchost "github.com/hashicorp/terraform-svchost"
"github.com/hashicorp/terraform-svchost/auth"
"github.com/zclconf/go-cty/cty"
)
var _ auth.CredentialsSource = &credentialsSource{}
type credentialsSource struct {
configured map[svchost.Hostname]cty.Value
}
func newCredentialsSource() *credentialsSource {
return &credentialsSource{
configured: map[svchost.Hostname]cty.Value{},
}
}
func (c *credentialsSource) ForHost(host svchost.Hostname) (auth.HostCredentials, error) {
v, ok := c.configured[host]
if ok {
return auth.HostCredentialsFromObject(v), nil
}
return nil, nil
}
func (c *credentialsSource) StoreForHost(host svchost.Hostname, credentials auth.HostCredentialsWritable) error {
c.configured[host] = credentials.ToStore()
return nil
}
func (c *credentialsSource) ForgetForHost(host svchost.Hostname) error {
delete(c.configured, host)
return nil
}