-
Notifications
You must be signed in to change notification settings - Fork 21
/
checks.go
54 lines (44 loc) · 1.42 KB
/
checks.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
// SPDX-FileCopyrightText: 2017 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
"errors"
"strings"
)
type parsedCheck struct {
name string
deviceCredentialPath string
wrpCredentialPath string
inputValue interface{}
assertion binOp
inversed bool
}
var (
errNameRequired = errors.New("Name is required")
errDeviceCredPathRequired = errors.New("DeviceCredentialPath is required")
errInputValueOrWRPCredPathRequired = errors.New("Either InputValue or WRPCredentialPath is required")
)
func parseDeviceAccessCheck(config deviceAccessCheck) (*parsedCheck, error) {
parsedCheck := &parsedCheck{
name: strings.TrimSpace(config.Name),
wrpCredentialPath: strings.TrimSpace(config.WRPCredentialPath),
deviceCredentialPath: strings.TrimSpace(config.DeviceCredentialPath),
inputValue: config.InputValue,
inversed: config.Inversed,
}
if parsedCheck.name == "" {
return nil, errNameRequired
}
if parsedCheck.deviceCredentialPath == "" {
return nil, errDeviceCredPathRequired
}
if parsedCheck.inputValue == nil && parsedCheck.wrpCredentialPath == "" {
return nil, errInputValueOrWRPCredPathRequired
}
check, errBinOp := newBinOp(config.Op)
if errBinOp != nil {
return nil, errBinOp
}
parsedCheck.assertion = check
return parsedCheck, nil
}