feat: add app name verification to all golang plugins

Moving verification of input to the earliest place is the best way to decrease the need to validate this further downstream.

Additionally, some of the existing checks were.... lacking :)
This commit is contained in:
Jose Diaz-Gonzalez committed 2020-12-27 15:14:11 -05:00
1 parent 382dc01b33
commit ffa303092f
8 files changed
+41 -94

No files matched your search

-16
View File
@@ -79,10 +79,6 @@ func CommandDestroy(appName string, force bool) error {
// CommandExists checks if an app exists // CommandExists checks if an app exists
func CommandExists(appName string) error { func CommandExists(appName string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
return appExists(appName) return appExists(appName)
} }
@@ -104,10 +100,6 @@ func CommandList() error {
// CommandLock locks an app for deployment // CommandLock locks an app for deployment
func CommandLock(appName string) error { func CommandLock(appName string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -123,10 +115,6 @@ func CommandLock(appName string) error {
// CommandLocked checks if an app is locked for deployment // CommandLocked checks if an app is locked for deployment
func CommandLocked(appName string) error { func CommandLocked(appName string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -206,10 +194,6 @@ func CommandReport(appName string, infoFlag string) error {
// CommandUnlock unlocks an app for deployment // CommandUnlock unlocks an app for deployment
func CommandUnlock(appName string) error { func CommandUnlock(appName string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
+10 -10
View File
@@ -9,8 +9,8 @@ import (
// CommandAdd implements buildpacks:add // CommandAdd implements buildpacks:add
func CommandAdd(appName string, buildpack string, index int) error { func CommandAdd(appName string, buildpack string, index int) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
buildpack, err := validBuildpackURL(buildpack) buildpack, err := validBuildpackURL(buildpack)
@@ -23,8 +23,8 @@ func CommandAdd(appName string, buildpack string, index int) error {
// CommandClear implements buildpacks:clear // CommandClear implements buildpacks:clear
func CommandClear(appName string) error { func CommandClear(appName string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
return common.PropertyDelete("buildpacks", appName, "buildpacks") return common.PropertyDelete("buildpacks", appName, "buildpacks")
@@ -32,8 +32,8 @@ func CommandClear(appName string) error {
// CommandList implements buildpacks:list // CommandList implements buildpacks:list
func CommandList(appName string) (err error) { func CommandList(appName string) (err error) {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks") buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks")
@@ -50,8 +50,8 @@ func CommandList(appName string) (err error) {
// CommandRemove implements buildpacks:remove // CommandRemove implements buildpacks:remove
func CommandRemove(appName string, buildpack string, index int) (err error) { func CommandRemove(appName string, buildpack string, index int) (err error) {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
if index != 0 && buildpack != "" { if index != 0 && buildpack != "" {
@@ -123,8 +123,8 @@ func CommandReport(appName string, infoFlag string) error {
// CommandSet implements buildpacks:set // CommandSet implements buildpacks:set
func CommandSet(appName string, buildpack string, index int) error { func CommandSet(appName string, buildpack string, index int) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
buildpack, err := validBuildpackURL(buildpack) buildpack, err := validBuildpackURL(buildpack)
-5
View File
@@ -1,7 +1,6 @@
package logs package logs
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
@@ -10,10 +9,6 @@ import (
// CommandDefault displays recent log output // CommandDefault displays recent log output
func CommandDefault(appName string, num int64, process string, tail, quiet bool) error { func CommandDefault(appName string, num int64, process string, tail, quiet bool) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
+4
View File
@@ -142,6 +142,10 @@ func CommandReport(appName string, infoFlag string) error {
// CommandSet set or clear a network property for an app // CommandSet set or clear a network property for an app
func CommandSet(appName string, property string, value string) error { func CommandSet(appName string, property string, value string) error {
if err := common.VerifyAppName(appName); err != nil {
return err
}
if property == "bind-all-interfaces" && value == "" { if property == "bind-all-interfaces" && value == "" {
value = "false" value = "false"
} }
+16 -20
View File
@@ -10,10 +10,6 @@ import (
// CommandBuildConfig rebuilds config for a given app // CommandBuildConfig rebuilds config for a given app
func CommandBuildConfig(appName string) error { func CommandBuildConfig(appName string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -23,8 +19,8 @@ func CommandBuildConfig(appName string) error {
// CommandDisable disables the proxy for app via command line // CommandDisable disables the proxy for app via command line
func CommandDisable(appName string, skipRestart bool) error { func CommandDisable(appName string, skipRestart bool) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
if !IsAppProxyEnabled(appName) { if !IsAppProxyEnabled(appName) {
@@ -46,8 +42,8 @@ func CommandDisable(appName string, skipRestart bool) error {
// CommandEnable enables the proxy for app via command line // CommandEnable enables the proxy for app via command line
func CommandEnable(appName string) error { func CommandEnable(appName string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
if IsAppProxyEnabled(appName) { if IsAppProxyEnabled(appName) {
@@ -66,8 +62,8 @@ func CommandEnable(appName string) error {
// CommandPorts is a cmd wrapper to list proxy port mappings for an app // CommandPorts is a cmd wrapper to list proxy port mappings for an app
func CommandPorts(appName string) error { func CommandPorts(appName string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
return listAppProxyPorts(appName) return listAppProxyPorts(appName)
@@ -75,8 +71,8 @@ func CommandPorts(appName string) error {
// CommandPortsAdd adds proxy port mappings to an app // CommandPortsAdd adds proxy port mappings to an app
func CommandPortsAdd(appName string, portMaps []string) error { func CommandPortsAdd(appName string, portMaps []string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
if len(portMaps) == 0 { if len(portMaps) == 0 {
@@ -97,8 +93,8 @@ func CommandPortsAdd(appName string, portMaps []string) error {
// CommandPortsClear clears all proxy port mappings for an app // CommandPortsClear clears all proxy port mappings for an app
func CommandPortsClear(appName string) error { func CommandPortsClear(appName string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
keys := []string{"DOKKU_PROXY_PORT_MAP"} keys := []string{"DOKKU_PROXY_PORT_MAP"}
@@ -111,8 +107,8 @@ func CommandPortsClear(appName string) error {
// CommandPortsRemove removes specific proxy port mappings from an app // CommandPortsRemove removes specific proxy port mappings from an app
func CommandPortsRemove(appName string, portMaps []string) error { func CommandPortsRemove(appName string, portMaps []string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
if len(portMaps) == 0 { if len(portMaps) == 0 {
@@ -133,8 +129,8 @@ func CommandPortsRemove(appName string, portMaps []string) error {
// CommandPortsSet sets proxy port mappings for an app // CommandPortsSet sets proxy port mappings for an app
func CommandPortsSet(appName string, portMaps []string) error { func CommandPortsSet(appName string, portMaps []string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
if len(portMaps) == 0 { if len(portMaps) == 0 {
@@ -173,8 +169,8 @@ func CommandReport(appName string, infoFlag string) error {
// CommandSet sets a proxy for an app // CommandSet sets a proxy for an app
func CommandSet(appName string, proxyType string) error { func CommandSet(appName string, proxyType string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
if len(proxyType) < 2 { if len(proxyType) < 2 {
-24
View File
@@ -13,10 +13,6 @@ import (
// CommandInspect displays a sanitized version of docker inspect for an app // CommandInspect displays a sanitized version of docker inspect for an app
func CommandInspect(appName string) error { func CommandInspect(appName string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -31,10 +27,6 @@ func CommandRebuild(appName string, allApps bool, parallelCount int) error {
return common.RunCommandAgainstAllApps(Rebuild, "rebuild", parallelCount) return common.RunCommandAgainstAllApps(Rebuild, "rebuild", parallelCount)
} }
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -66,10 +58,6 @@ func CommandRestart(appName string, allApps bool, parallelCount int) error {
return common.RunCommandAgainstAllApps(Restart, "restart", parallelCount) return common.RunCommandAgainstAllApps(Restart, "restart", parallelCount)
} }
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -128,10 +116,6 @@ func CommandRetire() error {
// CommandScale gets or sets how many instances of a given process to run // CommandScale gets or sets how many instances of a given process to run
func CommandScale(appName string, skipDeploy bool, processTuples []string) error { func CommandScale(appName string, skipDeploy bool, processTuples []string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -189,10 +173,6 @@ func CommandStart(appName string, allApps bool, parallelCount int) error {
return common.RunCommandAgainstAllApps(Start, "start", parallelCount) return common.RunCommandAgainstAllApps(Start, "start", parallelCount)
} }
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
@@ -206,10 +186,6 @@ func CommandStop(appName string, allApps bool, parallelCount int) error {
return common.RunCommandAgainstAllApps(Stop, "stop", parallelCount) return common.RunCommandAgainstAllApps(Stop, "stop", parallelCount)
} }
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return err return err
} }
+3 -9
View File
@@ -1,18 +1,12 @@
package repo package repo
import ( import (
"errors"
"github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/common"
) )
// CommandGc runs 'git gc --aggressive' against the application's repo // CommandGc runs 'git gc --aggressive' against the application's repo
func CommandGc(appName string) error { func CommandGc(appName string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on")
}
err := common.VerifyAppName(appName)
if err != nil {
return err return err
} }
@@ -28,8 +22,8 @@ func CommandGc(appName string) error {
// CommandPurgeCache deletes the contents of the build cache stored in the repository // CommandPurgeCache deletes the contents of the build cache stored in the repository
func CommandPurgeCache(appName string) error { func CommandPurgeCache(appName string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
common.LogFail("Please specify an app to run the command on") return err
} }
return PurgeCache(appName) return PurgeCache(appName)
+8 -10
View File
@@ -1,15 +1,13 @@
package resource package resource
import ( import (
"errors"
"github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/common"
) )
// CommandLimit implements resource:limit // CommandLimit implements resource:limit
func CommandLimit(appName string, processType string, r Resource) error { func CommandLimit(appName string, processType string, r Resource) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
return setResourceType(appName, processType, r, "limit") return setResourceType(appName, processType, r, "limit")
@@ -17,8 +15,8 @@ func CommandLimit(appName string, processType string, r Resource) error {
// CommandLimitClear implements resource:limit-clear // CommandLimitClear implements resource:limit-clear
func CommandLimitClear(appName string, processType string) error { func CommandLimitClear(appName string, processType string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
clearByResourceType(appName, processType, "limit") clearByResourceType(appName, processType, "limit")
@@ -45,8 +43,8 @@ func CommandReport(appName string, infoFlag string) error {
// CommandReserve implements resource:reserve // CommandReserve implements resource:reserve
func CommandReserve(appName string, processType string, r Resource) error { func CommandReserve(appName string, processType string, r Resource) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
return setResourceType(appName, processType, r, "reserve") return setResourceType(appName, processType, r, "reserve")
@@ -54,8 +52,8 @@ func CommandReserve(appName string, processType string, r Resource) error {
// CommandReserveClear implements resource:reserve-clear // CommandReserveClear implements resource:reserve-clear
func CommandReserveClear(appName string, processType string) error { func CommandReserveClear(appName string, processType string) error {
if appName == "" { if err := common.VerifyAppName(appName); err != nil {
return errors.New("Please specify an app to run the command on") return err
} }
clearByResourceType(appName, processType, "reserve") clearByResourceType(appName, processType, "reserve")