File: static.go

package info (click to toggle)
golang-github-hashicorp-terraform-svchost 0.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: makefile: 5; sh: 4
file content (38 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package auth

import (
	"fmt"

	"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
}

func (s staticCredentialsSource) StoreForHost(host svchost.Hostname, credentials HostCredentialsWritable) error {
	return fmt.Errorf("can't store new credentials in a static credentials source")
}

func (s staticCredentialsSource) ForgetForHost(host svchost.Hostname) error {
	return fmt.Errorf("can't discard credentials from a static credentials source")
}