-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
validate.go
47 lines (36 loc) · 1.1 KB
/
validate.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
package keeper
import (
"strings"
"github.com/google/uuid"
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
)
// ValidatedKeeperSpec analyses the tomlString passed as parameter and
// returns a newly-created Job if there are no validation errors inside the toml.
func ValidatedKeeperSpec(tomlString string) (job.Job, error) {
// Create a new job with a randomly generated uuid, which can be replaced with the one from tomlString.
var j = job.Job{
ExternalJobID: uuid.New(),
}
tree, err := toml.Load(tomlString)
if err != nil {
return j, err
}
if err := tree.Unmarshal(&j); err != nil {
return j, err
}
var spec job.KeeperSpec
if err := tree.Unmarshal(&spec); err != nil {
return j, err
}
j.KeeperSpec = &spec
if j.Type != job.Keeper {
return j, errors.Errorf("unsupported type %s", j.Type)
}
if strings.Contains(tomlString, "observationSource") ||
strings.Contains(tomlString, "ObservationSource") {
return j, errors.New("There should be no 'observationSource' parameter included in the toml")
}
return j, nil
}