@openstax/ts-utils 1.2.8 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/script/.build-dist.swo +0 -0
- package/script/.build-dist.swp +0 -0
- package/script/bin/copy-from-template.bash +32 -0
- package/script/bin/delete-stack.bash +22 -0
- package/script/bin/deploy.bash +41 -0
- package/script/bin/destroy-deployment.bash +60 -0
- package/script/bin/empty-bucket.bash +28 -0
- package/script/bin/get-arg.bash +10 -0
- package/script/bin/get-deployed-environments.bash +9 -0
- package/script/bin/get-env-param.bash +23 -0
- package/script/bin/get-kwarg.bash +10 -0
- package/script/bin/get-stack-param.bash +6 -0
- package/script/bin/has-flag.bash +10 -0
- package/script/bin/init-constants-script.bash +20 -0
- package/script/bin/init-params-script.bash +118 -0
- package/script/bin/stack-exists.bash +5 -0
- package/script/bin/upload-pager-duty-endpoints.bash +44 -0
- package/script/bin/upload-params.bash +59 -0
- package/script/bin/which.bash +14 -0
- package/script/bin-entry.bash +33 -0
- package/script/build.bash +21 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openstax/ts-utils",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.9",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"dist"
|
|
30
|
+
"dist",
|
|
31
|
+
"script"
|
|
31
32
|
],
|
|
32
33
|
"typesVersions": {
|
|
33
34
|
"*": {
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
project_dir=$(pwd)
|
|
6
|
+
|
|
7
|
+
temp_dir="$(dirname "$(mktemp -u)")/service-template"
|
|
8
|
+
patch_file=$(mktemp -t tst-patch.XXX)
|
|
9
|
+
|
|
10
|
+
if [ -d "$temp_dir" ]; then
|
|
11
|
+
cd "$temp_dir"
|
|
12
|
+
git pull
|
|
13
|
+
else
|
|
14
|
+
git clone git@github.com:openstax/typescript-service-template.git "$temp_dir"
|
|
15
|
+
cd "$temp_dir"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
read -d '\n' -r -a sync_ignore <<< "$(awk '{print ":\!*" $0}' "$project_dir/.syncignore")" || true
|
|
19
|
+
|
|
20
|
+
sync_from=$(git hash-object -t tree /dev/null)
|
|
21
|
+
if [ -f "$project_dir/.lastsync" ]; then
|
|
22
|
+
sync_from=$(< "$project_dir/.lastsync")
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
git rev-parse HEAD > "$project_dir/.lastsync"
|
|
26
|
+
git --no-pager diff --binary "$sync_from" "${sync_ignore[@]}" > "$patch_file"
|
|
27
|
+
|
|
28
|
+
cd "$project_dir"
|
|
29
|
+
|
|
30
|
+
git apply --reject --whitespace=nowarn "$patch_file" || true
|
|
31
|
+
|
|
32
|
+
echo "$project_dir"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
|
|
6
|
+
|
|
7
|
+
name=$1
|
|
8
|
+
region=$2
|
|
9
|
+
|
|
10
|
+
printf "\nchecking %s stack..." "$name"
|
|
11
|
+
if AWS_DEFAULT_REGION="$region" yarn -s ts-utils stack-exists "$name"; then
|
|
12
|
+
printf " deleting it"
|
|
13
|
+
AWS_DEFAULT_REGION="$region" aws cloudformation delete-stack --region "$region" --stack-name "$name"
|
|
14
|
+
|
|
15
|
+
while AWS_DEFAULT_REGION="$region" yarn -s ts-utils stack-exists "$name"; do
|
|
16
|
+
printf "."
|
|
17
|
+
sleep 5
|
|
18
|
+
done
|
|
19
|
+
echo
|
|
20
|
+
else
|
|
21
|
+
echo "stack not found."
|
|
22
|
+
fi
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
source $(yarn -s ts-utils which init-constants-script)
|
|
6
|
+
|
|
7
|
+
if [ -z "${APPLICATION:-}" ]; then echo "APPLICATION must be set" > /dev/stderr; exit 1; fi
|
|
8
|
+
if [ -z "${OWNER:-}" ]; then echo "OWNER must be set" > /dev/stderr; exit 1; fi
|
|
9
|
+
if [ -z "${PROJECT:-}" ]; then echo "PROJECT must be set" > /dev/stderr; exit 1; fi
|
|
10
|
+
if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
|
|
11
|
+
|
|
12
|
+
if [ "$#" -lt 1 ]; then
|
|
13
|
+
cat <<HEREDOC
|
|
14
|
+
|
|
15
|
+
Usage: yarn -s ts-utils deploy <environment>
|
|
16
|
+
|
|
17
|
+
Deploys the given $APPLICATION environment
|
|
18
|
+
|
|
19
|
+
HEREDOC
|
|
20
|
+
|
|
21
|
+
exit 1
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
ENVIRONMENT=$1
|
|
25
|
+
export ENVIRONMENT;
|
|
26
|
+
|
|
27
|
+
# this outputs the account alias, eg "openstax" or "openstax-dev-sandbox"
|
|
28
|
+
AWS_ACCOUNT=$(aws iam list-account-aliases --output text --query 'AccountAliases[0]')
|
|
29
|
+
export AWS_ACCOUNT;
|
|
30
|
+
|
|
31
|
+
if [ -z "$AWS_ACCOUNT" ]; then
|
|
32
|
+
echo "authorized. aws account not set, make sure you're logged in" > /dev/stderr
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
if [ ! -f "./deploy/deploy.bash" ]; then
|
|
37
|
+
echo "could not find project deployment script at ./deploy/deploy.bash" > /dev/stderr;
|
|
38
|
+
exit 1
|
|
39
|
+
fi;
|
|
40
|
+
|
|
41
|
+
./deploy/deploy.bash
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail kwarg
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
source $(yarn -s ts-utils which init-constants-script)
|
|
6
|
+
|
|
7
|
+
if [ -z "${APPLICATION:-}" ]; then echo "APPLICATION must be set" > /dev/stderr; exit 1; fi
|
|
8
|
+
if [ -z "${OWNER:-}" ]; then echo "OWNER must be set" > /dev/stderr; exit 1; fi
|
|
9
|
+
if [ -z "${PROJECT:-}" ]; then echo "PROJECT must be set" > /dev/stderr; exit 1; fi
|
|
10
|
+
if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
|
|
11
|
+
|
|
12
|
+
function print_usage_and_exit() {
|
|
13
|
+
cat <<HEREDOC
|
|
14
|
+
|
|
15
|
+
Usage: yarn -s ts-utils destroy-deployment <environment> [options]
|
|
16
|
+
|
|
17
|
+
Destroys the given $APPLICATION environment
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
-y - skips confirmation prompts - default: don't skip
|
|
21
|
+
|
|
22
|
+
HEREDOC
|
|
23
|
+
|
|
24
|
+
exit 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if [ "$#" -lt 1 ]; then
|
|
28
|
+
print_usage_and_exit
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
ENVIRONMENT=$(yarn -s ts-utils get-arg 0 "$@")
|
|
32
|
+
export ENVIRONMENT;
|
|
33
|
+
|
|
34
|
+
YES=$(yarn -s ts-utils get-kwarg y "$@")
|
|
35
|
+
export YES
|
|
36
|
+
|
|
37
|
+
if [ -z "$YES" ]; then
|
|
38
|
+
printf "This will destroy the %s %s environment. Proceed? [y/N]: " "$APPLICATION" "$ENVIRONMENT"
|
|
39
|
+
read -r do_it
|
|
40
|
+
|
|
41
|
+
if [ "$do_it" != "y" ]; then
|
|
42
|
+
exit 1
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# this outputs the account alias, eg "openstax" or "openstax-dev-sandbox"
|
|
47
|
+
AWS_ACCOUNT=$(aws iam list-account-aliases --output text --query 'AccountAliases[0]')
|
|
48
|
+
export AWS_ACCOUNT;
|
|
49
|
+
|
|
50
|
+
if [ -z "$AWS_ACCOUNT" ]; then
|
|
51
|
+
echo "authorized. aws account not set, make sure you're logged in" > /dev/stderr
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
if [ ! -f "./deploy/destroy-deployment.bash" ]; then
|
|
56
|
+
echo "could not find project destroy deployment script at ./deploy/destroy-deployment.bash" > /dev/stderr;
|
|
57
|
+
exit 1
|
|
58
|
+
fi;
|
|
59
|
+
|
|
60
|
+
./deploy/destroy-deployment.bash
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
cliVersion=$(aws --version)
|
|
6
|
+
if [[ "$cliVersion" == aws-cli/2* ]]; then
|
|
7
|
+
pager=--no-cli-pager
|
|
8
|
+
else
|
|
9
|
+
pager=
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
bucketName=$1
|
|
13
|
+
# Deleting versioned buckets is harder than non-versioned ones
|
|
14
|
+
|
|
15
|
+
versions=$(aws s3api list-object-versions \
|
|
16
|
+
--bucket "$bucketName" \
|
|
17
|
+
--output json \
|
|
18
|
+
--query '{Objects: Versions[].{Key:Key,VersionId:VersionId}}' \
|
|
19
|
+
"$pager")
|
|
20
|
+
|
|
21
|
+
versionsWithQuietFlag="${versions:0:$((${#versions}-1))}, \"Quiet\": true }"
|
|
22
|
+
|
|
23
|
+
if [[ ${versions} =~ Objects\":\ null ]]; then
|
|
24
|
+
echo "$bucketName" is empty.
|
|
25
|
+
else
|
|
26
|
+
echo "Deleting files in $bucketName."
|
|
27
|
+
aws s3api delete-objects --bucket "$bucketName" --delete "$versionsWithQuietFlag" "$pager"
|
|
28
|
+
fi
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail yargs
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
target=$1
|
|
6
|
+
shift
|
|
7
|
+
args=("$@")
|
|
8
|
+
|
|
9
|
+
# https://stackoverflow.com/a/61551944/14809536
|
|
10
|
+
node -e "console.log(require('yargs').argv['_']['$target'] || '')" -- yargs "${args[@]+"${args[@]}"}"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
source $(yarn -s ts-utils which init-constants-script)
|
|
6
|
+
|
|
7
|
+
if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
|
|
8
|
+
|
|
9
|
+
aws cloudformation describe-stacks --query "Stacks[?Tags[?Key == 'Project' && Value == '$PROJECT'] && Tags[?Key == 'Application' && Value == '$APPLICATION'] && Tags[?Key == 'Environment' && Value != 'shared']].[Tags[?Key=='Environment'].Value]" --output text
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
source $(yarn -s ts-utils which init-constants-script)
|
|
6
|
+
source $(yarn -s ts-utils which init-params-script)
|
|
7
|
+
|
|
8
|
+
environment=$(yarn -s ts-utils get-arg 0 "$@")
|
|
9
|
+
param=$(yarn -s ts-utils get-arg 1 "$@")
|
|
10
|
+
|
|
11
|
+
if [ -z "$environment" ] || [ -z "$param" ]; then
|
|
12
|
+
cat <<HEREDOC
|
|
13
|
+
Usage: $(basename ${BASH_SOURCE[0]}) <environment> <parameter name>
|
|
14
|
+
|
|
15
|
+
Shows secret value from AWS parameter store
|
|
16
|
+
HEREDOC
|
|
17
|
+
|
|
18
|
+
exit 1
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
name=$(get_param_name)
|
|
22
|
+
|
|
23
|
+
get_parameter
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail yargs
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
target=$1
|
|
6
|
+
shift
|
|
7
|
+
args=("$@")
|
|
8
|
+
|
|
9
|
+
# https://stackoverflow.com/a/61551944/14809536
|
|
10
|
+
node -e "console.log(require('yargs').argv['$target'] || '')" -- yargs "${args[@]+"${args[@]}"}"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
aws cloudformation describe-stacks --stack-name "$1" --output json | \
|
|
6
|
+
jq -r --arg key "$2" '(.Stacks[0].Outputs // [])[]|select(.OutputKey == $key).OutputValue'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail yargs
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
target=$1
|
|
6
|
+
shift
|
|
7
|
+
args=("$@")
|
|
8
|
+
|
|
9
|
+
# https://stackoverflow.com/a/61551944/14809536
|
|
10
|
+
node -e "if (!require('yargs').argv['$target']) { process.exit(1) }" -- yargs "${args[@]+"${args[@]}"}"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
# https://stackoverflow.com/a/28776166
|
|
6
|
+
([[ -n "${ZSH_EVAL_CONTEXT:-}" && "$ZSH_EVAL_CONTEXT" =~ :file$ ]] ||
|
|
7
|
+
[[ -n "$BASH_VERSION" ]] && (return 0 2>/dev/null)) && sourced=true || sourced=false
|
|
8
|
+
|
|
9
|
+
if [ "$sourced" == "false" ]; then
|
|
10
|
+
echo "env files must be sourced" > /dev/stderr
|
|
11
|
+
exit 1
|
|
12
|
+
fi;
|
|
13
|
+
|
|
14
|
+
# yarn seems to naturally run things from the project root, so this is just a safety check
|
|
15
|
+
if [ ! -f "./deploy/constants.env" ]; then
|
|
16
|
+
echo "This command must be run from the project root directory" > /dev/stderr;
|
|
17
|
+
exit 1
|
|
18
|
+
fi;
|
|
19
|
+
|
|
20
|
+
source "./deploy/constants.env"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail kwarg urlparam
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
# https://stackoverflow.com/a/28776166
|
|
6
|
+
([[ -n "${ZSH_EVAL_CONTEXT:-}" && "$ZSH_EVAL_CONTEXT" =~ :file$ ]] ||
|
|
7
|
+
[[ -n "$BASH_VERSION" ]] && (return 0 2>/dev/null)) && sourced=true || sourced=false
|
|
8
|
+
|
|
9
|
+
if [ "$sourced" == "false" ]; then
|
|
10
|
+
echo "env files must be sourced" > /dev/stderr
|
|
11
|
+
exit 1
|
|
12
|
+
fi;
|
|
13
|
+
|
|
14
|
+
# note - usually you wouldn't use exit from a sourced script, but this is never sourced
|
|
15
|
+
# into an interactive shell, only as a script helper, so we want it to exit the script
|
|
16
|
+
if [ -z "${APPLICATION:-}" ]; then echo "APPLICATION must be set" > /dev/stderr; exit 1; fi
|
|
17
|
+
if [ -z "${OWNER:-}" ]; then echo "OWNER must be set" > /dev/stderr; exit 1; fi
|
|
18
|
+
if [ -z "${PROJECT:-}" ]; then echo "PROJECT must be set" > /dev/stderr; exit 1; fi
|
|
19
|
+
|
|
20
|
+
region=$(yarn -s ts-utils get-kwarg r "$@")
|
|
21
|
+
region=${region:-us-east-1}
|
|
22
|
+
|
|
23
|
+
# Prevent bad behavior when trying to upload URL params on aws cli v1
|
|
24
|
+
aws_version=$(aws --version)
|
|
25
|
+
if [ -z "${aws_version##aws-cli/1.*}" ]; then
|
|
26
|
+
# true is the default value for aws cli v1
|
|
27
|
+
original_cli_follow_urlparam=$(aws configure get cli_follow_urlparam || echo 'true')
|
|
28
|
+
|
|
29
|
+
function restore_cli_follow_urlparam() {
|
|
30
|
+
aws configure set cli_follow_urlparam "$original_cli_follow_urlparam"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Needed to upload URLs as secret values. Explanation: https://github.com/aws/aws-cli/issues/2507
|
|
34
|
+
aws configure set cli_follow_urlparam false
|
|
35
|
+
|
|
36
|
+
trap restore_cli_follow_urlparam EXIT
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
function get_param_name() {
|
|
40
|
+
echo "/$APPLICATION/$environment/api/$param"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function get_value() {
|
|
44
|
+
printf "Enter new value for \"$name\" (leave blank to skip): "
|
|
45
|
+
read -r value
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function get_parameter() {
|
|
49
|
+
aws ssm get-parameter --region "$region" --name "$name" --with-decryption \
|
|
50
|
+
--query Parameter.Value --output text 2>&1
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function upload_parameter() {
|
|
54
|
+
set +e
|
|
55
|
+
previous_value=$(get_parameter)
|
|
56
|
+
get_parameter_failed=$?
|
|
57
|
+
set -e
|
|
58
|
+
|
|
59
|
+
if [ "$get_parameter_failed" -eq 0 ]; then
|
|
60
|
+
echo "Parameter \"$name\" already exists"
|
|
61
|
+
|
|
62
|
+
if [ -n "${interactive:-}" ]; then
|
|
63
|
+
echo "Current value: \"$previous_value\""
|
|
64
|
+
|
|
65
|
+
get_value
|
|
66
|
+
|
|
67
|
+
if [ -z "$value" ]; then
|
|
68
|
+
echo "Skipping parameter \"$name\" (previous value kept)"
|
|
69
|
+
|
|
70
|
+
return
|
|
71
|
+
fi
|
|
72
|
+
# The parameter store (or maybe the upload command) removes trailing newlines
|
|
73
|
+
# Maybe relevant when uploading public/private key certificates
|
|
74
|
+
elif [ "$value" = "$previous_value" ] || [ "$value" = "$previous_value"$'\n' ]; then
|
|
75
|
+
echo "Skipping parameter \"$name\" as the new and previous values match"
|
|
76
|
+
|
|
77
|
+
return
|
|
78
|
+
else
|
|
79
|
+
echo "New and previous values for parameter \"$param\" differ"
|
|
80
|
+
|
|
81
|
+
if [ -z "$overwrite" ]; then
|
|
82
|
+
echo "Skipping parameter \"$name\" as the -o option was not set (previous value kept)"
|
|
83
|
+
|
|
84
|
+
return
|
|
85
|
+
fi
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
if [ -n "$value" ]; then
|
|
89
|
+
echo "Overwriting parameter \"$name\" with new value"
|
|
90
|
+
|
|
91
|
+
aws ssm put-parameter --region "$region" --type SecureString \
|
|
92
|
+
--name "$name" --value "$value" --overwrite
|
|
93
|
+
else
|
|
94
|
+
echo "Skipping parameter \"$name\" (previous value kept)"
|
|
95
|
+
fi
|
|
96
|
+
elif [[ -n "${previous_value##*ParameterNotFound*}" ]]; then
|
|
97
|
+
# Error is NOT ParameterNotFound
|
|
98
|
+
printf "%s\n\n" "$previous_value"
|
|
99
|
+
exit 1
|
|
100
|
+
else
|
|
101
|
+
# Error is ParameterNotFound
|
|
102
|
+
if [ -n "${interactive:-}" ]; then
|
|
103
|
+
get_value
|
|
104
|
+
|
|
105
|
+
if [ -z "$value" ]; then
|
|
106
|
+
echo "Skipping parameter \"$name\" (not uploaded)"
|
|
107
|
+
|
|
108
|
+
return
|
|
109
|
+
fi
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
echo "Uploading new parameter \"$name\""
|
|
113
|
+
|
|
114
|
+
aws ssm put-parameter --region "$region" --type SecureString --name "$name" --value "$value" \
|
|
115
|
+
--tags "Key=Project,Value=$PROJECT" "Key=Application,Value=$APPLICATION" \
|
|
116
|
+
'Key=Environment,Value=shared' "Key=Owner,Value=$OWNER"
|
|
117
|
+
fi
|
|
118
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail kwarg
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
source $(yarn -s ts-utils which init-constants-script)
|
|
6
|
+
source $(yarn -s ts-utils which init-params-script)
|
|
7
|
+
|
|
8
|
+
# List all configured PagerDuty endpoints here
|
|
9
|
+
ENDPOINTS=(
|
|
10
|
+
anytime
|
|
11
|
+
workday
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
help=$(yarn -s ts-utils get-kwarg h "$@")
|
|
15
|
+
|
|
16
|
+
if [ -n "$help" ]; then
|
|
17
|
+
cat <<HEREDOC
|
|
18
|
+
Usage: $(basename ${BASH_SOURCE[0]}) [options]
|
|
19
|
+
|
|
20
|
+
Uploads PagerDuty endpoints to the AWS parameter store with proper tags
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
-h - display this help message and exit
|
|
24
|
+
-r - set AWS region - default: us-east-1
|
|
25
|
+
|
|
26
|
+
HEREDOC
|
|
27
|
+
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
interactive=true
|
|
32
|
+
environment=shared
|
|
33
|
+
|
|
34
|
+
printf "Find or create your PagerDuty service endpoints here: https://staxly.pagerduty.com/service-directory\n\n"
|
|
35
|
+
|
|
36
|
+
for endpoint in "${ENDPOINTS[@]}"; do
|
|
37
|
+
name="/external/pager_duty/$APPLICATION/${endpoint}_endpoint"
|
|
38
|
+
|
|
39
|
+
upload_parameter
|
|
40
|
+
|
|
41
|
+
echo
|
|
42
|
+
done
|
|
43
|
+
|
|
44
|
+
printf "\nDone uploading PagerDuty endpoints for $APPLICATION\n\n"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail kwarg sparameters
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
source $(yarn -s ts-utils which init-constants-script)
|
|
6
|
+
source $(yarn -s ts-utils which init-params-script)
|
|
7
|
+
|
|
8
|
+
if [ -z "${PARAMS:-}" ]; then echo "PARAMS must be set" > /dev/stderr; exit 1; fi
|
|
9
|
+
|
|
10
|
+
environment=$(yarn -s ts-utils get-arg 0 "$@")
|
|
11
|
+
|
|
12
|
+
if [ -z "$environment" ]; then
|
|
13
|
+
cat <<HEREDOC
|
|
14
|
+
Usage: $(basename "${BASH_SOURCE[0]}") <environment> [options]
|
|
15
|
+
|
|
16
|
+
Uploads secret values from your environment to the AWS parameter store with proper tags
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
-o - overwrite existing parameters - default: don't overwrite
|
|
20
|
+
-p - upload set parameters, even if some are missing - default: abort if any are missing
|
|
21
|
+
-r - set AWS region - default: us-east-1
|
|
22
|
+
|
|
23
|
+
HEREDOC
|
|
24
|
+
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
overwrite=$(yarn -s ts-utils get-kwarg o "$@")
|
|
29
|
+
partial=$(yarn -s ts-utils get-kwarg p "$@")
|
|
30
|
+
|
|
31
|
+
# Check if any params are missing
|
|
32
|
+
params_with_value=
|
|
33
|
+
for param in "${PARAMS[@]}"; do
|
|
34
|
+
if [ -n "${!param:-}" ]; then
|
|
35
|
+
params_with_value="$params_with_value $param"
|
|
36
|
+
else
|
|
37
|
+
if [ -n "$partial" ]; then
|
|
38
|
+
echo "\"$param\" not uploaded as it is not set or not exported in your environment"
|
|
39
|
+
else
|
|
40
|
+
echo "\"$param\" is not set or not exported in your environment"
|
|
41
|
+
printf "Please set it first or use the -p option to upload only defined variables\n\n"
|
|
42
|
+
exit 1
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
done
|
|
46
|
+
|
|
47
|
+
if [ -z "$params_with_value" ]; then
|
|
48
|
+
printf '\nAborting: None of the parameters that could be uploaded have values\n\n'
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
for param in $params_with_value; do
|
|
53
|
+
name="$(get_param_name)"
|
|
54
|
+
value="${!param}"
|
|
55
|
+
|
|
56
|
+
upload_parameter
|
|
57
|
+
done
|
|
58
|
+
|
|
59
|
+
printf "\nSuccessfully uploaded %sparameters for %s-%s\n\n" "${partial:+partial }" "$environment" "$APPLICATION"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
project_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." >/dev/null 2>&1 && pwd )"
|
|
6
|
+
|
|
7
|
+
file="$project_dir"/script/bin/"$1".bash
|
|
8
|
+
|
|
9
|
+
if [ ! -f "$file" ]; then
|
|
10
|
+
echo "$1 not found" > /dev/stderr;
|
|
11
|
+
exit 1;
|
|
12
|
+
fi;
|
|
13
|
+
|
|
14
|
+
echo "$file";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
project_dir="$(cd "$(dirname "$0")" && cd "$(dirname "$(readlink "$0")")/.." && pwd)"
|
|
6
|
+
|
|
7
|
+
script=${1-}
|
|
8
|
+
|
|
9
|
+
bin="$project_dir/script/bin/"
|
|
10
|
+
file="$bin$script.bash"
|
|
11
|
+
|
|
12
|
+
if [ -z "$script" ]; then
|
|
13
|
+
printf "specify a command\n\neg:\n yarn -s ts-utils [command name] [parameters]\n\n"
|
|
14
|
+
|
|
15
|
+
find "$bin" -name "*.bash" -exec basename {} \; | sed "s/\.bash//" | sort
|
|
16
|
+
|
|
17
|
+
echo
|
|
18
|
+
exit 1;
|
|
19
|
+
elif [ -n "$script" ] && [ ! -f "$file" ]; then
|
|
20
|
+
printf "%s is not a valid command. did you mean:\n\n" "$script"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
find "$bin" -name "*$script*.bash" -exec basename {} \; | sed "s/\.bash//" | sort
|
|
24
|
+
|
|
25
|
+
echo
|
|
26
|
+
exit 1;
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
shift
|
|
30
|
+
args=("$@")
|
|
31
|
+
|
|
32
|
+
# https://stackoverflow.com/a/61551944/14809536
|
|
33
|
+
"$file" "${args[@]+"${args[@]}"}"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spell-checker: ignore pipefail yargs mkdir withoutspecs
|
|
3
|
+
set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
|
|
4
|
+
|
|
5
|
+
project_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
|
|
6
|
+
|
|
7
|
+
cd "$project_dir";
|
|
8
|
+
|
|
9
|
+
tsc_args=(--noEmit false --declaration)
|
|
10
|
+
|
|
11
|
+
if yarn -s ts-utils has-flag watch "$@"; then
|
|
12
|
+
tsc_args+=(--watch)
|
|
13
|
+
fi
|
|
14
|
+
if yarn -s ts-utils has-flag clean "$@"; then
|
|
15
|
+
rm -rf "$project_dir"/dist
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
mkdir -p dist
|
|
19
|
+
|
|
20
|
+
yarn -s tsc --project tsconfig.without-specs.esm.json "${tsc_args[@]}"
|
|
21
|
+
yarn -s tsc --project tsconfig.without-specs.cjs.json "${tsc_args[@]}"
|