Skip to content

Commit d47fc52

Browse files
authored
Add auto formatting for shell scripts (#461)
1 parent 7e14050 commit d47fc52

14 files changed

+182
-157
lines changed

docker/app/run-gunicorn.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare -a api_spec_paths
55
case "${CONNEXION_SPEC}" in
66
file:*)
77
specs="${CONNEXION_SPEC:5}"
8-
IFS="," read -r -a api_spec_paths <<< "${specs}"
8+
IFS="," read -r -a api_spec_paths <<<"${specs}"
99
;;
1010
dir:*)
1111
specs="${CONNEXION_SPEC:4}"

docker/ci/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ RUN wget -q https://github.com/instrumenta/kubeval/releases/download/${KUBEVAL_V
2626
&& rm kubeval-linux-amd64.tar.gz \
2727
&& kubeval --version
2828

29+
ARG SHFMT_VERSION=3.1.1
30+
RUN wget -q https://github.com/mvdan/sh/releases/download/v${SHFMT_VERSION}/shfmt_v${SHFMT_VERSION}_linux_amd64 \
31+
&& mv shfmt_v${SHFMT_VERSION}_linux_amd64 shfmt \
32+
&& cp shfmt /usr/local/bin \
33+
&& rm shfmt \
34+
&& chmod +x /usr/local/bin/shfmt \
35+
&& shfmt -version
36+
2937
COPY docker/ci/requirements.txt ./
3038
RUN pip install --no-cache-dir -r requirements.txt
3139

@@ -60,3 +68,5 @@ RUN helm lint --strict ./helm/opwen_cloudserver \
6068
&& helm template ./helm/opwen_cloudserver > helm.yaml \
6169
&& kubeval --ignore-missing-schemas helm.yaml \
6270
&& rm helm.yaml
71+
72+
RUN shfmt -d -i 2 -ci .

docker/integtest/0-wait-for-services.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ wait_for_appinsights() {
3131
for i in $(seq 1 "${max_retries}"); do
3232
if [[ \
3333
"$(az storage container exists \
34-
--name "${APPINSIGHTS_INSTRUMENTATIONKEY}" \
35-
--connection-string "$(az_connection_string)" \
36-
--output tsv)" = "True" \
37-
]]; then
34+
--name "${APPINSIGHTS_INSTRUMENTATIONKEY}" \
35+
--connection-string "$(az_connection_string)" \
36+
--output tsv)" = "True" ]] \
37+
; then
3838
log "Appinsights is running"
3939
return
4040
fi

docker/integtest/1-register-client.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,19 @@ if REGISTRATION_CREDENTIALS="baduser:badpassword" authenticated_request \
4040
"http://nginx:8888/api/email/register/" \
4141
-H "Content-Type: application/json" \
4242
-d '{"domain":"hacker.lokole.ca"}' \
43-
; then echo "Was able to register a client with bad basic auth credentials" >&2; exit 4; fi
43+
; then
44+
echo "Was able to register a client with bad basic auth credentials" >&2
45+
exit 4
46+
fi
4447

4548
if REGISTRATION_CREDENTIALS="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" authenticated_request \
4649
"http://nginx:8888/api/email/register/" \
4750
-H "Content-Type: application/json" \
4851
-d '{"domain":"hacker.lokole.ca"}' \
49-
; then echo "Was able to register a client with bad bearer credentials" >&2; exit 4; fi
52+
; then
53+
echo "Was able to register a client with bad bearer credentials" >&2
54+
exit 4
55+
fi
5056

5157
# also register another client to simulate multi-client emails
5258
authenticated_request \
@@ -68,7 +74,10 @@ if authenticated_request \
6874
"http://nginx:8888/api/email/register/" \
6975
-H "Content-Type: application/json" \
7076
-d '{"domain":"developer3.lokole.ca"}' \
71-
; then echo "Was able to register a duplicate client" >&2; exit 5; fi
77+
; then
78+
echo "Was able to register a duplicate client" >&2
79+
exit 5
80+
fi
7281

7382
authenticated_request \
7483
"http://nginx:8888/api/email/register/developer3.lokole.ca" \

docker/integtest/2-client-uploads-emails.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ mkdir -p "${out_dir}"
1111
emails_to_send="${in_dir}/client-emails.tar.gz"
1212
tar -czf "${emails_to_send}" -C "${in_dir}" emails.jsonl zzusers.jsonl
1313

14-
client_id="$(jq -r '.client_id' < "${out_dir}/register1.json")"
15-
resource_container="$(jq -r '.resource_container' < "${out_dir}/register1.json")"
14+
client_id="$(jq -r '.client_id' <"${out_dir}/register1.json")"
15+
resource_container="$(jq -r '.resource_container' <"${out_dir}/register1.json")"
1616
resource_id="$(uuidgen).tar.gz"
1717

1818
# workflow 1: send emails written on the client to the world

docker/integtest/3-receive-email-for-client.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ email_to_receive="${in_dir}/inbound-email.mime"
1313
if [[ -n "$1" ]]; then
1414
client_id="$1"
1515
else
16-
client_id="$(jq -r '.client_id' < "${out_dir}/register1.json")"
16+
client_id="$(jq -r '.client_id' <"${out_dir}/register1.json")"
1717
fi
1818

