Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding style normalisation #155

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true
[*]
indent_style = space
indent_size = 2
shell_variant = bash
binary_next_line = true
switch_case_indent = true
space_redirects = true
keep_padding = true
function_next_line = false
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: "Linting & Formatting"

on:
- push
- pull_request
Expand All @@ -6,7 +8,14 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ludeeus/action-shellcheck@master
- name: "Checkout"
uses: actions/checkout@v4

- name: "Lint check"
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -x
- name: "Format check"
run: |
curl -sS https://webi.sh/shfmt | sh
shfmt -l -d .
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ brew "yq"
brew "coreutils"
brew "oath-toolkit"
brew "gnupg"
brew "shfmt"
cask "session-manager-plugin"
27 changes: 10 additions & 17 deletions bin/aurora/count-sql-backups
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ]
then
usage
if [ $# -lt 1 ]; then
usage
fi

while getopts "i:r:e:d:h" opt; do
Expand All @@ -43,12 +42,7 @@ while getopts "i:r:e:d:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME"
|| -z "$RDS_NAME"
|| -z "$ENVIRONMENT"
]]
then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$RDS_NAME" || -z "$ENVIRONMENT" ]]; then
usage
fi

Expand All @@ -62,13 +56,12 @@ TODAY=$(date +%Y-%m-%d)

echo "==> Counting SQL backups in $INFRASTRUCTURE_NAME $RDS_NAME $ENVIRONMENT..."

if [ -n "$DATE" ]
then
aws s3api list-objects-v2 \
--bucket "$S3_BUCKET_NAME" \
--query "Contents[?contains(LastModified,\`${DATE}\`)].Key" | jq -r 'length'
if [ -n "$DATE" ]; then
aws s3api list-objects-v2 \
--bucket "$S3_BUCKET_NAME" \
--query "Contents[?contains(LastModified,\`${DATE}\`)].Key" | jq -r 'length'
else
aws s3api list-objects-v2 \
--bucket "$S3_BUCKET_NAME" \
--query "Contents[?contains(LastModified,\`${TODAY}\`)].Key" | jq -r 'length'
aws s3api list-objects-v2 \
--bucket "$S3_BUCKET_NAME" \
--query "Contents[?contains(LastModified,\`${TODAY}\`)].Key" | jq -r 'length'
fi
18 changes: 4 additions & 14 deletions bin/aurora/create-database
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ]
then
usage
if [ $# -lt 1 ]; then
usage
fi

while getopts "i:e:r:d:u:P:I:h" opt; do
Expand Down Expand Up @@ -55,15 +54,7 @@ while getopts "i:e:r:d:u:P:I:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME"
|| -z "$RDS_NAME"
|| -z "$DB_NAME"
|| -z "$USER_NAME"
|| -z "$USER_PASSWORD"
|| -z "$ENVIRONMENT"
]]
then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$RDS_NAME" || -z "$DB_NAME" || -z "$USER_NAME" || -z "$USER_PASSWORD" || -z "$ENVIRONMENT" ]]; then
usage
fi

Expand Down Expand Up @@ -96,8 +87,7 @@ RDS_ROOT_USERNAME=$(echo "$RDS_INFO" | jq -r .DBClusters[0].MasterUsername)
echo "Engine: $RDS_ENGINE"
echo "Root username: $RDS_ROOT_USERNAME"

if [ -z "$ECS_INSTANCE_ID" ]
then
if [ -z "$ECS_INSTANCE_ID" ]; then
echo "==> Finding ECS instance..."

ECS_INSTANCES=$(
Expand Down
19 changes: 5 additions & 14 deletions bin/aurora/export-dump
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ]
then
usage
if [ $# -lt 1 ]; then
usage
fi

while getopts "i:e:r:d:o:I:h" opt; do
Expand Down Expand Up @@ -51,18 +50,11 @@ while getopts "i:e:r:d:o:I:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME"
|| -z "$RDS_NAME"
|| -z "$DATABASE_NAME"
|| -z "$ENVIRONMENT"
]]
then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$RDS_NAME" || -z "$DATABASE_NAME" || -z "$ENVIRONMENT" ]]; then
usage
fi

if [ -n "$OUTPUT_FILE_PATH" ]
then
if [ -n "$OUTPUT_FILE_PATH" ]; then
OUTPUT_FILE_PATH="$(realpath "$OUTPUT_FILE_PATH")"
else
OUTPUT_FILE_PATH="."
Expand Down Expand Up @@ -97,8 +89,7 @@ RDS_ROOT_USERNAME=$(echo "$RDS_INFO" | jq -r .DBClusters[0].MasterUsername)
echo "Engine: $RDS_ENGINE"
echo "Root username: $RDS_ROOT_USERNAME"

if [ -z "$ECS_INSTANCE_ID" ]
then
if [ -z "$ECS_INSTANCE_ID" ]; then
echo "==> Finding ECS instance..."

