From 7136da1aa57ddc30ba28f7e94b8c103fe3d6c797 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 28 Jan 2022 20:26:49 -0500 Subject: [PATCH] feat: add a command to clear all proxy configs Closes #5002 --- plugins/proxy/proxy.go | 5 ++ plugins/proxy/src/subcommands/subcommands.go | 6 ++ plugins/proxy/subcommands.go | 13 ++++ tests/unit/proxy.bats | 62 ++++++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/plugins/proxy/proxy.go b/plugins/proxy/proxy.go index 817602cea..ec87bf48c 100644 --- a/plugins/proxy/proxy.go +++ b/plugins/proxy/proxy.go @@ -32,6 +32,11 @@ func BuildConfig(appName string) error { return common.PlugnTrigger("proxy-build-config", []string{appName}...) } +// ClearConfig clears the proxy config for the specified app +func ClearConfig(appName string) error { + return common.PlugnTrigger("proxy-clear-config", []string{appName}...) +} + // Disable disables proxy implementations for the specified app func Disable(appName string) error { if !IsAppProxyEnabled(appName) { diff --git a/plugins/proxy/src/subcommands/subcommands.go b/plugins/proxy/src/subcommands/subcommands.go index d0a8b3960..c25db395c 100644 --- a/plugins/proxy/src/subcommands/subcommands.go +++ b/plugins/proxy/src/subcommands/subcommands.go @@ -25,6 +25,12 @@ func main() { args.Parse(os.Args[2:]) appName := args.Arg(0) err = proxy.CommandBuildConfig(appName, *allApps, *parallelCount) + case "clear-config": + args := flag.NewFlagSet("proxy:clear-config", flag.ExitOnError) + allApps := args.Bool("all", false, "--all: build-config for all apps") + args.Parse(os.Args[2:]) + appName := args.Arg(0) + err = proxy.CommandClearConfig(appName, *allApps) case "disable": args := flag.NewFlagSet("proxy:disable", flag.ExitOnError) allApps := args.Bool("all", false, "--all: disable proxy for all apps") diff --git a/plugins/proxy/subcommands.go b/plugins/proxy/subcommands.go index 44a035f26..1dcb66558 100644 --- a/plugins/proxy/subcommands.go +++ b/plugins/proxy/subcommands.go @@ -21,6 +21,19 @@ func CommandBuildConfig(appName string, allApps bool, parallelCount int) error { return BuildConfig(appName) } +// 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) +} + // CommandDisable disables the proxy for app via command line func CommandDisable(appName string, allApps bool, parallelCount int) error { if allApps { diff --git a/tests/unit/proxy.bats b/tests/unit/proxy.bats index 6b2188961..8aef61c86 100644 --- a/tests/unit/proxy.bats +++ b/tests/unit/proxy.bats @@ -28,6 +28,68 @@ teardown() { assert_output "$help_output" } +@test "(proxy) proxy:build-config/clear-config" { + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "test -f $DOKKU_ROOT/$TEST_APP/nginx.conf" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "rm -f $DOKKU_ROOT/$TEST_APP/nginx.conf" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "test -f $DOKKU_ROOT/$TEST_APP/nginx.conf" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku proxy:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "test -f $DOKKU_ROOT/$TEST_APP/nginx.conf" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku proxy:clear-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "test -f $DOKKU_ROOT/$TEST_APP/nginx.conf" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku proxy:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "test -f $DOKKU_ROOT/$TEST_APP/nginx.conf" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku proxy:clear-config --all" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "test -f $DOKKU_ROOT/$TEST_APP/nginx.conf" + echo "output: $output" + echo "status: $status" + assert_failure +} + @test "(proxy) proxy:enable/disable" { deploy_app assert_nonssl_domain "${TEST_APP}.dokku.me"