feat: add ability to set global properties

Not all properties can be set globally, and the "appName" in the global case is currently defaulted to `--global`. This is okay because domain label names cannot start with hyphens, and all app names must be valid domain label names.
This commit is contained in:
Jose Diaz-Gonzalez committed 2021-01-04 00:50:14 -05:00
1 parent f5fa94cc9c
commit e1425a85e4
7 files changed
+20 -6

No files matched your search

+8 -3
View File
@@ -12,9 +12,14 @@ import (
) )
// CommandPropertySet is a generic function that will set a property for a given plugin/app combination // CommandPropertySet is a generic function that will set a property for a given plugin/app combination
func CommandPropertySet(pluginName, appName, property, value string, properties map[string]string) { func CommandPropertySet(pluginName, appName, property, value string, properties map[string]string, globalProperties map[string]bool) {
if err := VerifyAppName(appName); err != nil { if appName != "--global" {
LogFail(err.Error()) if err := VerifyAppName(appName); err != nil {
LogFail(err.Error())
}
}
if !globalProperties[property] {
LogFail("Property cannot be specified globally")
} }
if property == "" { if property == "" {
LogFail("No property specified") LogFail("No property specified")
+3
View File
@@ -11,6 +11,9 @@ var (
DefaultProperties = map[string]string{ DefaultProperties = map[string]string{
"vector-sink": "", "vector-sink": "",
} }
// GlobalProperties is a map of all valid global logs properties
GlobalProperties = map[string]bool{}
) )
const VectorImage = "timberio/vector:0.11.X-debian" const VectorImage = "timberio/vector:0.11.X-debian"
+1 -1
View File
@@ -75,7 +75,7 @@ func CommandSet(appName string, property string, value string) error {
} }
} }
common.CommandPropertySet("logs", appName, property, value, DefaultProperties) common.CommandPropertySet("logs", appName, property, value, DefaultProperties, GlobalProperties)
if property == "vector-sink" { if property == "vector-sink" {
common.LogVerboseQuiet(fmt.Sprintf("Writing updated vector config to %s", filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "logs", "vector.json"))) common.LogVerboseQuiet(fmt.Sprintf("Writing updated vector config to %s", filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "logs", "vector.json")))
return writeVectorConfig() return writeVectorConfig()
+3
View File
@@ -22,6 +22,9 @@ var (
"attach-post-deploy": "", "attach-post-deploy": "",
"tld": "", "tld": "",
} }
// GlobalProperties is a map of all valid global network properties
GlobalProperties = map[string]bool{}
) )
// BuildConfig builds network config files // BuildConfig builds network config files
+1 -1
View File
@@ -169,6 +169,6 @@ func CommandSet(appName string, property string, value string) error {
} }
} }
common.CommandPropertySet("network", appName, property, value, DefaultProperties) common.CommandPropertySet("network", appName, property, value, DefaultProperties, GlobalProperties)
return nil return nil
} }
+3
View File
@@ -16,6 +16,9 @@ var (
DefaultProperties = map[string]string{ DefaultProperties = map[string]string{
"restart-policy": "on-failure:10", "restart-policy": "on-failure:10",
} }
// GlobalProperties is a map of all valid global ps properties
GlobalProperties = map[string]bool{}
) )
// Rebuild rebuilds app from base image // Rebuild rebuilds app from base image
+1 -1
View File
@@ -163,7 +163,7 @@ func CommandSet(appName string, property string, value string) error {
return dockeroptions.SetDockerOptionForPhases(appName, []string{"deploy"}, "restart", value) return dockeroptions.SetDockerOptionForPhases(appName, []string{"deploy"}, "restart", value)
} }
common.CommandPropertySet("ps", appName, property, value, DefaultProperties) common.CommandPropertySet("ps", appName, property, value, DefaultProperties, GlobalProperties)
return nil return nil
} }