ECS_INSTANCES=$(
Expand Down
11 changes: 3 additions & 8 deletions bin/aurora/get-root-password
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ];
then
usage
if [ $# -lt 1 ]; then
usage
fi

while getopts "i:e:r:h" opt; do
Expand All @@ -39,11 +38,7 @@ while getopts "i:e:r:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME"
|| -z "$RDS_NAME"
|| -z "$ENVIRONMENT"
]]; then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$RDS_NAME" || -z "$ENVIRONMENT" ]]; then
usage
fi

Expand Down
33 changes: 13 additions & 20 deletions bin/aurora/import-dump
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ]
then
usage
if [ $# -lt 1 ]; then
usage
fi

SCRIPT_PATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
Expand Down Expand Up @@ -60,13 +59,7 @@ while getopts "i:e:r:d:f:R:p:I:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME"
|| -z "$RDS_NAME"
|| -z "$DATABASE_NAME"
|| -z "$ENVIRONMENT"
]]
then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$RDS_NAME" || -z "$DATABASE_NAME" || -z "$ENVIRONMENT" ]]; then
usage
fi

Expand Down Expand Up @@ -99,8 +92,7 @@ RDS_ROOT_USERNAME=$(echo "$RDS_INFO" | jq -r .DBClusters[0].MasterUsername)
echo "Engine: $RDS_ENGINE"
echo "Root username: $RDS_ROOT_USERNAME"

if [ -z "$ECS_INSTANCE_ID" ]
then
if [ -z "$ECS_INSTANCE_ID" ]; then
echo "==> Finding ECS instance..."

ECS_INSTANCES=$(
Expand All @@ -115,14 +107,12 @@ fi

echo "ECS instance ID: $ECS_INSTANCE_ID"

if [ ! -f "$DB_DUMP_FILE" ];
then
if [ ! -f "$DB_DUMP_FILE" ]; then
echo "$DB_DUMP_FILE not found ..."
exit 1
fi

if [ -n "$REWRITE_FILE" ];
then
if [ -n "$REWRITE_FILE" ]; then
INPUT_FILE="$(realpath "$DB_DUMP_FILE")"
OUTPUT_PATH="$APP_ROOT/bin/tmp/sql-munged"
REWRITE_FILE="$(realpath "$REWRITE_FILE")"
Expand All @@ -149,12 +139,15 @@ echo ""
echo "Are you sure?"
echo ""

echo "Continue (Yes/No)"
echo "Continue (Y/N)"
read -r -p " > " choice

case "$choice" in
Yes ) echo "==> Importing ...";;
* ) echo "Aborting!"
exit 1
Y)
echo "==> Importing ..."
;;
*)
echo "Aborting!" && exit 1
;;
esac

Expand Down
16 changes: 4 additions & 12 deletions bin/aurora/list-databases
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ]
then
usage
if [ $# -lt 1 ]; then
usage
fi

while getopts "i:e:r:h" opt; do
Expand All @@ -39,12 +38,7 @@ while getopts "i:e:r:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME"
|| -z "$ENVIRONMENT"
|| -z "$RDS_NAME"
]]
then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$ENVIRONMENT" || -z "$RDS_NAME" ]]; then
usage
fi

Expand All @@ -65,9 +59,7 @@ RDS_ROOT_PASSWORD=$(
| jq -r .Parameters[0].Value
)


if [ -z "$ECS_INSTANCE_ID" ]
then
if [ -z "$ECS_INSTANCE_ID" ]; then
echo "==> Finding ECS instance..."

ECS_INSTANCES=$(
Expand Down
13 changes: 4 additions & 9 deletions bin/aurora/list-instances
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ]
then
usage
if [ $# -lt 1 ]; then
usage
fi

while getopts "i:e:h" opt; do
Expand All @@ -35,17 +34,13 @@ while getopts "i:e:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME" ||
-z "$ENVIRONMENT"
]]
then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$ENVIRONMENT" ]]; then
usage
fi

echo "==> Getting RDS instances in $INFRASTRUCTURE_NAME $ENVIRONMENT..."

RDS_IDENTIFIER_SEARCH="${INFRASTRUCTURE_NAME//-/}.*${ENVIRONMENT//-/}"

aws rds describe-db-clusters \
aws rds describe-db-clusters \
| jq -r '.DBClusters[] | "Name: \(.DBClusterIdentifier) Engine: \(.Engine) Address: \(.Endpoint):\(.Port)" ' | grep "$RDS_IDENTIFIER_SEARCH"
12 changes: 3 additions & 9 deletions bin/aurora/set-root-password
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ usage() {
}

# if there are no arguments passed exit with usage
if [ $# -lt 1 ];
then
usage
if [ $# -lt 1 ]; then
usage
fi

while getopts "i:e:r:P:h" opt; do
Expand All @@ -43,12 +42,7 @@ while getopts "i:e:r:P:h" opt; do
esac
done

if [[
-z "$INFRASTRUCTURE_NAME"
|| -z "$RDS_NAME"
|| -z "$ENVIRONMENT"
|| -z "$NEW_PASSWORD"
]]; then
if [[ -z "$INFRASTRUCTURE_NAME" || -z "$RDS_NAME" || -z "$ENVIRONMENT" || -z "$NEW_PASSWORD" ]]; then
usage
fi

Expand Down
Loading