2017-04-24 09:03:30 -06:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
|
|
import (
|
2021-02-19 23:44:41 -05:00
|
|
|
"github.com/dokku/dokku/plugins/common"
|
2017-04-24 09:03:30 -06:00
|
|
|
)
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
// RunInSerial is the default value for whether to run a command in parallel or not
|
|
|
|
|
// and defaults to -1 (false)
|
|
|
|
|
const RunInSerial = 0
|
|
|
|
|
|
2026-04-25 05:11:07 -04:00
|
|
|
var (
|
|
|
|
|
// DefaultProperties is a map of all valid proxy properties with corresponding default property values
|
|
|
|
|
DefaultProperties = map[string]string{
|
2026-04-25 17:19:42 -04:00
|
|
|
"disabled": "false",
|
|
|
|
|
"proxy-port": "",
|
|
|
|
|
"proxy-ssl-port": "",
|
|
|
|
|
"type": "",
|
2026-04-25 05:11:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GlobalProperties is a map of all valid global proxy properties
|
|
|
|
|
GlobalProperties = map[string]bool{
|
2026-04-25 17:19:42 -04:00
|
|
|
"proxy-port": true,
|
|
|
|
|
"proxy-ssl-port": true,
|
|
|
|
|
"type": true,
|
2026-04-25 05:11:07 -04:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
// BuildConfig rebuilds the proxy config for the specified app
|
|
|
|
|
func BuildConfig(appName string) error {
|
2024-03-14 02:19:03 -04:00
|
|
|
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "proxy-build-config",
|
|
|
|
|
Args: []string{appName},
|
|
|
|
|
StreamStdio: true,
|
|
|
|
|
})
|
|
|
|
|
return err
|
2021-02-19 23:44:41 -05:00
|
|
|
}
|
|
|
|
|
|
2022-01-28 20:26:49 -05:00
|
|
|
// ClearConfig clears the proxy config for the specified app
|
|
|
|
|
func ClearConfig(appName string) error {
|
2024-03-14 02:19:03 -04:00
|
|
|
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "proxy-clear-config",
|
|
|
|
|
Args: []string{appName},
|
|
|
|
|
StreamStdio: true,
|
|
|
|
|
})
|
|
|
|
|
return err
|
2022-01-28 20:26:49 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
// Disable disables proxy implementations for the specified app
|
|
|
|
|
func Disable(appName string) error {
|
|
|
|
|
if !IsAppProxyEnabled(appName) {
|
|
|
|
|
common.LogInfo1("Proxy is already disable for app")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
common.LogInfo1("Disabling proxy for app")
|
2026-04-25 05:11:07 -04:00
|
|
|
if err := common.PropertyWrite("proxy", appName, "disabled", "true"); err != nil {
|
2021-02-19 23:44:41 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 02:19:03 -04:00
|
|
|
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "proxy-disable",
|
|
|
|
|
Args: []string{appName},
|
|
|
|
|
StreamStdio: true,
|
|
|
|
|
})
|
|
|
|
|
return err
|
2021-02-19 23:44:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enable enables proxy implementations for the specified app
|
|
|
|
|
func Enable(appName string) error {
|
|
|
|
|
if IsAppProxyEnabled(appName) {
|
|
|
|
|
common.LogInfo1("Proxy is already enabled for app")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
common.LogInfo1("Enabling proxy for app")
|
2026-04-25 05:11:07 -04:00
|
|
|
if err := common.PropertyDelete("proxy", appName, "disabled"); err != nil {
|
2021-02-19 23:44:41 -05:00
|
|
|
return err
|
|
|
|
|
}
|
2026-04-25 05:11:07 -04:00
|
|
|
|
2024-03-14 02:19:03 -04:00
|
|
|
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "proxy-enable",
|
|
|
|
|
Args: []string{appName},
|
|
|
|
|
StreamStdio: true,
|
|
|
|
|
})
|
|
|
|
|
return err
|
2021-02-19 23:44:41 -05:00
|
|
|
}
|
|
|
|
|
|
2017-04-24 09:03:30 -06:00
|
|
|
// IsAppProxyEnabled returns true if proxy is enabled; otherwise return false
|
|
|
|
|
func IsAppProxyEnabled(appName string) bool {
|
2026-04-25 05:11:07 -04:00
|
|
|
return common.PropertyGetDefault("proxy", appName, "disabled", "false") != "true"
|
2017-04-24 09:03:30 -06:00
|
|
|
}
|