aboutsummaryrefslogtreecommitdiff
path: root/secrets/noop_client.go
blob: 1b6b72bc47279c9491f61f654d712bea0b49b4f6 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package secrets

import (
	"context"
	"sync"
	"time"
)

type NoopHandle struct{}

func (h *NoopHandle) Reference() string { return "NOOP" }

var _ Handle = (*NoopHandle)(nil)

// NoopClient does nothing and will never fail. It returns empty but
// non-nil credentials and handles where needed. This is useful for when
// code paths expect a secret client but using one is not needed.
type NoopClient struct {
	c chan Renewal
}

var _ Client = (*NoopClient)(nil)
var _ ClientManager = (*NoopClient)(nil)

func NewNoopClient() (ClientManager, error) {
	return &NoopClient{make(chan Renewal)}, nil
}

func (c *NoopClient) DatabaseCredential(ctx context.Context, path string) (*Credential, Handle, error) {
	return &Credential{}, &NoopHandle{}, nil
}

func (c *NoopClient) Secret(ctx context.Context, path string, out any) (Handle, error) {
	return &NoopHandle{}, nil
}

func (c *NoopClient) RawSecret(ctx context.Context, path string, out any) (Handle, error) {
	return &NoopHandle{}, nil
}

func (c *NoopClient) AWSIAMUser(ctx context.Context, name string) (*AWSCredential, Handle, error) {
	return &AWSCredential{}, &NoopHandle{}, nil
}

func (c *NoopClient) AWSAssumeRoleSimple(ctx context.Context, name string) (*AWSCredential, Handle, error) {
	return &AWSCredential{}, &NoopHandle{}, nil
}

func (c *NoopClient) AWSAssumeRole(ctx context.Context, name string, sessionName string, ttl time.Duration) (*AWSCredential, Handle, error) {
	return &AWSCredential{}, &NoopHandle{}, nil
}

func (c *NoopClient) WriteSecret(ctx context.Context, path string, in any) error {
	return nil
}

func (c *NoopClient) Encrypt(ctx context.Context, suffix string, data []byte) (string, error) {
	return "", nil
}

func (c *NoopClient) Decrypt(ctx context.Context, suffix, data string) ([]byte, error) {
	return nil, nil
}

func (c *NoopClient) Destroy(h Handle) error {
	return nil
}

func (c *NoopClient) MakeNonCritical(h Handle) error {
	return nil
}

func (c *NoopClient) Authenticate(ctx context.Context) error {
	return nil
}

func (c *NoopClient) Notifications() <-chan Renewal {
	return c.c
}

func (c *NoopClient) Run(ctx context.Context, wg *sync.WaitGroup) error {
	wg.Add(1)
	defer wg.Done()

	for {
		select {
		case <-ctx.Done():
			close(c.c)
			return nil
		}
	}
}