-
Notifications
You must be signed in to change notification settings - Fork 394
/
settings.go
67 lines (59 loc) · 1.82 KB
/
settings.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
package buildkitd
import (
"strconv"
"strings"
"time"
"github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors"
)
// Settings represents the buildkitd settings used to start up the daemon with.
type Settings struct {
CacheSizeMb int
CacheSizePct int
CacheKeepDuration int
Debug bool
BuildkitAddress string
LocalRegistryAddress string
AdditionalArgs []string
AdditionalConfig string
CniMtu uint16
Timeout time.Duration `hash:"ignore"`
TLSCA string
ClientTLSCert string
ClientTLSKey string
ServerTLSCert string
ServerTLSKey string
UseTCP bool
UseTLS bool
VolumeName string
IPTables string
MaxParallelism int
SatelliteName string `hash:"ignore"`
SatelliteDisplayName string `hash:"ignore"`
SatelliteOrgID string `hash:"ignore"`
SatelliteToken string `hash:"ignore"`
SatelliteIsManaged bool `hash:"ignore"`
EnableProfiler bool
NoUpdate bool `hash:"ignore"`
StartUpLockPath string `hash:"ignore"`
}
// Hash returns a secure hash of the settings.
func (s Settings) Hash() (string, error) {
hash, err := hashstructure.Hash(s, hashstructure.FormatV2, nil)
if err != nil {
return "", errors.Wrap(err, "hash settings")
}
return strconv.FormatUint(hash, 16), nil
}
// VerifyHash checks whether a given hash matches the settings.
func (s Settings) VerifyHash(hash string) (bool, error) {
newHash, err := hashstructure.Hash(s, hashstructure.FormatV2, nil)
if err != nil {
return false, errors.Wrap(err, "hash settings")
}
oldHash, err := strconv.ParseUint(strings.TrimSpace(hash), 16, 64)
if err != nil {
return false, errors.Wrap(err, "parse hash")
}
return oldHash == newHash, nil
}