2020-02-22 06:35:30 -05:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
"github.com/dokku/dokku/plugins/config"
|
|
|
|
|
)
|
|
|
|
|
|
2020-06-29 20:17:23 -04:00
|
|
|
// CommandBuildConfig rebuilds config for a given app
|
2021-02-19 23:44:41 -05:00
|
|
|
func CommandBuildConfig(appName string, allApps bool, parallelCount int) error {
|
|
|
|
|
if allApps {
|
|
|
|
|
return common.RunCommandAgainstAllApps(BuildConfig, "build-config", parallelCount)
|
2020-06-29 20:17:23 -04:00
|
|
|
}
|
|
|
|
|
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
return BuildConfig(appName)
|
|
|
|
|
}
|
2020-02-22 06:35:30 -05:00
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
// CommandDisable disables the proxy for app via command line
|
|
|
|
|
func CommandDisable(appName string, allApps bool, parallelCount int) error {
|
|
|
|
|
if allApps {
|
|
|
|
|
return common.RunCommandAgainstAllApps(Disable, "disable", parallelCount)
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
2020-02-22 06:35:30 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
return Disable(appName)
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandEnable enables the proxy for app via command line
|
2021-02-19 23:44:41 -05:00
|
|
|
func CommandEnable(appName string, allApps bool, parallelCount int) error {
|
|
|
|
|
if allApps {
|
|
|
|
|
return common.RunCommandAgainstAllApps(Enable, "enable", parallelCount)
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
2020-02-22 06:35:30 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 23:44:41 -05:00
|
|
|
return Enable(appName)
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandPorts is a cmd wrapper to list proxy port mappings for an app
|
2020-05-28 23:55:30 -04:00
|
|
|
func CommandPorts(appName string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return listAppProxyPorts(appName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandPortsAdd adds proxy port mappings to an app
|
2020-05-28 23:55:30 -04:00
|
|
|
func CommandPortsAdd(appName string, portMaps []string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:55:30 -04:00
|
|
|
if len(portMaps) == 0 {
|
2020-02-22 06:35:30 -05:00
|
|
|
return errors.New("No port mapping specified")
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:55:30 -04:00
|
|
|
proxyPortMap, err := parseProxyPortMapString(strings.Join(portMaps, " "))
|
2020-02-28 03:11:31 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 06:35:30 -05:00
|
|
|
if err := addProxyPorts(appName, proxyPortMap); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "add"}...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandPortsClear clears all proxy port mappings for an app
|
2020-05-28 23:55:30 -04:00
|
|
|
func CommandPortsClear(appName string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keys := []string{"DOKKU_PROXY_PORT_MAP"}
|
2020-05-28 23:55:30 -04:00
|
|
|
if err := config.UnsetMany(appName, keys, false); err != nil {
|
2020-02-22 06:35:30 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "clear"}...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandPortsRemove removes specific proxy port mappings from an app
|
2020-05-28 23:55:30 -04:00
|
|
|
func CommandPortsRemove(appName string, portMaps []string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:55:30 -04:00
|
|
|
if len(portMaps) == 0 {
|
2020-02-22 06:35:30 -05:00
|
|
|
return errors.New("No port mapping specified")
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:55:30 -04:00
|
|
|
proxyPortMap, err := parseProxyPortMapString(strings.Join(portMaps, " "))
|
2020-02-28 03:11:31 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 06:35:30 -05:00
|
|
|
if err := removeProxyPorts(appName, proxyPortMap); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "remove"}...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandPortsSet sets proxy port mappings for an app
|
2020-05-28 23:55:30 -04:00
|
|
|
func CommandPortsSet(appName string, portMaps []string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:55:30 -04:00
|
|
|
if len(portMaps) == 0 {
|
2020-02-22 06:35:30 -05:00
|
|
|
return errors.New("No port mapping specified")
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:55:30 -04:00
|
|
|
proxyPortMap, err := parseProxyPortMapString(strings.Join(portMaps, " "))
|
2020-02-28 03:11:31 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 06:35:30 -05:00
|
|
|
if err := setProxyPorts(appName, proxyPortMap); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "set"}...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandReport displays a proxy report for one or more apps
|
2021-02-01 22:23:05 -05:00
|
|
|
func CommandReport(appName string, format string, infoFlag string) error {
|
2020-02-22 06:35:30 -05:00
|
|
|
if len(appName) == 0 {
|
|
|
|
|
apps, err := common.DokkuApps()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
for _, appName := range apps {
|
2021-02-01 22:23:05 -05:00
|
|
|
if err := ReportSingleApp(appName, format, infoFlag); err != nil {
|
2020-02-22 06:35:30 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 22:23:05 -05:00
|
|
|
return ReportSingleApp(appName, format, infoFlag)
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandSet sets a proxy for an app
|
2020-05-28 23:55:30 -04:00
|
|
|
func CommandSet(appName string, proxyType string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 23:55:30 -04:00
|
|
|
if len(proxyType) < 2 {
|
2020-02-22 16:56:35 -05:00
|
|
|
return errors.New("Please specify a proxy type")
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entries := map[string]string{
|
|
|
|
|
"DOKKU_APP_PROXY_TYPE": proxyType,
|
|
|
|
|
}
|
|
|
|
|
return config.SetMany(appName, entries, false)
|
|
|
|
|
}
|