forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.go
48 lines (38 loc) · 931 Bytes
/
source.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
package creds
import (
"github.com/concourse/atc"
"github.com/mitchellh/mapstructure"
)
type Source struct {
variablesResolver Variables
rawSource atc.Source
}
func NewSource(variables Variables, source atc.Source) Source {
return Source{
variablesResolver: variables,
rawSource: source,
}
}
func (s Source) Evaluate() (atc.Source, error) {
var untypedInput interface{}
err := evaluate(s.variablesResolver, s.rawSource, &untypedInput)
if err != nil {
return nil, err
}
var metadata mapstructure.Metadata
var source atc.Source
msConfig := &mapstructure.DecoderConfig{
Metadata: &metadata,
Result: &source,
WeaklyTypedInput: true,
DecodeHook: atc.SanitizeDecodeHook,
}
decoder, err := mapstructure.NewDecoder(msConfig)
if err != nil {
return nil, err
}
if err := decoder.Decode(untypedInput); err != nil {
return nil, err
}
return source, nil
}