Skip to content

Commit ca62926

Browse files
committed
Fixed more sonar issues
1 parent b02ab0c commit ca62926

10 files changed

Lines changed: 76 additions & 70 deletions

File tree

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
set -e
3636

37+
readonly GH_ACCEPT_HEADER="Accept: application/vnd.github+json"
38+
readonly GH_API_VERSION_HEADER="X-GitHub-Api-Version: 2022-11-28"
39+
3740
usage() {
3841
cat >&2 <<'EOF'
3942
Usage:
@@ -171,16 +174,16 @@ signature=$(
171174
JWT="${header_payload}"."${signature}"
172175

173176
INSTALLATION_ID=$(curl -X GET \
174-
-H "Accept: application/vnd.github+json" \
177+
-H "${GH_ACCEPT_HEADER}" \
175178
-H "Authorization: Bearer ${JWT}" \
176-
-H "X-GitHub-Api-Version: 2022-11-28" \
179+
-H "${GH_API_VERSION_HEADER}" \
177180
--url "https://api.github.com/app/installations" | jq -r '.[0].id')
178181

179182
PR_TRIGGER_PAT=$(curl --request POST \
180183
--url "https://api.github.com/app/installations/${INSTALLATION_ID}/access_tokens" \
181-
-H "Accept: application/vnd.github+json" \
184+
-H "${GH_ACCEPT_HEADER}" \
182185
-H "Authorization: Bearer ${JWT}" \
183-
-H "X-GitHub-Api-Version: 2022-11-28" | jq -r '.token')
186+
-H "${GH_API_VERSION_HEADER}" | jq -r '.token')
184187

185188
# Set default values if not provided
186189
if [[ -z "$PR_TRIGGER_PAT" ]]; then
@@ -243,9 +246,9 @@ echo "[INFO] Triggering workflow '$targetWorkflow' in nhs-notify-internal..."
243246
trigger_response=$(curl -s -L \
244247
--fail \
245248
-X POST \
246-
-H "Accept: application/vnd.github+json" \
249+
-H "${GH_ACCEPT_HEADER}" \
247250
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \
248-
-H "X-GitHub-Api-Version: 2022-11-28" \
251+
-H "${GH_API_VERSION_HEADER}" \
249252
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/$targetWorkflow/dispatches" \
250253
-d "$DISPATCH_EVENT" 2>&1)
251254

@@ -264,9 +267,9 @@ workflow_run_url=""
264267
for _ in {1..18}; do
265268

266269
response=$(curl -s -L \
267-
-H "Accept: application/vnd.github+json" \
270+
-H "${GH_ACCEPT_HEADER}" \
268271
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \
269-
-H "X-GitHub-Api-Version: 2022-11-28" \
272+
-H "${GH_API_VERSION_HEADER}" \
270273
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch")
271274

272275
if ! echo "$response" | jq empty 2>/dev/null; then
@@ -318,7 +321,7 @@ while true; do
318321
sleep 10
319322
response=$(curl -s -L \
320323
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \
321-
-H "Accept: application/vnd.github+json" \
324+
-H "${GH_ACCEPT_HEADER}" \
322325
"$workflow_run_url")
323326

324327
status=$(echo "$response" | jq -r '.status')

.github/workflows/cicd-3-deploy.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ on:
1818
run-name: "Include prerelease: ${{ inputs.include_prereleases }} Version: ${{ inputs.version }} by @${{ github.actor }}"
1919
permissions:
2020
contents: read
21-
pages: write
22-
id-token: write
2321

2422
jobs:
2523
metadata:
@@ -66,6 +64,10 @@ jobs:
6664
make list-variables
6765
6866
deploy-jekyll:
67+
permissions:
68+
contents: read
69+
pages: write
70+
id-token: write
6971
environment:
7072
name: github-pages
7173
url: ${{ steps.deployment.outputs.page_url }}

docs/assets/js/nhs-notify.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// Quick poc for view full screen
22

3-
window.addEventListener("load", (event) => {
4-
var fullScreenParamName = "fullscreen";
5-
var urlParams = new URLSearchParams(document.location.search);
6-
var param = urlParams.get(fullScreenParamName);
3+
window.addEventListener("load", () => {
4+
const fullScreenParamName = "fullscreen";
5+
const urlParams = new URLSearchParams(document.location.search);
6+
const param = urlParams.get(fullScreenParamName);
77
if (param) {
88
tempViewFullScreen();
99
} else {
1010
setViewAtStart();
1111
}
1212
});
1313

14-
let nhsNotify = nhsNotifyDefaults();
14+
const nhsNotify = nhsNotifyDefaults();
1515

1616
function nhsNotifyDefaults() {
17-
var defaults = {};
17+
const defaults = {};
1818
defaults.storageName = "cb-checked";
1919
defaults.buttonName = "fullScreenButton";
2020
defaults.standard = "Standard";
@@ -24,16 +24,16 @@ function nhsNotifyDefaults() {
2424

2525
function tempViewFullScreen() {
2626
viewFullScreen();
27-
var buttons = document.getElementsByName(nhsNotify.buttonName);
27+
const buttons = document.getElementsByName(nhsNotify.buttonName);
2828
buttons.forEach((item) => {
2929
item.style.display = "none";
3030
});
3131
}
3232

3333
function viewFullScreen() {
34-
var sideBar = document.getElementsByClassName("side-bar")[0];
35-
var main = document.getElementsByClassName("main")[0];
36-
var pageInfo = document.getElementsByClassName("page-info")[0];
34+
const sideBar = document.getElementsByClassName("side-bar")[0];
35+
const main = document.getElementsByClassName("main")[0];
36+
const pageInfo = document.getElementsByClassName("page-info")[0];
3737
sideBar.style.display = "none";
3838
main.style.maxWidth = "100%";
3939
main.style.marginLeft = "0px";
@@ -45,9 +45,9 @@ function setFullScreen() {
4545
}
4646

4747
function setStandard() {
48-
var sideBar = document.getElementsByClassName("side-bar")[0];
49-
var main = document.getElementsByClassName("main")[0];
50-
var pageInfo = document.getElementsByClassName("page-info")[0];
48+
const sideBar = document.getElementsByClassName("side-bar")[0];
49+
const main = document.getElementsByClassName("main")[0];
50+
const pageInfo = document.getElementsByClassName("page-info")[0];
5151
sideBar.style.display = "";
5252
main.style.maxWidth = "";
5353
main.style.marginLeft = "";
@@ -56,7 +56,7 @@ function setStandard() {
5656
}
5757

5858
function setViewAtStart() {
59-
var currentStatus = localStorage.getItem(nhsNotify.storageName);
59+
const currentStatus = localStorage.getItem(nhsNotify.storageName);
6060
if (currentStatus == nhsNotify.fullScreen) makeChange(currentStatus);
6161
}
6262

@@ -69,41 +69,27 @@ function makeChange(newStatus) {
6969
}
7070

7171
function afterChange(currentStatus, newStatus) {
72-
var storageName = nhsNotify.storageName;
73-
var buttonName = nhsNotify.buttonName;
74-
var buttons = document.getElementsByName(buttonName);
75-
localStorage.setItem(storageName, newStatus);
72+
const buttons = document.getElementsByName(nhsNotify.buttonName);
73+
localStorage.setItem(nhsNotify.storageName, newStatus);
7674

7775
buttons.forEach((item) => {
7876
item.textContent = currentStatus + " View";
7977
});
8078
}
8179

8280
function fullScreenToggle() {
83-
var standard = nhsNotify.standard;
84-
var fullScreen = nhsNotify.fullScreen;
85-
var storageName = nhsNotify.storageName;
86-
var currentStatus = "";
87-
var newStatus = "";
88-
89-
currentStatus = localStorage.getItem(storageName);
81+
const { standard, fullScreen, storageName } = nhsNotify;
82+
let currentStatus = localStorage.getItem(storageName);
9083

9184
if (
9285
currentStatus == "false" ||
9386
currentStatus == "undefined" ||
9487
currentStatus == null
9588
) {
9689
currentStatus = standard;
97-
newStatus = fullScreen;
9890
}
9991

100-
if (currentStatus == standard) {
101-
newStatus = fullScreen;
102-
currentStatus = standard;
103-
} else {
104-
newStatus = standard;
105-
currentStatus = fullScreen;
106-
}
92+
const newStatus = currentStatus == standard ? fullScreen : standard;
10793

10894
makeChange(newStatus);
10995
}

scripts/docker/dgoss.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ info() {
1818
return 0
1919
}
2020
error() {
21-
echo -e "ERROR: $*" >&2;
21+
local message="$*";
22+
echo -e "ERROR: $message" >&2;
2223
exit 1;
2324
}
2425

@@ -98,7 +99,8 @@ GOSS_SLEEP=${GOSS_SLEEP:-0.2}
9899

99100
[[ $CONTAINER_RUNTIME =~ ^(docker|podman)$ ]] || { error "Runtime must be one of docker or podman"; }
100101

101-
case "$1" in
102+
readonly command="$1"
103+
case "$command" in
102104
run)
103105
run "$@"
104106
if [[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]]; then

scripts/docker/docker.lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function docker-get-image-version-and-pull() {
189189
local version="latest"
190190
if [[ -f "$versions_file" ]]; then
191191
line=$(grep "docker/${name} " "$versions_file" | sed "s/^#\s*//; s/\s*#.*$//" | grep "${match_version:-".*"}")
192-
[ -n "$line" ] && version=$(echo "$line" | awk '{print $2}')
192+
[[ -n "$line" ]] && version=$(echo "$line" | awk '{print $2}')
193193
fi
194194

195195
# Split the image version into two, tag name and digest sha256.
@@ -250,7 +250,7 @@ function _replace-image-latest-by-specific-version() {
250250
# First, list the entries specific for Docker to take precedence, then the rest but exclude comments
251251
content=$(grep " docker/" "$versions_file"; grep -v " docker/" "$versions_file" ||: | grep -v "^#")
252252
echo "$content" | while IFS= read -r line; do
253-
[ -z "$line" ] && continue
253+
[[ -z "$line" ]] && continue
254254
line=$(echo "$line" | sed "s/^#\s*//; s/\s*#.*$//" | sed "s;docker/;;")
255255
name=$(echo "$line" | awk '{print $1}')
256256
version=$(echo "$line" | awk '{print $2}')

scripts/githooks/check-markdown-format.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function main() {
4949
"branch")
5050
files="$( (git diff --diff-filter=ACMRT --name-only "${BRANCH_NAME:-origin/main}" "*.md"; git diff --name-only "*.md") | sort | uniq )"
5151
;;
52+
*)
53+
echo "Unknown check mode: $check" >&2
54+
return 1
55+
;;
5256
esac
5357

5458
if [[ -n "$files" ]] && command -v markdownlint > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then

scripts/githooks/scan-secrets.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ function get-cmd-to-run() {
5454
"staged-changes")
5555
cmd="protect --source $dir --verbose --staged"
5656
;;
57+
*)
58+
echo "Unknown check mode: $check" >&2
59+
return 1
60+
;;
5761
esac
5862
# Include base line file if it exists
5963
if [[ -f "$dir/scripts/config/.gitleaks-baseline.json" ]]; then

scripts/shellscript-linter.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function main() {
2121

2222
cd "$(git rev-parse --show-toplevel)"
2323

24-
[ -z "${file:-}" ] && echo "WARNING: 'file' variable not set, defaulting to itself"
24+
[[ -z "${file:-}" ]] && echo "WARNING: 'file' variable not set, defaulting to itself"
2525
local file=${file:-scripts/shellscript-linter.sh}
2626
if command -v shellcheck > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
2727
file="$file" run-shellcheck-natively

scripts/terraform/terraform.sh

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

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

3739
# shellcheck disable=SC2086
3840
terraform $cmd
41+
42+
return 0
3943
}
4044

4145
# Run Terraform in a Docker container.
@@ -54,13 +58,16 @@ function run-terraform-in-docker() {
5458
--workdir /workdir \
5559
"$image" \
5660
$cmd
61+
62+
return 0
5763
}
5864

5965
# ==============================================================================
6066

6167
function is-arg-true() {
68+
local arg="$1"
6269

63-
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
70+
if [[ "$arg" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
6471
return 0
6572
else
6673
return 1

scripts/terraform/trivy-scan.sh

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,36 @@ function main() {
2828
local dir_to_scan="."
2929

3030
while [[ $# -gt 0 ]]; do
31-
local current_arg="$1"
32-
case "$current_arg" in
31+
local arg="$1"
32+
case "$arg" in
3333
--mode|-m)
3434
if [[ $# -lt 2 ]]; then
3535
echo "Error: --mode requires an argument." >&2
3636
usage
3737
exit 1
3838
fi
39-
local mode_arg="$2"
40-
scan_mode="$mode_arg"
39+
scan_mode="$2"
4140
shift 2
42-
exit 0
43-
;;
44-
--)
45-
shift
46-
break
47-
;;
48-
-*)
4941
;;
50-
usage
51-
exit 1
52-
;;
53-
*)
54-
dir_to_scan="$current_arg"
55-
shift
5642
--help|-h)
57-
dir_to_scan="$trailing_arg"
43+
usage
44+
exit 0
45+
;;
46+
--)
47+
shift
48+
break
49+
;;
50+
-*)
51+
echo "Unknown option: $arg" >&2
52+
usage
53+
exit 1
54+
;;
55+
*)
56+
dir_to_scan="$arg"
5857
shift
5958
;;
6059
esac
61-
local trailing_arg="$1"
62-
dir_to_scan="$trailing_arg"
60+
done
6361

6462
if [[ $# -gt 0 ]]; then
6563
dir_to_scan="$1"

0 commit comments

Comments
 (0)