1919
# workflow 2a: receive an email directed at one of the clients

docker/integtest/4-client-downloads-emails.sh

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@ num_emails_expected_for_client[2]=1
1313

1414
for i in 1 2; do
1515

16-
client_id="$(jq -r '.client_id' < "${out_dir}/register${i}.json")"
17-
resource_container="$(jq -r '.resource_container' < "${out_dir}/register${i}.json")"
16+
client_id="$(jq -r '.client_id' <"${out_dir}/register${i}.json")"
17+
resource_container="$(jq -r '.resource_container' <"${out_dir}/register${i}.json")"
1818

19-
# workflow 2b: deliver emails written by the world to a lokole client
20-
# first the client makes a request to ask the server to package up all the
21-
# emails sent from the world to the client during the last period; the server
22-
# will package up the emails and store them on the shared blob storage
23-
curl -fs \
24-
-H "Accept: application/json" \
25-
"http://nginx:8888/api/email/download/${client_id}" \
26-
| tee "${out_dir}/download${i}.json"
19+
# workflow 2b: deliver emails written by the world to a lokole client
20+
# first the client makes a request to ask the server to package up all the
21+
# emails sent from the world to the client during the last period; the server
22+
# will package up the emails and store them on the shared blob storage
23+
curl -fs \
24+
-H "Accept: application/json" \
25+
"http://nginx:8888/api/email/download/${client_id}" |
26+
tee "${out_dir}/download${i}.json"
2727

28-
resource_id="$(jq -r '.resource_id' < "${out_dir}/download${i}.json")"
28+
resource_id="$(jq -r '.resource_id' <"${out_dir}/download${i}.json")"
2929

30-
# now we simulate the client downloading the package from the shared blob storage
31-
az_storage download "${resource_container}" "${resource_id}" "${out_dir}/downloaded${i}.tar.gz"
30+
# now we simulate the client downloading the package from the shared blob storage
31+
az_storage download "${resource_container}" "${resource_id}" "${out_dir}/downloaded${i}.tar.gz"
3232

33-
tar xzf "${out_dir}/downloaded${i}.tar.gz" -C "${out_dir}"
33+
tar xzf "${out_dir}/downloaded${i}.tar.gz" -C "${out_dir}"
3434

35-
num_emails_actual="$(wc -l "${out_dir}/emails.jsonl" | cut -d' ' -f1)"
36-
num_emails_expected="${num_emails_expected_for_client[${i}]}"
35+
num_emails_actual="$(wc -l "${out_dir}/emails.jsonl" | cut -d' ' -f1)"
36+
num_emails_expected="${num_emails_expected_for_client[${i}]}"
3737

38-
if [[ "${num_emails_actual}" -ne "${num_emails_expected}" ]]; then
39-
echo "Got ${num_emails_actual} emails but expected ${num_emails_expected}" >&2
40-
exit 1
41-
fi
38+
if [[ "${num_emails_actual}" -ne "${num_emails_expected}" ]]; then
39+
echo "Got ${num_emails_actual} emails but expected ${num_emails_expected}" >&2
40+
exit 1
41+
fi
4242

43-
rm "${out_dir}/emails.jsonl"
43+
rm "${out_dir}/emails.jsonl"
4444

4545
done

docker/integtest/6-receive-service-email.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mkdir -p "${out_dir}"
1010

1111
email_to_receive="${in_dir}/service-email.mime"
1212

13-
1413
#receive an email directed at the service endpoint
1514
http --check-status -f POST \
1615
"http://nginx:8888/api/email/sendgrid/service" \

docker/integtest/utils.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
set -eo pipefail
33

44
get_container() {
5-
docker ps --format '{{.Names}}' | grep "$1"
5+
docker ps --format '{{.Names}}' | grep "$1"
66
}
77

88
log() {
99
echo "$@" >&2
1010
}
1111

1212
authenticated_request() {
13-
local endpoint="$1"; shift
13+
local endpoint="$1"
14+
shift
1415

1516
if [[ "${REGISTRATION_CREDENTIALS}" =~ ^[^:]+:.*$ ]]; then
1617
curl -fs "${endpoint}" -u "${REGISTRATION_CREDENTIALS}" "$@"
@@ -38,7 +39,7 @@ az_storage() {
3839
--name "${blob}" \
3940
--container-name "${container}" \
4041
--connection-string "$(az_connection_string)" \
41-
> /dev/null
42+
>/dev/null
4243
}
4344

4445
wait_seconds() {

docker/nginx/run-nginx.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
mo < /app/nginx.conf.mustache > /app/nginx.conf
4-
mo < /app/server.conf.mustache > /etc/nginx/sites-enabled/server.conf
3+
mo </app/nginx.conf.mustache >/app/nginx.conf
4+
mo </app/server.conf.mustache >/etc/nginx/sites-enabled/server.conf
55

66
exec nginx -c "/app/nginx.conf" -p "${PWD}" -g "daemon off;"

0 commit comments

Comments
 (0)