Skip to content

Commit 6d83a83

Browse files
cfergeauanjannath
authored andcommitted
config: Don't export the validate* functions
They are not used outside of the `config` package except for ValidateBool (which is used in the preflight package to register the skip-* settings, and which is still exported after this commit) Since validateMemory can be overridden, it's better if it's only possible to do this from within the `config` package, ie it's better if it's validateMemory() and not ValidateMemory().
1 parent 4ac0c86 commit 6d83a83

File tree

5 files changed

+53
-53
lines changed

5 files changed

+53
-53
lines changed

pkg/crc/config/secret_config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const (
1515
func newTestConfigSecret() (*Config, error) {
1616
cfg := New(NewEmptyInMemoryStorage(), NewEmptyInMemorySecretStorage())
1717

18-
cfg.AddSetting(password, Secret(""), ValidateString, SuccessfullyApplied, "")
19-
cfg.AddSetting(secret, Secret("apples"), ValidateString, SuccessfullyApplied, "")
18+
cfg.AddSetting(password, Secret(""), validateString, SuccessfullyApplied, "")
19+
cfg.AddSetting(secret, Secret("apples"), validateString, SuccessfullyApplied, "")
2020
return cfg, nil
2121
}
2222

pkg/crc/config/settings.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ func RegisterSettings(cfg *Config) {
4646
return ValidateBool(value)
4747
}
4848

49-
validateCPUs := func(value interface{}) (bool, string) {
50-
return ValidateCPUs(value, GetPreset(cfg))
49+
validCPUs := func(value interface{}) (bool, string) {
50+
return validateCPUs(value, GetPreset(cfg))
5151
}
5252

53-
validateMemory := func(value interface{}) (bool, string) {
54-
return ValidateMemory(value, GetPreset(cfg))
53+
validMemory := func(value interface{}) (bool, string) {
54+
return validateMemory(value, GetPreset(cfg))
5555
}
5656

57-
validateBundlePath := func(value interface{}) (bool, string) {
58-
return ValidateBundlePath(value, GetPreset(cfg))
57+
validBundlePath := func(value interface{}) (bool, string) {
58+
return validateBundlePath(value, GetPreset(cfg))
5959
}
6060

6161
validateSmbSharedDirs := func(value interface{}) (bool, string) {
@@ -73,16 +73,16 @@ func RegisterSettings(cfg *Config) {
7373
cfg.AddSetting(Preset, version.GetDefaultPreset().String(), validatePreset, RequiresDeleteAndSetupMsg,
7474
fmt.Sprintf("Virtual machine preset (valid values are: %s)", preset.AllPresets()))
7575
// Start command settings in config
76-
cfg.AddSetting(Bundle, defaultBundlePath(cfg), validateBundlePath, SuccessfullyApplied, BundleHelpMsg(cfg))
77-
cfg.AddSetting(CPUs, defaultCPUs(cfg), validateCPUs, RequiresRestartMsg,
76+
cfg.AddSetting(Bundle, defaultBundlePath(cfg), validBundlePath, SuccessfullyApplied, BundleHelpMsg(cfg))
77+
cfg.AddSetting(CPUs, defaultCPUs(cfg), validCPUs, RequiresRestartMsg,
7878
fmt.Sprintf("Number of CPU cores (must be greater than or equal to '%d')", defaultCPUs(cfg)))
79-
cfg.AddSetting(Memory, defaultMemory(cfg), validateMemory, RequiresRestartMsg,
79+
cfg.AddSetting(Memory, defaultMemory(cfg), validMemory, RequiresRestartMsg,
8080
fmt.Sprintf("Memory size in MiB (must be greater than or equal to '%d')", defaultMemory(cfg)))
81-
cfg.AddSetting(DiskSize, constants.DefaultDiskSize, ValidateDiskSize, RequiresRestartMsg,
81+
cfg.AddSetting(DiskSize, constants.DefaultDiskSize, validateDiskSize, RequiresRestartMsg,
8282
fmt.Sprintf("Total size in GiB of the disk (must be greater than or equal to '%d')", constants.DefaultDiskSize))
83-
cfg.AddSetting(NameServer, "", ValidateIPAddress, SuccessfullyApplied,
83+
cfg.AddSetting(NameServer, "", validateIPAddress, SuccessfullyApplied,
8484
"IPv4 address of nameserver (string, like '1.1.1.1 or 8.8.8.8')")
85-
cfg.AddSetting(PullSecretFile, "", ValidatePath, SuccessfullyApplied,
85+
cfg.AddSetting(PullSecretFile, "", validatePath, SuccessfullyApplied,
8686
fmt.Sprintf("Path of image pull secret (download from %s)", constants.CrcLandingPageURL))
8787
cfg.AddSetting(DisableUpdateCheck, false, ValidateBool, SuccessfullyApplied,
8888
"Disable update check (true/false, default: false)")
@@ -91,7 +91,7 @@ func RegisterSettings(cfg *Config) {
9191

9292
// Shared directories configs
9393
if runtime.GOOS == "windows" {
94-
cfg.AddSetting(SharedDirPassword, Secret(""), ValidateString, SuccessfullyApplied,
94+
cfg.AddSetting(SharedDirPassword, Secret(""), validateString, SuccessfullyApplied,
9595
"Password used while using CIFS/SMB file sharing (It is the password for the current logged in user)")
9696

9797
cfg.AddSetting(EnableSharedDirs, false, validateSmbSharedDirs, SuccessfullyApplied,
@@ -109,27 +109,27 @@ func RegisterSettings(cfg *Config) {
109109
cfg.AddSetting(HostNetworkAccess, false, validateHostNetworkAccess, RequiresCleanupAndSetupMsg,
110110
"Allow TCP/IP connections from the CRC VM to services running on the host (true/false, default: false)")
111111
// Proxy Configuration
112-
cfg.AddSetting(HTTPProxy, "", ValidateHTTPProxy, SuccessfullyApplied,
112+
cfg.AddSetting(HTTPProxy, "", validateHTTPProxy, SuccessfullyApplied,
113113
"HTTP proxy URL (string, like 'http://my-proxy.com:8443')")
114-
cfg.AddSetting(HTTPSProxy, "", ValidateHTTPSProxy, SuccessfullyApplied,
114+
cfg.AddSetting(HTTPSProxy, "", validateHTTPSProxy, SuccessfullyApplied,
115115
"HTTPS proxy URL (string, like 'https://my-proxy.com:8443')")
116-
cfg.AddSetting(NoProxy, "", ValidateNoProxy, SuccessfullyApplied,
116+
cfg.AddSetting(NoProxy, "", validateNoProxy, SuccessfullyApplied,
117117
"Hosts, ipv4 addresses or CIDR which do not use a proxy (string, comma-separated list such as '127.0.0.1,192.168.100.1/24')")
118-
cfg.AddSetting(ProxyCAFile, "", ValidatePath, SuccessfullyApplied,
118+
cfg.AddSetting(ProxyCAFile, "", validatePath, SuccessfullyApplied,
119119
"Path to an HTTPS proxy certificate authority (CA)")
120120

121121
cfg.AddSetting(EnableClusterMonitoring, false, ValidateBool, SuccessfullyApplied,
122122
"Enable cluster monitoring Operator (true/false, default: false)")
123123

124124
// Telemeter Configuration
125-
cfg.AddSetting(ConsentTelemetry, "", ValidateYesNo, SuccessfullyApplied,
125+
cfg.AddSetting(ConsentTelemetry, "", validateYesNo, SuccessfullyApplied,
126126
"Consent to collection of anonymous usage data (yes/no)")
127127

128-
cfg.AddSetting(KubeAdminPassword, "", ValidateString, SuccessfullyApplied,
128+
cfg.AddSetting(KubeAdminPassword, "", validateString, SuccessfullyApplied,
129129
"User defined kubeadmin password")
130-
cfg.AddSetting(IngressHTTPPort, constants.OpenShiftIngressHTTPPort, ValidatePort, RequiresHTTPPortChangeWarning,
130+
cfg.AddSetting(IngressHTTPPort, constants.OpenShiftIngressHTTPPort, validatePort, RequiresHTTPPortChangeWarning,
131131
fmt.Sprintf("HTTP port to use for OpenShift ingress/routes on the host (1024-65535, default: %d)", constants.OpenShiftIngressHTTPPort))
132-
cfg.AddSetting(IngressHTTPSPort, constants.OpenShiftIngressHTTPSPort, ValidatePort, RequiresHTTPSPortChangeWarning,
132+
cfg.AddSetting(IngressHTTPSPort, constants.OpenShiftIngressHTTPSPort, validatePort, RequiresHTTPSPortChangeWarning,
133133
fmt.Sprintf("HTTPS port to use for OpenShift ingress/routes on the host (1024-65535, default: %d)", constants.OpenShiftIngressHTTPSPort))
134134

135135
if err := cfg.RegisterNotifier(Preset, presetChanged); err != nil {

pkg/crc/config/settings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func validateMemoryNoPhysicalCheck(value interface{}, preset crcpreset.Preset) (
2626
}
2727

2828
func newInMemoryConfig() (*Config, error) {
29-
ValidateMemory = validateMemoryNoPhysicalCheck
29+
validateMemory = validateMemoryNoPhysicalCheck
3030
cfg := New(NewEmptyInMemoryStorage(), NewEmptyInMemorySecretStorage())
3131

3232
RegisterSettings(cfg)

pkg/crc/config/validations.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func ValidateBool(value interface{}) (bool, string) {
2121
return true, ""
2222
}
2323

24-
func ValidateString(value interface{}) (bool, string) {
24+
func validateString(value interface{}) (bool, string) {
2525
if _, err := cast.ToStringE(value); err != nil {
2626
return false, "must be a valid string"
2727
}
2828
return true, ""
2929
}
3030

31-
// ValidateDiskSize checks if provided disk size is valid in the config
32-
func ValidateDiskSize(value interface{}) (bool, string) {
31+
// validateDiskSize checks if provided disk size is valid in the config
32+
func validateDiskSize(value interface{}) (bool, string) {
3333
diskSize, err := cast.ToIntE(value)
3434
if err != nil {
3535
return false, fmt.Sprintf("could not convert '%s' to integer", value)
@@ -41,8 +41,8 @@ func ValidateDiskSize(value interface{}) (bool, string) {
4141
return true, ""
4242
}
4343

44-
// ValidateCPUs checks if provided cpus count is valid in the config
45-
func ValidateCPUs(value interface{}, preset crcpreset.Preset) (bool, string) {
44+
// validateCPUs checks if provided cpus count is valid in the config
45+
func validateCPUs(value interface{}, preset crcpreset.Preset) (bool, string) {
4646
v, err := cast.ToIntE(value)
4747
if err != nil {
4848
return false, fmt.Sprintf("requires integer value >= %d", constants.GetDefaultCPUs(preset))
@@ -53,9 +53,9 @@ func ValidateCPUs(value interface{}, preset crcpreset.Preset) (bool, string) {
5353
return true, ""
5454
}
5555

56-
// ValidateMemory checks if provided memory is valid in the config
56+
// validateMemory checks if provided memory is valid in the config
5757
// It's defined as a variable so that it can be overridden in tests to disable the physical memory check
58-
var ValidateMemory = func(value interface{}, preset crcpreset.Preset) (bool, string) {
58+
var validateMemory = func(value interface{}, preset crcpreset.Preset) (bool, string) {
5959
v, err := cast.ToIntE(value)
6060
if err != nil {
6161
return false, fmt.Sprintf("requires integer value in MiB >= %d", constants.GetDefaultMemory(preset))
@@ -66,55 +66,55 @@ var ValidateMemory = func(value interface{}, preset crcpreset.Preset) (bool, str
6666
return true, ""
6767
}
6868

69-
// ValidateBundlePath checks if the provided bundle path is valid
70-
func ValidateBundlePath(value interface{}, preset crcpreset.Preset) (bool, string) {
69+
// validateBundlePath checks if the provided bundle path is valid
70+
func validateBundlePath(value interface{}, preset crcpreset.Preset) (bool, string) {
7171
if err := validation.ValidateBundlePath(cast.ToString(value), preset); err != nil {
7272
return false, err.Error()
7373
}
7474
return true, ""
7575
}
7676

77-
// ValidateIP checks if provided IP is valid
78-
func ValidateIPAddress(value interface{}) (bool, string) {
77+
// validateIP checks if provided IP is valid
78+
func validateIPAddress(value interface{}) (bool, string) {
7979
if err := validation.ValidateIPAddress(cast.ToString(value)); err != nil {
8080
return false, err.Error()
8181
}
8282
return true, ""
8383
}
8484

85-
// ValidatePath checks if provided path is exist
86-
func ValidatePath(value interface{}) (bool, string) {
85+
// validatePath checks if provided path is exist
86+
func validatePath(value interface{}) (bool, string) {
8787
if err := validation.ValidatePath(cast.ToString(value)); err != nil {
8888
return false, err.Error()
8989
}
9090
return true, ""
9191
}
9292

93-
// ValidateHTTPProxy checks if given URI is valid for a HTTP proxy
94-
func ValidateHTTPProxy(value interface{}) (bool, string) {
93+
// validateHTTPProxy checks if given URI is valid for a HTTP proxy
94+
func validateHTTPProxy(value interface{}) (bool, string) {
9595
if err := network.ValidateProxyURL(cast.ToString(value), false); err != nil {
9696
return false, err.Error()
9797
}
9898
return true, ""
9999
}
100100

101-
// ValidateHTTPSProxy checks if given URI is valid for a HTTPS proxy
102-
func ValidateHTTPSProxy(value interface{}) (bool, string) {
101+
// validateHTTPSProxy checks if given URI is valid for a HTTPS proxy
102+
func validateHTTPSProxy(value interface{}) (bool, string) {
103103
if err := network.ValidateProxyURL(cast.ToString(value), true); err != nil {
104104
return false, err.Error()
105105
}
106106
return true, ""
107107
}
108108

109-
// ValidateNoProxy checks if the NoProxy string has the correct format
110-
func ValidateNoProxy(value interface{}) (bool, string) {
109+
// validateNoProxy checks if the NoProxy string has the correct format
110+
func validateNoProxy(value interface{}) (bool, string) {
111111
if strings.Contains(cast.ToString(value), " ") {
112112
return false, "NoProxy string can't contain spaces"
113113
}
114114
return true, ""
115115
}
116116

117-
func ValidateYesNo(value interface{}) (bool, string) {
117+
func validateYesNo(value interface{}) (bool, string) {
118118
if cast.ToString(value) == "yes" || cast.ToString(value) == "no" {
119119
return true, ""
120120
}
@@ -129,7 +129,7 @@ func validatePreset(value interface{}) (bool, string) {
129129
return true, ""
130130
}
131131

132-
func ValidatePort(value interface{}) (bool, string) {
132+
func validatePort(value interface{}) (bool, string) {
133133
port, err := cast.ToUintE(value)
134134
if err != nil {
135135
return false, "Requires integer value in range of 1024-65535"

pkg/crc/config/viper_config_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const (
1717
)
1818

1919
func newTestConfig(configFile, envPrefix string) (*Config, error) {
20-
validateCPUs := func(value interface{}) (bool, string) {
21-
return ValidateCPUs(value, preset.OpenShift)
20+
validCPUs := func(value interface{}) (bool, string) {
21+
return validateCPUs(value, preset.OpenShift)
2222
}
2323
storage, err := NewViperStorage(configFile, envPrefix)
2424
if err != nil {
@@ -27,8 +27,8 @@ func newTestConfig(configFile, envPrefix string) (*Config, error) {
2727

2828
secretStorage := NewEmptyInMemorySecretStorage()
2929
config := New(storage, secretStorage)
30-
config.AddSetting(cpus, 4, validateCPUs, RequiresRestartMsg, "")
31-
config.AddSetting(nameServer, "", ValidateIPAddress, SuccessfullyApplied, "")
30+
config.AddSetting(cpus, 4, validCPUs, RequiresRestartMsg, "")
31+
config.AddSetting(nameServer, "", validateIPAddress, SuccessfullyApplied, "")
3232
return config, nil
3333
}
3434

@@ -142,14 +142,14 @@ func TestViperConfigBindFlagSet(t *testing.T) {
142142
dir := t.TempDir()
143143
configFile := filepath.Join(dir, "crc.json")
144144

145-
validateCPUs := func(value interface{}) (bool, string) {
146-
return ValidateCPUs(value, preset.OpenShift)
145+
validCPUs := func(value interface{}) (bool, string) {
146+
return validateCPUs(value, preset.OpenShift)
147147
}
148148
storage, err := NewViperStorage(configFile, "CRC")
149149
require.NoError(t, err)
150150
config := New(storage, NewEmptyInMemorySecretStorage())
151-
config.AddSetting(cpus, 4, validateCPUs, RequiresRestartMsg, "")
152-
config.AddSetting(nameServer, "", ValidateIPAddress, SuccessfullyApplied, "")
151+
config.AddSetting(cpus, 4, validCPUs, RequiresRestartMsg, "")
152+
config.AddSetting(nameServer, "", validateIPAddress, SuccessfullyApplied, "")
153153

154154
flagSet := pflag.NewFlagSet("start", pflag.ExitOnError)
155155
flagSet.IntP(cpus, "c", 4, "")

0 commit comments

Comments
 (0)