Skip to content

Commit 7cc77a6

Browse files
committed
Refactor environment variable validation in adopt_event_source_mappings.sh
- Introduced a new function, require_value, to streamline the validation of required environment variables. - Replaced individual checks for ENVIRONMENT, SUB_ENVIRONMENT, and RESOURCE_SCOPE with calls to the new function for improved code clarity and maintainability.
1 parent 0174644 commit 7cc77a6

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

utilities/scripts/adopt_event_source_mappings.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ environment="${ENVIRONMENT:-${environment:-}}"
66
sub_environment="${SUB_ENVIRONMENT:-${sub_environment:-}}"
77
resource_scope="${RESOURCE_SCOPE:-${resource_scope:-}}"
88

9-
if [[ -z "${environment}" ]]; then
10-
echo "ENVIRONMENT must be set."
11-
exit 1
12-
fi
9+
require_value() {
10+
local name="$1"
11+
local value="$2"
1312

14-
if [[ -z "${sub_environment}" ]]; then
15-
echo "SUB_ENVIRONMENT must be set."
16-
exit 1
17-
fi
13+
if [[ -z "${value}" ]]; then
14+
echo "${name} must be set."
15+
exit 1
16+
fi
17+
}
1818

19-
if [[ -z "${resource_scope}" ]]; then
20-
echo "RESOURCE_SCOPE must be set."
21-
exit 1
22-
fi
19+
require_value "ENVIRONMENT" "${environment}"
20+
require_value "SUB_ENVIRONMENT" "${sub_environment}"
21+
require_value "RESOURCE_SCOPE" "${resource_scope}"
2322

2423
lookup_mapping_uuid() {
2524
local event_source_arn="$1"

0 commit comments

Comments
 (0)