Merge pull request #2881 from dokku/2807-bad-app-name
Verify app name on git push
This commit is contained in:
commit
15494d85a9
3 files changed
+25
-8
No files matched your search
@@ -137,14 +137,21 @@ dokku_container_log_verbose_quiet() {
|
|||||||
IFS=$OIFS
|
IFS=$OIFS
|
||||||
}
|
}
|
||||||
|
|
||||||
verify_app_name() {
|
is_valid_app_name() {
|
||||||
declare desc="verify app name format and app existence"
|
declare desc="verify app name format"
|
||||||
local APP="$1"
|
local APP="$1"
|
||||||
[[ ! -n "$APP" ]] && dokku_log_fail "(verify_app_name) APP must not be null"
|
[[ ! -n "$APP" ]] && dokku_log_fail "APP must not be null"
|
||||||
if [[ ! "$APP" =~ ^[a-z].* && ! "$APP" =~ ^[0-9].* ]]; then
|
if [[ ! "$APP" =~ ^[a-z].* && ! "$APP" =~ ^[0-9].* ]]; then
|
||||||
[[ -d "$DOKKU_ROOT/$APP" ]] && rm -rf "${DOKKU_ROOT:?}/$APP"
|
[[ -d "$DOKKU_ROOT/$APP" ]] && rm -rf "${DOKKU_ROOT:?}/$APP"
|
||||||
dokku_log_fail "App name must begin with lowercase alphanumeric character"
|
dokku_log_fail "App name must begin with lowercase alphanumeric character"
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_app_name() {
|
||||||
|
declare desc="verify app name format and app existence"
|
||||||
|
local APP="$1"
|
||||||
|
is_valid_app_name "$APP"
|
||||||
[[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist"
|
[[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -163,14 +170,14 @@ verify_image() {
|
|||||||
get_app_image_repo() {
|
get_app_image_repo() {
|
||||||
declare desc="central definition of image repo pattern"
|
declare desc="central definition of image repo pattern"
|
||||||
local APP="$1"; local IMAGE_REPO="dokku/$APP"
|
local APP="$1"; local IMAGE_REPO="dokku/$APP"
|
||||||
[[ -z "$APP" ]] && dokku_log_fail "(get_app_image_repo) APP must not be null"
|
is_valid_app_name "$APP"
|
||||||
echo "$IMAGE_REPO"
|
echo "$IMAGE_REPO"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_deploying_app_image_name() {
|
get_deploying_app_image_name() {
|
||||||
declare desc="return deploying image identifier for a given app, tag tuple. validate if tag is presented"
|
declare desc="return deploying image identifier for a given app, tag tuple. validate if tag is presented"
|
||||||
local APP="$1"; local IMAGE_TAG="$2"; IMAGE_REPO="$3"
|
local APP="$1"; local IMAGE_TAG="$2"; IMAGE_REPO="$3"
|
||||||
[[ -z "$APP" ]] && dokku_log_fail "(get_deploying_app_image_name) APP must not be null"
|
is_valid_app_name "$APP"
|
||||||
|
|
||||||
local IMAGE_REMOTE_REPOSITORY=$(plugn trigger deployed-app-repository "$APP")
|
local IMAGE_REMOTE_REPOSITORY=$(plugn trigger deployed-app-repository "$APP")
|
||||||
local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP")
|
local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP")
|
||||||
@@ -189,7 +196,7 @@ get_deploying_app_image_name() {
|
|||||||
get_app_image_name() {
|
get_app_image_name() {
|
||||||
declare desc="return image identifier for a given app, tag tuple. validate if tag is presented"
|
declare desc="return image identifier for a given app, tag tuple. validate if tag is presented"
|
||||||
local APP="$1"; local IMAGE_TAG="$2"; IMAGE_REPO="$3"
|
local APP="$1"; local IMAGE_TAG="$2"; IMAGE_REPO="$3"
|
||||||
[[ -z "$APP" ]] && dokku_log_fail "(get_app_image_name) APP must not be null"
|
is_valid_app_name "$APP"
|
||||||
|
|
||||||
if [[ -z "$IMAGE_REPO" ]]; then
|
if [[ -z "$IMAGE_REPO" ]]; then
|
||||||
IMAGE_REPO=$(get_app_image_repo "$APP")
|
IMAGE_REPO=$(get_app_image_repo "$APP")
|
||||||
@@ -207,7 +214,6 @@ get_app_image_name() {
|
|||||||
get_running_image_tag() {
|
get_running_image_tag() {
|
||||||
declare desc="retrieve current image tag for a given app. returns empty string if no deployed containers are found"
|
declare desc="retrieve current image tag for a given app. returns empty string if no deployed containers are found"
|
||||||
local APP="$1"
|
local APP="$1"
|
||||||
[[ ! -n "$APP" ]] && dokku_log_fail "(get_running_image_tag) APP must not be null"
|
|
||||||
verify_app_name "$APP"
|
verify_app_name "$APP"
|
||||||
|
|
||||||
local CIDS=( $(get_app_container_ids "$APP") )
|
local CIDS=( $(get_app_container_ids "$APP") )
|
||||||
|
|||||||
@@ -105,8 +105,10 @@ git_hook_cmd() {
|
|||||||
declare desc="kick off receive-app trigger from git prereceive hook"
|
declare desc="kick off receive-app trigger from git prereceive hook"
|
||||||
local cmd="git-hook"
|
local cmd="git-hook"
|
||||||
local APP="$2"
|
local APP="$2"
|
||||||
local DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")"
|
local DOKKU_DEPLOY_BRANCH
|
||||||
|
is_valid_app_name "$APP"
|
||||||
|
|
||||||
|
DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")"
|
||||||
if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" > /dev/null 2>&1; then
|
if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" > /dev/null 2>&1; then
|
||||||
echo $'\e[1G\e[K'"-----> WARNING: Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via DOKKU_DEPLOY_BRANCH."
|
echo $'\e[1G\e[K'"-----> WARNING: Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via DOKKU_DEPLOY_BRANCH."
|
||||||
echo $'\e[1G\e[K'"-----> For more details, please see the man page for 'git-check-ref-format.'"
|
echo $'\e[1G\e[K'"-----> For more details, please see the man page for 'git-check-ref-format.'"
|
||||||
@@ -150,6 +152,7 @@ git_upload_pack_cmd() {
|
|||||||
declare desc="executes git-upload-pack"
|
declare desc="executes git-upload-pack"
|
||||||
local cmd="git-upload-pack"
|
local cmd="git-upload-pack"
|
||||||
local APP="$(echo "$2" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
|
local APP="$(echo "$2" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
|
||||||
|
is_valid_app_name "$APP"
|
||||||
plugn trigger git-pre-pull "$APP"
|
plugn trigger git-pre-pull "$APP"
|
||||||
cat | git-upload-pack "$DOKKU_ROOT/$APP"
|
cat | git-upload-pack "$DOKKU_ROOT/$APP"
|
||||||
plugn trigger git-post-pull "$APP"
|
plugn trigger git-post-pull "$APP"
|
||||||
@@ -160,6 +163,7 @@ git_glob_cmd() {
|
|||||||
local cmd="git-*"
|
local cmd="git-*"
|
||||||
local APP="$(echo "$2" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')"
|
local APP="$(echo "$2" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')"
|
||||||
local APP_PATH=$DOKKU_ROOT/$APP
|
local APP_PATH=$DOKKU_ROOT/$APP
|
||||||
|
is_valid_app_name "$APP"
|
||||||
|
|
||||||
if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then
|
if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then
|
||||||
git init --bare "$APP_PATH" > /dev/null
|
git init --bare "$APP_PATH" > /dev/null
|
||||||
|
|||||||
@@ -97,3 +97,10 @@ build_nginx_config() {
|
|||||||
echo "status: "$status
|
echo "status: "$status
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "(core) git-remote (bad name)" {
|
||||||
|
run deploy_app nodejs-express ssh://dokku@127.0.0.1:22333/home/dokku/$TEST_APP
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
Reference in new issue
Block a user