This repository was archived by the owner on Apr 7, 2020. It is now read-only.
forked from telia-oss/concourse-sts-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.go
83 lines (73 loc) · 1.9 KB
/
models.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
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
package handler
import (
"strings"
"text/template"
)
// Configuration passed to the Lambda, pointing to an S3 object with the team configuration.
type Configuration struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
}
// Team represents the configuration for a single team.
type Team struct {
Name string `json:"name"`
Accounts []*Account `json:"accounts"`
// TODO make enum "parameter-store" | "secrets-manager"
ParameterType string `json:"parameterType"`
}
// Account represents the configuration for an assumable role.
type Account struct {
Name string `json:"name"`
RoleArn string `json:"roleArn"`
Duration int64 `json:"duration"`
}
// SecretPath represents the path used to write secrets into Secrets manager.
type SecretPath struct {
Team string
Account string
Template string
}
// ParameterStorePath represents the path used to write secrets into Secrets manager.
type ParameterStorePath struct {
Team string
Account string
Template string
}
// NewSecretPath ...
func NewSecretPath(team, account, template string) *SecretPath {
return &SecretPath{
Team: team,
Account: account,
Template: template,
}
}
// NewParameterStorePath ...
func NewParameterStorePath(team, account, template string) *ParameterStorePath {
return &ParameterStorePath{
Team: team,
Account: account,
Template: template,
}
}
func (p *SecretPath) String() (string, error) {
t, err := template.New("path").Option("missingkey=error").Parse(p.Template)
if err != nil {
return "", err
}
var s strings.Builder
if err = t.Execute(&s, p); err != nil {
return "", err
}
return s.String(), nil
}
func (p *ParameterStorePath) String() (string, error) {
t, err := template.New("path").Option("missingkey=error").Parse(p.Template)
if err != nil {
return "", err
}
var s strings.Builder
if err = t.Execute(&s, p); err != nil {
return "", err
}
return s.String(), nil
}