-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreaders.go
More file actions
55 lines (45 loc) · 1.18 KB
/
readers.go
File metadata and controls
55 lines (45 loc) · 1.18 KB
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
package noble
import (
"errors"
"os"
)
type rawReader struct{}
func (rr rawReader) Read(path string) (string, error) {
return path, nil
}
// Clone returns new empty instance of rawReader
func (rr rawReader) Clone() SecretStorage {
return &rawReader{}
}
// Read parameter value from environment variable and store into "cache"
type envReader struct {
cached string
}
// Read env.variable into internal cache
func (er *envReader) Read(path string) (string, error) {
if er.cached == "" {
er.cached = os.Getenv(path)
}
if er.cached == "" {
return er.cached, errors.New("unable to read OS environment variable:" + path)
}
return er.cached, nil
}
// Clone returns new empty instance of envReader
func (er envReader) Clone() SecretStorage {
return &envReader{}
}
// Read parameter value from environment variable dynamically
type dynReader struct{}
// Read env.variable dynamically
func (d *dynReader) Read(path string) (string, error) {
val := os.Getenv(path)
if val == "" {
return val, errors.New("unable to read OS environment variable:" + path)
}
return val, nil
}
// Clone returns new empty instance of dynReader
func (d dynReader) Clone() SecretStorage {
return &dynReader{}
}