forked from concourse/concourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conjur.go
46 lines (38 loc) · 1.19 KB
/
conjur.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
package conjur
import (
"time"
"code.cloudfoundry.org/lager"
"github.com/chenbh/concourse/v6/atc/creds"
)
type IConjurClient interface {
RetrieveSecret(string) ([]byte, error)
}
type Conjur struct {
log lager.Logger
client IConjurClient
secretTemplates []*creds.SecretTemplate
}
func NewConjur(log lager.Logger, client IConjurClient, secretTemplates []*creds.SecretTemplate) *Conjur {
return &Conjur{
log: log,
client: client,
secretTemplates: secretTemplates,
}
}
func (c Conjur) NewSecretLookupPaths(teamName string, pipelineName string, allowRootPath bool) []creds.SecretLookupPath {
lookupPaths := []creds.SecretLookupPath{}
for _, template := range c.secretTemplates {
c.log.Info(" teamname: " + teamName + "pipeline: " + pipelineName)
if lPath := creds.NewSecretLookupWithTemplate(template, teamName, pipelineName); lPath != nil {
lookupPaths = append(lookupPaths, lPath)
}
}
return lookupPaths
}
func (c Conjur) Get(secretPath string) (interface{}, *time.Time, bool, error) {
secretValue, err := c.client.RetrieveSecret(secretPath)
if err != nil {
return nil, nil, false, nil
}
return string(secretValue), nil, true, nil
}