feat: implement global support for setting proxy type

This commit is contained in:
Jose Diaz-Gonzalez
2024-01-19 04:13:55 -05:00
parent ea28367689
commit 7fbb86093b
6 changed files with 73 additions and 8 deletions

View File

@@ -5,5 +5,18 @@ import (
)
func getAppProxyType(appName string) string {
return config.GetWithDefault(appName, "DOKKU_APP_PROXY_TYPE", "nginx")
return config.GetWithDefault(appName, "DOKKU_APP_PROXY_TYPE", "")
}
func getComputedProxyType(appName string) string {
proxyType := getGlobalProxyType()
if proxyType == "" {
proxyType = getAppProxyType(appName)
}
return proxyType
}
func getGlobalProxyType() string {
return config.GetWithDefault("--global", "DOKKU_PROXY_TYPE", "nginx")
}

View File

@@ -11,8 +11,10 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
}
flags := map[string]common.ReportFunc{
"--proxy-enabled": reportEnabled,
"--proxy-type": reportType,
"--proxy-enabled": reportEnabled,
"--proxy-computed-type": reportComputedType,
"--proxy-global-type": reportGlobalType,
"--proxy-type": reportType,
}
flagKeys := []string{}
@@ -35,6 +37,19 @@ func reportEnabled(appName string) string {
return proxyEnabled
}
func reportComputedType(appName string) string {
proxyType := getGlobalProxyType()
if proxyType == "" {
proxyType = getAppProxyType(appName)
}
return proxyType
}
func reportGlobalType(appName string) string {
return getGlobalProxyType()
}
func reportType(appName string) string {
return getAppProxyType(appName)
}

View File

@@ -56,9 +56,14 @@ func main() {
}
case "set":
args := flag.NewFlagSet("proxy:set", flag.ExitOnError)
global := args.Bool("global", false, "--global: set a global property")
args.Parse(os.Args[2:])
appName := args.Arg(0)
proxyType := args.Arg(1)
if *global {
appName = "--global"
proxyType = args.Arg(0)
}
err = proxy.CommandSet(appName, proxyType)
default:
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)

View File

@@ -79,16 +79,22 @@ func CommandReport(appName string, format string, infoFlag string) error {
// CommandSet sets a proxy for an app
func CommandSet(appName string, proxyType string) error {
if err := common.VerifyAppName(appName); err != nil {
return err
if appName != "--global" {
if err := common.VerifyAppName(appName); err != nil {
return err
}
}
if len(proxyType) < 2 {
return errors.New("Please specify a proxy type")
}
key := "DOKKU_APP_PROXY_TYPE"
if appName == "--global" {
key = "DOKKU_PROXY_TYPE"
}
entries := map[string]string{
"DOKKU_APP_PROXY_TYPE": proxyType,
key: proxyType,
}
return config.SetMany(appName, entries, false)
}

View File

@@ -17,7 +17,7 @@ func TriggerProxyIsEnabled(appName string) error {
// TriggerProxyType prints out the current proxy type, defaulting to nginx
func TriggerProxyType(appName string) error {
proxyType := getAppProxyType(appName)
proxyType := getComputedProxyType(appName)
fmt.Println(proxyType)
return nil