Use constants for default action values

This commit is contained in:
Daniel
2022-10-13 14:18:34 +02:00
parent 106793b56a
commit c99c4aeeff
4 changed files with 18 additions and 14 deletions

View File

@@ -44,11 +44,11 @@ func updateGlobalConfigProfile(ctx context.Context, task *modules.Task) error {
action := cfgOptionDefaultAction()
switch action {
case "permit":
case DefaultActionPermitValue:
cfgDefaultAction = DefaultActionPermit
case "ask":
case DefaultActionAskValue:
cfgDefaultAction = DefaultActionAsk
case "block":
case DefaultActionBlockValue:
cfgDefaultAction = DefaultActionBlock
default:
// TODO: module error?

View File

@@ -23,6 +23,10 @@ var (
cfgOptionDefaultAction config.StringOption
cfgOptionDefaultActionOrder = 1
DefaultActionPermitValue = "permit"
DefaultActionBlockValue = "block"
DefaultActionAskValue = "ask"
// Setting "Prompt Desktop Notifications" at order 2.
// Setting "Prompt Timeout" at order 3.
@@ -182,7 +186,7 @@ func registerConfiguration() error { //nolint:maintidx
Key: CfgOptionDefaultActionKey,
Description: `The default network action is applied when nothing else allows or blocks an outgoing connection. Incoming connections are always blocked by default.`,
OptType: config.OptTypeString,
DefaultValue: "permit",
DefaultValue: DefaultActionPermitValue,
Annotations: config.Annotations{
config.DisplayHintAnnotation: config.DisplayHintOneOf,
config.DisplayOrderAnnotation: cfgOptionDefaultActionOrder,
@@ -191,17 +195,17 @@ func registerConfiguration() error { //nolint:maintidx
PossibleValues: []config.PossibleValue{
{
Name: "Allow",
Value: "permit",
Value: DefaultActionPermitValue,
Description: "Allow all connections",
},
{
Name: "Block",
Value: "block",
Value: DefaultActionBlockValue,
Description: "Block all connections",
},
{
Name: "Prompt",
Value: "ask",
Value: DefaultActionAskValue,
Description: "Prompt for decisions",
},
},
@@ -209,7 +213,7 @@ func registerConfiguration() error { //nolint:maintidx
if err != nil {
return err
}
cfgOptionDefaultAction = config.Concurrent.GetAsString(CfgOptionDefaultActionKey, "permit")
cfgOptionDefaultAction = config.Concurrent.GetAsString(CfgOptionDefaultActionKey, DefaultActionPermitValue)
cfgStringOptions[CfgOptionDefaultActionKey] = cfgOptionDefaultAction
// Disable Auto Permit

View File

@@ -175,11 +175,11 @@ func (profile *Profile) parseConfig() error {
profile.defaultAction = DefaultActionNotSet
if ok {
switch action {
case "permit":
case DefaultActionPermitValue:
profile.defaultAction = DefaultActionPermit
case "ask":
case DefaultActionAskValue:
profile.defaultAction = DefaultActionAsk
case "block":
case DefaultActionBlockValue:
profile.defaultAction = DefaultActionBlock
default:
lastErr = fmt.Errorf(`default action "%s" invalid`, action)

View File

@@ -174,7 +174,7 @@ func createSpecialProfile(profileID string, path string) *Profile {
// Resolved domain from the system resolver are checked again when
// attributed to a connection of a regular process. Otherwise, users
// would see two connection prompts for the same domain.
CfgOptionDefaultActionKey: "permit",
CfgOptionDefaultActionKey: DefaultActionPermitValue,
// Explicitly allow incoming connections.
CfgOptionBlockInboundKey: status.SecurityLevelOff,
// Explicitly allow localhost and answers to multicast protocols that
@@ -211,7 +211,7 @@ func createSpecialProfile(profileID string, path string) *Profile {
Source: SourceLocal,
PresentationPath: path,
Config: map[string]interface{}{
CfgOptionDefaultActionKey: "block",
CfgOptionDefaultActionKey: DefaultActionBlockValue,
CfgOptionEndpointsKey: []string{
"+ Localhost",
"+ .safing.io",
@@ -226,7 +226,7 @@ func createSpecialProfile(profileID string, path string) *Profile {
Source: SourceLocal,
PresentationPath: path,
Config: map[string]interface{}{
CfgOptionDefaultActionKey: "block",
CfgOptionDefaultActionKey: DefaultActionBlockValue,
CfgOptionEndpointsKey: []string{
"+ Localhost",
},