forked from dabblebox/stash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.go
53 lines (41 loc) · 1.09 KB
/
inject.go
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
package stash
import (
"os"
"github.com/dabblebox/stash/component/action"
"github.com/dabblebox/stash/component/monitor"
"github.com/gookit/color"
)
// InjectOptions defines the criteria used to inject
// remote service configuration into local files.
type InjectOptions struct {
// Files list the target files.
// Required: true
// Default: []
Files []string
// Service specifies which service to use.
// Required: true
// Default: secrets-manager
Service string
// Output specifies the format for the file contents.
// Required: false
// Default: original
Output string
}
// Inject replaces local file tokens with values from a remote service.
func Inject(opt InjectOptions) ([]action.DownloadedFile, error) {
color.Disable()
gopt := action.InjectOpt{}
gopt.Files = opt.Files
gopt.Service = opt.Service
gopt.Output = opt.Output
m := monitor.New(os.Stderr, true)
files, err := action.Inject(gopt, action.Dep{
Stderr: os.NewFile(0, os.DevNull),
Stdout: os.NewFile(0, os.DevNull),
Monitor: &m,
})
if len(m.Errors) > 0 {
return files, m.Errors[0]
}
return files, err
}