Skip to content

Commit e52f0c0

Browse files
CCM-15866: Address Sonar Findings - Lots more
1 parent 47fc86f commit e52f0c0

21 files changed

Lines changed: 229 additions & 53 deletions

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Usage:
5050
[--overrideProjectName <name>] \
5151
[--overrideRoleName <name>]
5252
EOF
53+
return 0
5354
}
5455

5556
require_arg() {
@@ -61,6 +62,8 @@ require_arg() {
6162
usage
6263
exit 1
6364
fi
65+
66+
return 0
6467
}
6568

6669
while [[ $# -gt 0 ]]; do
@@ -110,7 +113,7 @@ while [[ $# -gt 0 ]]; do
110113
shift 2
111114
;;
112115
*)
113-
echo "[ERROR] Unknown argument: $1"
116+
echo "[ERROR] Unknown argument: $1" >&2
114117
exit 1
115118
;;
116119
esac
@@ -124,20 +127,23 @@ require_arg "--targetComponent" "${targetComponent:-}"
124127
require_arg "--targetAccountGroup" "${targetAccountGroup:-}"
125128

126129
if [[ -z "$APP_PEM_FILE" ]]; then
127-
echo "[ERROR] PEM_FILE environment variable is not set or is empty."
130+
echo "[ERROR] PEM_FILE environment variable is not set or is empty." >&2
128131
exit 1
129132
fi
130133

131134
if [[ -z "$APP_CLIENT_ID" ]]; then
132-
echo "[ERROR] CLIENT_ID environment variable is not set or is empty."
135+
echo "[ERROR] CLIENT_ID environment variable is not set or is empty." >&2
133136
exit 1
134137
fi
135138

136139
now=$(date +%s)
137140
iat=$((${now} - 60)) # Issues 60 seconds in the past
138141
exp=$((${now} + 600)) # Expires 10 minutes in the future
139142

140-
b64enc() { openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'; }
143+
b64enc() {
144+
openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'
145+
return 0
146+
}
141147

142148
header_json='{
143149
"typ":"JWT",
@@ -178,7 +184,7 @@ PR_TRIGGER_PAT=$(curl --request POST \
178184

179185
# Set default values if not provided
180186
if [[ -z "$PR_TRIGGER_PAT" ]]; then
181-
echo "[ERROR] PR_TRIGGER_PAT environment variable is not set or is empty."
187+
echo "[ERROR] PR_TRIGGER_PAT environment variable is not set or is empty." >&2
182188
exit 1
183189
fi
184190

@@ -244,7 +250,7 @@ trigger_response=$(curl -s -L \
244250
-d "$DISPATCH_EVENT" 2>&1)
245251

246252
if [[ $? -ne 0 ]]; then
247-
echo "[ERROR] Failed to trigger workflow. Response: $trigger_response"
253+
echo "[ERROR] Failed to trigger workflow. Response: $trigger_response" >&2
248254
exit 1
249255
fi
250256

@@ -264,8 +270,8 @@ for _ in {1..18}; do
264270
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch")
265271

266272
if ! echo "$response" | jq empty 2>/dev/null; then
267-
echo "[ERROR] Invalid JSON response from GitHub API during workflow polling:"
268-
echo "$response"
273+
echo "[ERROR] Invalid JSON response from GitHub API during workflow polling:" >&2
274+
echo "$response" >&2
269275
exit 1
270276
fi
271277

@@ -303,7 +309,7 @@ for _ in {1..18}; do
303309
done
304310

305311
if [[ -z "$workflow_run_url" || "$workflow_run_url" == null ]]; then
306-
echo "[ERROR] Failed to get the workflow run url. Exiting."
312+
echo "[ERROR] Failed to get the workflow run url. Exiting." >&2
307313
exit 1
308314
fi
309315

@@ -332,7 +338,7 @@ while true; do
332338
echo "[SUCCESS] Workflow completed successfully!"
333339
exit 0
334340
else
335-
echo "[FAIL] Workflow failed with conclusion: $conclusion"
341+
echo "[FAIL] Workflow failed with conclusion: $conclusion" >&2
336342
exit 1
337343
fi
338344
fi

containers/example-app/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Placeholder HTTP server for AppRunner. Replace with real application code.
2-
import http from 'http';
2+
import http from 'node:http';
33

44
export const createRequestHandler = () => {
55
return (_req: http.IncomingMessage, res: http.ServerResponse) => {

scripts/docker/dgoss.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-docker}"
1515

1616
info() {
1717
echo -e "INFO: $*" >&2;
18+
return 0
1819
}
1920
error() {
2021
echo -e "ERROR: $*" >&2;
@@ -32,6 +33,7 @@ cleanup() {
3233
info "Deleting container"
3334
$CONTAINER_RUNTIME rm -vf "$id" > /dev/null
3435
fi
36+
return 0
3537
}
3638

3739
run(){
@@ -67,6 +69,7 @@ run(){
6769
$CONTAINER_RUNTIME logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 &
6870
log_pid=$!
6971
info "Container ID: ${id:0:8}"
72+
return 0
7073
}
7174

7275
get_docker_file() {
@@ -79,6 +82,7 @@ get_docker_file() {
7982
$CONTAINER_RUNTIME cp "${cid}:${src}" "${dst}"
8083
info "Copied '${src}' from container to '${dst}'"
8184
fi
85+
return 0
8286
}
8387

8488
# Main

scripts/docker/docker.lib.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function docker-build() {
5353
docker tag "${DOCKER_IMAGE}:$(_get-effective-version)" "${DOCKER_IMAGE}:${version}"
5454
done
5555
docker rmi --force "$(docker images | grep "<none>" | awk '{print $3}')" 2> /dev/null ||:
56+
57+
return 0
5658
}
5759

5860
# Check test Docker image.
@@ -71,6 +73,8 @@ function docker-check-test() {
7173
"${DOCKER_IMAGE}:$(_get-effective-version)" 2>/dev/null \
7274
${cmd:-} \
7375
| grep -q "${check}" && echo PASS || echo FAIL
76+
77+
return 0
7478
}
7579

7680
# Run Docker image.
@@ -87,6 +91,8 @@ function docker-run() {
8791
${args:-} \
8892
"${DOCKER_IMAGE}:$(dir="$dir" _get-effective-version)" \
8993
${cmd:-}
94+
95+
return 0
9096
}
9197

9298
# Push Docker image.
@@ -100,6 +106,8 @@ function docker-push() {
100106
for version in $(dir="$dir" _get-all-effective-versions) latest; do
101107
docker push "${DOCKER_IMAGE}:${version}"
102108
done
109+
110+
return 0
103111
}
104112

105113
# Remove Docker resources.
@@ -123,6 +131,8 @@ function docker-clean() {
123131
rm -f \
124132
.version \
125133
Dockerfile.effective
134+
135+
return 0
126136
}
127137

128138
# Create effective version from the VERSION file.
@@ -147,6 +157,8 @@ function version-create-effective-file() {
147157
sed "s/\(\${hash}\|\$hash\)/$(git rev-parse --short HEAD)/g" \
148158
> "$dir/.version"
149159
fi
160+
161+
return 0
150162
}
151163

152164
# ==============================================================================
@@ -203,6 +215,8 @@ function docker-get-image-version-and-pull() {
203215
fi
204216

205217
echo "${name}:${version}"
218+
219+
return 0
206220
}
207221

208222
# ==============================================================================
@@ -218,6 +232,8 @@ function _create-effective-dockerfile() {
218232
cp "${dir}/Dockerfile" "${dir}/Dockerfile.effective"
219233
_replace-image-latest-by-specific-version
220234
_append-metadata
235+
236+
return 0
221237
}
222238

223239
# Replace image:latest by a specific version.
@@ -258,6 +274,8 @@ function _replace-image-latest-by-specific-version() {
258274

259275
# Do not ignore the issue if 'latest' is used in the effective image
260276
sed -Ei "/# hadolint ignore=DL3007$/d" "${dir}/Dockerfile.effective"
277+
278+
return 0
261279
}
262280

263281
# Append metadata to the end of Dockerfile.
@@ -272,6 +290,8 @@ function _append-metadata() {
272290
"$(git rev-parse --show-toplevel)/scripts/docker/Dockerfile.metadata" \
273291
> "$dir/Dockerfile.effective.tmp"
274292
mv "$dir/Dockerfile.effective.tmp" "$dir/Dockerfile.effective"
293+
294+
return 0
275295
}
276296

277297
# Print top Docker image version.
@@ -282,6 +302,8 @@ function _get-effective-version() {
282302
local dir=${dir:-$PWD}
283303

284304
head -n 1 "${dir}/.version" 2> /dev/null ||:
305+
306+
return 0
285307
}
286308

287309
# Print all Docker image versions.
@@ -292,6 +314,8 @@ function _get-all-effective-versions() {
292314
local dir=${dir:-$PWD}
293315

294316
cat "${dir}/.version" 2> /dev/null ||:
317+
318+
return 0
295319
}
296320

297321
# Print Git branch name. Check the GitHub variables first and then the local Git
@@ -308,6 +332,8 @@ function _get-git-branch-name() {
308332
fi
309333

310334
echo "$branch_name"
335+
336+
return 0
311337
}
312338

313339
# ==============================================================================
@@ -327,6 +353,8 @@ function docker-get-git-version-suffix() {
327353
else
328354
echo "sha-${short_sha}"
329355
fi
356+
357+
return 0
330358
}
331359

332360
# Authenticate Docker with AWS ECR.
@@ -349,6 +377,8 @@ function docker-ecr-login() {
349377
aws ecr get-login-password --region "${AWS_REGION}" | \
350378
docker login --username AWS --password-stdin \
351379
"${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
380+
381+
return 0
352382
}
353383

354384
# Authenticate Docker with GitHub Container Registry.
@@ -374,6 +404,8 @@ function docker-ghcr-login() {
374404

375405
echo "Authenticating Docker with GitHub Container Registry..."
376406
echo "${GITHUB_TOKEN}" | docker login ghcr.io --username "${ghcr_username}" --password-stdin
407+
408+
return 0
377409
}
378410

379411
# Build container image.
@@ -428,6 +460,8 @@ function docker-build-container() {
428460
.
429461

430462
cd "$current_dir"
463+
464+
return 0
431465
}
432466

433467
# Push container image to ECR.
@@ -450,6 +484,8 @@ function docker-push-container() {
450484
echo "PUBLISH_CONTAINER_IMAGE is false. Skipping push."
451485
echo "Built image is available locally as: ${DOCKER_IMAGE}"
452486
fi
487+
488+
return 0
453489
}
454490

455491
# Calculate and print Docker image name for NHS Notify containers.
@@ -480,4 +516,6 @@ function docker-calculate-image-name() {
480516
local image_tag="${CONTAINER_IMAGE_PREFIX}-${container_name}"
481517
local ecr_repo_uri="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ecr_repo}"
482518
echo "${ecr_repo_uri}:${image_tag}-${image_suffix}"
519+
520+
return 0
483521
}

scripts/docker/dockerfile-linter.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function main() {
2727
else
2828
file="$file" run-hadolint-in-docker
2929
fi
30+
31+
return 0
3032
}
3133

3234
# Run hadolint natively.
@@ -36,6 +38,8 @@ function run-hadolint-natively() {
3638

3739
# shellcheck disable=SC2001
3840
hadolint "$(echo "$file" | sed "s#$PWD#.#")"
41+
42+
return 0
3943
}
4044

4145
# Run hadolint in a Docker container.
@@ -56,13 +60,16 @@ function run-hadolint-in-docker() {
5660
hadolint \
5761
--config /workdir/scripts/config/hadolint.yaml \
5862
"/workdir/$(echo "$file" | sed "s#$PWD#.#")"
63+
64+
return 0
5965
}
6066

6167
# ==============================================================================
6268

6369
function is-arg-true() {
70+
local arg="$1"
6471

65-
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
72+
if [[ "$arg" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
6673
return 0
6774
else
6875
return 1

scripts/githooks/check-english-usage.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function main() {
5252
else
5353
filter="$filter" run-vale-in-docker
5454
fi
55+
56+
return 0
5557
}
5658

5759
# Run Vale natively.
@@ -63,6 +65,8 @@ function run-vale-natively() {
6365
vale \
6466
--config "$PWD/scripts/config/vale/vale.ini" \
6567
$($filter)
68+
69+
return 0
6670
}
6771

6872
# Run Vale in a Docker container.
@@ -86,13 +90,16 @@ function run-vale-in-docker() {
8690
"$image" \
8791
--config /workdir/scripts/config/vale/vale.ini \
8892
$($filter) /dev/null
93+
94+
return 0
8995
}
9096

9197
# ==============================================================================
9298

9399
function is-arg-true() {
100+
local arg="$1"
94101

95-
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
102+
if [[ "$arg" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
96103
return 0
97104
else
98105
return 1

0 commit comments

Comments
 (0)