refactor: consolidate app name verification into golang binary
This change ensures we only have to change this logic once in order to get them to apply to both languages in the codebase.
This commit is contained in:
@@ -250,43 +250,11 @@ is_valid_app_name_old() {
|
||||
verify_app_name() {
|
||||
declare desc="verify app name format and app existence"
|
||||
declare APP="$1"
|
||||
export SSH_USER=${SSH_USER:=$USER}
|
||||
export SSH_NAME=${NAME:="default"}
|
||||
|
||||
local VALID_NEW=false
|
||||
local VALID_OLD=false
|
||||
if fn-is-valid-app-name "$APP" 2>/dev/null; then
|
||||
VALID_NEW=true
|
||||
fi
|
||||
|
||||
if fn-is-valid-app-name-old "$APP" 2>/dev/null; then
|
||||
VALID_OLD=true
|
||||
fi
|
||||
|
||||
if [[ "$VALID_NEW" == "false" ]] && [[ "$VALID_OLD" == "false" ]]; then
|
||||
dokku_log_fail "App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores"
|
||||
fi
|
||||
|
||||
[[ ! -d "$DOKKU_ROOT/$APP" ]] && DOKKU_FAIL_EXIT_CODE=20 dokku_log_fail "App $APP does not exist"
|
||||
|
||||
local user_auth_count=$(find "$PLUGIN_PATH"/enabled/*/user-auth-app 2>/dev/null | wc -l)
|
||||
|
||||
# no plugin trigger exists
|
||||
if [[ $user_auth_count == 0 ]]; then
|
||||
if "$PLUGIN_CORE_AVAILABLE_PATH/common/common" --quiet verify-app-name "$APP"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# this plugin trigger exists in the core `20_events` plugin
|
||||
if [[ "$user_auth_count" == 1 ]] && [[ -f "$PLUGIN_PATH"/enabled/20_events/user-auth-app ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if output="$(plugn trigger user-auth-app "$SSH_USER" "$SSH_NAME" "$@" "$APP")"; then
|
||||
if [[ -n "$output" ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
DOKKU_FAIL_EXIT_CODE=20 dokku_log_fail "App $APP does not exist"
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,19 @@ func LogFailWithError(err error) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// LogFailWithErrorQuiet is the failure log formatter (with quiet option)
|
||||
// prints text to stderr and exits with the specified exit code
|
||||
// The error message is not printed if DOKKU_QUIET_OUTPUT has any value
|
||||
func LogFailWithErrorQuiet(err error) {
|
||||
if os.Getenv("DOKKU_QUIET_OUTPUT") == "" {
|
||||
fmt.Fprintln(os.Stderr, fmt.Sprintf(" ! %s", err.Error()))
|
||||
}
|
||||
if errExit, ok := err.(ErrWithExitCode); ok {
|
||||
os.Exit(errExit.ExitCode())
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// LogFailQuiet is the failure log formatter (with quiet option)
|
||||
// prints text to stderr and exits with status 1
|
||||
func LogFailQuiet(text string) {
|
||||
|
||||
@@ -38,11 +38,14 @@ func main() {
|
||||
appName = "--global"
|
||||
}
|
||||
fmt.Print(common.GetAppScheduler(appName))
|
||||
case "verify-app-name":
|
||||
appName := flag.Arg(1)
|
||||
err = common.VerifyAppName(appName)
|
||||
default:
|
||||
err = fmt.Errorf("Invalid common command call: %v", cmd)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
common.LogFailQuiet(err.Error())
|
||||
common.LogFailWithErrorQuiet(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user