From 65d7fd9cce90fca725dcb162deef73a690f57d27 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 25 Dec 2020 00:08:52 -0500 Subject: [PATCH] refactor: drop extra internal calls to VerifyAppName These are duplicative of the checks that happen at the subcommand level. --- plugins/apps/functions.go | 4 ---- plugins/common/common.go | 21 --------------------- plugins/common/docker.go | 4 ---- plugins/network/network.go | 4 ---- plugins/network/triggers.go | 16 ---------------- plugins/proxy/proxy.go | 5 ----- plugins/repo/repo.go | 5 ----- 7 files changed, 59 deletions(-) diff --git a/plugins/apps/functions.go b/plugins/apps/functions.go index 9d6b0491a..88d42e03a 100644 --- a/plugins/apps/functions.go +++ b/plugins/apps/functions.go @@ -44,10 +44,6 @@ func createApp(appName string) error { // destroys an app func destroyApp(appName string) error { - if err := common.VerifyAppName(appName); err != nil { - return err - } - if os.Getenv("DOKKU_APPS_FORCE_DELETE") != "1" { if err := common.AskForDestructiveConfirmation(appName, "app"); err != nil { return err diff --git a/plugins/common/common.go b/plugins/common/common.go index 4fc019cea..05fbc8434 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -90,10 +90,6 @@ func GetGlobalScheduler() string { // GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented func GetDeployingAppImageName(appName, imageTag, imageRepo string) (string, error) { - if appName == "" { - LogFail("(GetDeployingAppImageName) APP must not be empty") - } - b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...) if err != nil { return "", err @@ -140,10 +136,6 @@ func GetAppImageRepo(appName string) string { // GetAppContainerIDs returns a list of docker container ids for given app and optional container_type func GetAppContainerIDs(appName string, containerType string) ([]string, error) { var containerIDs []string - if err := VerifyAppName(appName); err != nil { - return containerIDs, err - } - appRoot := AppRoot(appName) containerFilePath := fmt.Sprintf("%v/CONTAINER", appRoot) _, err := os.Stat(containerFilePath) @@ -170,10 +162,6 @@ func GetAppContainerIDs(appName string, containerType string) ([]string, error) // GetAppRunningContainerIDs return a list of running docker container ids for given app and optional container_type func GetAppRunningContainerIDs(appName string, containerType string) ([]string, error) { var runningContainerIDs []string - if err := VerifyAppName(appName); err != nil { - return runningContainerIDs, err - } - if !IsDeployed(appName) { LogFail(fmt.Sprintf("App %v has not been deployed", appName)) } @@ -193,10 +181,6 @@ func GetAppRunningContainerIDs(appName string, containerType string) ([]string, // GetRunningImageTag retrieves current image tag for a given app and returns empty string if no deployed containers are found func GetRunningImageTag(appName string) (string, error) { - if err := VerifyAppName(appName); err != nil { - return "", err - } - containerIDs, err := GetAppContainerIDs(appName, "") if err != nil { return "", err @@ -241,11 +225,6 @@ func DokkuApps() (apps []string, err error) { // GetAppImageName returns image identifier for a given app, tag tuple. validate if tag is presented func GetAppImageName(appName, imageTag, imageRepo string) (imageName string) { - err := VerifyAppName(appName) - if err != nil { - LogFail(err.Error()) - } - if imageRepo == "" { imageRepo = GetAppImageRepo(appName) } diff --git a/plugins/common/docker.go b/plugins/common/docker.go index 73abf75eb..ec80b6acd 100644 --- a/plugins/common/docker.go +++ b/plugins/common/docker.go @@ -22,10 +22,6 @@ func ContainerIsRunning(containerID string) bool { // CopyFromImage copies a file from named image to destination func CopyFromImage(appName string, image string, source string, destination string) error { - if err := VerifyAppName(appName); err != nil { - return err - } - if !VerifyImage(image) { return fmt.Errorf("Invalid docker image for copying content") } diff --git a/plugins/network/network.go b/plugins/network/network.go index 380731ae0..9f141d53b 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -26,10 +26,6 @@ var ( // BuildConfig builds network config files func BuildConfig(appName string) error { - if err := common.VerifyAppName(appName); err != nil { - return err - } - if !common.IsDeployed(appName) { return nil } diff --git a/plugins/network/triggers.go b/plugins/network/triggers.go index 631767d17..d0c28c02f 100644 --- a/plugins/network/triggers.go +++ b/plugins/network/triggers.go @@ -104,14 +104,6 @@ func TriggerNetworkGetProperty(appName string, property string) { // TriggerNetworkWriteIpaddr writes the ip to disk func TriggerNetworkWriteIpaddr(appName string, processType string, containerIndex string, ip string) { - if appName == "" { - common.LogFail("Please specify an app to run the command on") - } - err := common.VerifyAppName(appName) - if err != nil { - common.LogFail(err.Error()) - } - appRoot := common.AppRoot(appName) filename := fmt.Sprintf("%v/IP.%v.%v", appRoot, processType, containerIndex) f, err := os.Create(filename) @@ -129,14 +121,6 @@ func TriggerNetworkWriteIpaddr(appName string, processType string, containerInde // TriggerNetworkWritePort writes the port to disk func TriggerNetworkWritePort(appName string, processType string, containerIndex string, port string) { - if appName == "" { - common.LogFail("Please specify an app to run the command on") - } - err := common.VerifyAppName(appName) - if err != nil { - common.LogFail(err.Error()) - } - appRoot := common.AppRoot(appName) filename := fmt.Sprintf("%v/PORT.%v.%v", appRoot, processType, containerIndex) f, err := os.Create(filename) diff --git a/plugins/proxy/proxy.go b/plugins/proxy/proxy.go index 0a1860d2b..3da647658 100644 --- a/plugins/proxy/proxy.go +++ b/plugins/proxy/proxy.go @@ -35,11 +35,6 @@ func inRange(value int, min int, max int) bool { // IsAppProxyEnabled returns true if proxy is enabled; otherwise return false func IsAppProxyEnabled(appName string) bool { - err := common.VerifyAppName(appName) - if err != nil { - common.LogFail(err.Error()) - } - proxyEnabled := true disableProxy := config.GetWithDefault(appName, "DOKKU_DISABLE_PROXY", "") if disableProxy != "" { diff --git a/plugins/repo/repo.go b/plugins/repo/repo.go index 938602077..04e7cdea1 100644 --- a/plugins/repo/repo.go +++ b/plugins/repo/repo.go @@ -11,11 +11,6 @@ import ( // PurgeCache deletes the contents of the build cache stored in the repository func PurgeCache(appName string) error { - err := common.VerifyAppName(appName) - if err != nil { - return err - } - cacheDir := strings.Join([]string{common.AppRoot(appName), "cache"}, "/") cacheHostDir := strings.Join([]string{common.AppHostRoot(appName), "cache"}, "/") dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS")