-
Notifications
You must be signed in to change notification settings - Fork 28
/
validate.go
73 lines (62 loc) · 1.96 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
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
// SPDX-License-Identifier: Apache-2.0
package database
import (
"fmt"
"strings"
"github.com/go-vela/types/constants"
"github.com/sirupsen/logrus"
)
// Validate verifies the required fields from the provided configuration are populated correctly.
func (c *config) Validate() error {
logrus.Trace("validating database configuration for engine")
// verify a database driver was provided
if len(c.Driver) == 0 {
return fmt.Errorf("no database driver provided")
}
// verify a database address was provided
if len(c.Address) == 0 {
return fmt.Errorf("no database address provided")
}
// check if the database address has a trailing slash
if strings.HasSuffix(c.Address, "/") {
return fmt.Errorf("invalid database address provided: address must not have trailing slash")
}
// verify a database encryption key was provided
if len(c.EncryptionKey) == 0 {
return fmt.Errorf("no database encryption key provided")
}
// check the database encryption key length - enforce AES-256 by forcing 32 characters in the key
if len(c.EncryptionKey) != 32 {
return fmt.Errorf("invalid database encryption key provided: key length (%d) must be 32 characters", len(c.EncryptionKey))
}
// verify the database compression level is valid
switch c.CompressionLevel {
case constants.CompressionNegOne:
fallthrough
case constants.CompressionZero:
fallthrough
case constants.CompressionOne:
fallthrough
case constants.CompressionTwo:
fallthrough
case constants.CompressionThree:
fallthrough
case constants.CompressionFour:
fallthrough
case constants.CompressionFive:
fallthrough
case constants.CompressionSix:
fallthrough
case constants.CompressionSeven:
fallthrough
case constants.CompressionEight:
fallthrough
case constants.CompressionNine:
break
default:
return fmt.Errorf("invalid database compression level provided: level (%d) must be between %d and %d",
c.CompressionLevel, constants.CompressionNegOne, constants.CompressionNine,
)
}
return nil
}