2020-02-22 06:35:30 -05:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
2024-04-04 23:01:47 -04:00
|
|
|
"strings"
|
2020-02-22 06:35:30 -05:00
|
|
|
|
|
|
|
|
"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
|
|
|
|
2022-01-28 20:26:49 -05:00
|
|
|
// CommandClearConfig clears config for a given app
|
|
|
|
|
func CommandClearConfig(appName string, allApps bool) error {
|
|
|
|
|
if allApps {
|
|
|
|
|
return ClearConfig("--all")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ClearConfig(appName)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 {
|
2025-02-02 01:37:14 -05:00
|
|
|
if errors.Is(err, common.NoAppsExist) {
|
|
|
|
|
common.LogWarn(err.Error())
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2020-02-22 06:35:30 -05:00
|
|
|
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 {
|
2024-01-19 04:13:55 -05:00
|
|
|
if appName != "--global" {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-04-04 23:01:47 -04:00
|
|
|
if strings.Contains(proxyType, ":") {
|
|
|
|
|
common.LogWarn("Detected potential port mapping instead of proxy type")
|
|
|
|
|
return errors.New("Consider using ports:set command or specifying a valid proxy")
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 04:13:55 -05:00
|
|
|
key := "DOKKU_APP_PROXY_TYPE"
|
|
|
|
|
if appName == "--global" {
|
|
|
|
|
key = "DOKKU_PROXY_TYPE"
|
|
|
|
|
}
|
2020-02-22 06:35:30 -05:00
|
|
|
entries := map[string]string{
|
2024-01-19 04:13:55 -05:00
|
|
|
key: proxyType,
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|
2025-11-08 01:02:19 -05:00
|
|
|
return config.SetMany(appName, entries, false, false)
|
2020-02-22 06:35:30 -05:00
|
|
|
}
|