From 12531dfb3e719cbf0719a529d7e9dec429b77680 Mon Sep 17 00:00:00 2001 From: nisseknudsen Date: Sun, 10 Jan 2021 19:26:16 +0100 Subject: [PATCH 1/3] Regex handles absolute mount path _and_ named volumes --- plugins/storage/functions | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/storage/functions b/plugins/storage/functions index 6fc97da21..280047cf1 100755 --- a/plugins/storage/functions +++ b/plugins/storage/functions @@ -6,7 +6,13 @@ source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" verify_paths() { declare desc="verifies storage paths" - echo "$1" | grep -qe '^/.*\:/' || dokku_log_fail "Storage path must be two valid paths divided by colon." + local -r passed_path=$1 + if [[ "$passed_path" = \* ]]; then + echo "$passed_path" | grep -qe '^/.*\:/' || dokku_log_fail "Storage path must be two valid paths divided by colon." + else + echo "$passed_path" | grep -qe '^[a-zA-Z0-9]\{1\}[a-zA-Z0-9_.-]\+\:\/' || dokku_log_fail "Volume name must be two characters or more. Volume name must not contain invalid characters. Storage path must be two valid paths divided by colon." + fi + } check_if_path_exists() { From a1f4a9a386e2d62765794a07aef4966c7ed67ec4 Mon Sep 17 00:00:00 2001 From: nisseknudsen Date: Sun, 10 Jan 2021 19:32:05 +0100 Subject: [PATCH 2/3] Checks if passed path starts with / and shoudl be an absolute mount --- plugins/storage/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/storage/functions b/plugins/storage/functions index 280047cf1..d8b8e4dae 100755 --- a/plugins/storage/functions +++ b/plugins/storage/functions @@ -7,7 +7,7 @@ source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" verify_paths() { declare desc="verifies storage paths" local -r passed_path=$1 - if [[ "$passed_path" = \* ]]; then + if [[ "$passed_path" = /* ]]; then echo "$passed_path" | grep -qe '^/.*\:/' || dokku_log_fail "Storage path must be two valid paths divided by colon." else echo "$passed_path" | grep -qe '^[a-zA-Z0-9]\{1\}[a-zA-Z0-9_.-]\+\:\/' || dokku_log_fail "Volume name must be two characters or more. Volume name must not contain invalid characters. Storage path must be two valid paths divided by colon." From a3ab4d1b68632bf65baef9eb1300151ad5138e18 Mon Sep 17 00:00:00 2001 From: nisseknudsen Date: Fri, 15 Jan 2021 22:40:52 +0100 Subject: [PATCH 3/3] Mounting new named volume after unmounting host directory --- tests/unit/storage.bats | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/storage.bats b/tests/unit/storage.bats index 1c0dacb35..8a20f0be8 100644 --- a/tests/unit/storage.bats +++ b/tests/unit/storage.bats @@ -53,4 +53,8 @@ teardown() { echo "status: $status" assert_output " ! Mount path does not exist." assert_failure + run /bin/bash -c "dokku storage:mount $TEST_APP mount_volume:/mount" + echo "output: $output" + echo "status: $status" + assert_success }