Skip to content

Commit 8ff2aae

Browse files
guimardclaude
andcommitted
Fix ShellCheck warnings in enrollment script
- Declare and assign variables separately (SC2155) - Quote command substitutions to prevent word splitting (SC2046) - Rename 'hostname' and 'error' variables to avoid confusion 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 66b26df commit 8ff2aae

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

scripts/llng-pam-enroll

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ initiate_device_auth() {
259259
local response
260260
local http_code
261261

262-
response=$(curl $(curl_opts) -w "\n%{http_code}" \
262+
local curl_options
263+
curl_options=$(curl_opts)
264+
response=$(curl $curl_options -w "\n%{http_code}" \
263265
-X POST "${PORTAL_URL}/oauth2/device" \
264266
-d "client_id=${CLIENT_ID}" \
265267
-d "scope=${SCOPE}" 2>&1) || {
@@ -322,13 +324,16 @@ display_instructions() {
322324
poll_for_token() {
323325
log_step "Waiting for administrator approval"
324326

325-
local start_time=$(date +%s)
327+
local start_time
328+
start_time=$(date +%s)
326329
local end_time=$((start_time + TIMEOUT))
327330
local response
328331
local error
329332
local access_token
333+
local now
330334

331-
while [ $(date +%s) -lt $end_time ]; do
335+
now=$(date +%s)
336+
while [ "$now" -lt $end_time ]; do
332337
# Show progress
333338
local elapsed=$(($(date +%s) - start_time))
334339
local remaining=$((TIMEOUT - elapsed))
@@ -339,7 +344,9 @@ poll_for_token() {
339344

340345
sleep "$POLL_INTERVAL"
341346

342-
response=$(curl $(curl_opts) \
347+
local curl_options
348+
curl_options=$(curl_opts)
349+
response=$(curl $curl_options \
343350
-X POST "${PORTAL_URL}/oauth2/token" \
344351
-d "grant_type=urn:ietf:params:oauth:grant-type:device_code" \
345352
-d "device_code=${DEVICE_CODE}" \
@@ -384,6 +391,7 @@ poll_for_token() {
384391
fi
385392
;;
386393
esac
394+
now=$(date +%s)
387395
done
388396

389397
echo ""
@@ -396,7 +404,8 @@ poll_for_token() {
396404
save_token() {
397405
log_step "Saving server token"
398406

399-
local token_dir=$(dirname "$TOKEN_FILE")
407+
local token_dir
408+
token_dir=$(dirname "$TOKEN_FILE")
400409

401410
# Create directory if needed
402411
if [ ! -d "$token_dir" ]; then
@@ -429,7 +438,8 @@ save_token() {
429438
update_config() {
430439
if [ -f "$CONFIG_FILE" ] && [ "$(id -u)" = "0" ]; then
431440
# Check if server_group is already set
432-
local current_group=$(read_config "server_group" "$CONFIG_FILE")
441+
local current_group
442+
current_group=$(read_config "server_group" "$CONFIG_FILE")
433443

434444
if [ -z "$current_group" ] && [ "$SERVER_GROUP" != "default" ]; then
435445
log_info "Adding server_group to $CONFIG_FILE"
@@ -439,7 +449,8 @@ update_config() {
439449
fi
440450

441451
# Ensure token_file is set
442-
local current_token_file=$(read_config "server_token_file" "$CONFIG_FILE")
452+
local current_token_file
453+
current_token_file=$(read_config "server_token_file" "$CONFIG_FILE")
443454
if [ -z "$current_token_file" ]; then
444455
current_token_file=$(read_config "token_file" "$CONFIG_FILE")
445456
fi
@@ -456,27 +467,32 @@ verify_enrollment() {
456467
log_step "Verifying enrollment"
457468

458469
local response
459-
local hostname=$(hostname -f 2>/dev/null || hostname)
470+
local the_hostname
471+
the_hostname=$(hostname -f 2>/dev/null || hostname)
460472

461473
# Try to call /pam/authorize to verify the token works
462-
response=$(curl $(curl_opts) \
474+
local curl_options
475+
curl_options=$(curl_opts)
476+
response=$(curl $curl_options \
463477
-X POST "${PORTAL_URL}/pam/authorize" \
464478
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
465479
-H "Content-Type: application/json" \
466-
-d "{\"user\": \"__test__\", \"host\": \"${hostname}\", \"server_group\": \"${SERVER_GROUP}\"}" 2>&1) || {
480+
-d "{\"user\": \"__test__\", \"host\": \"${the_hostname}\", \"server_group\": \"${SERVER_GROUP}\"}" 2>&1) || {
467481
log_warn "Could not verify enrollment (this may be normal)"
468482
return 0
469483
}
470484

471485
# Check if we got a valid response (even if user not found)
472-
local authorized=$(echo "$response" | jq -r '.authorized // empty' 2>/dev/null)
486+
local authorized
487+
authorized=$(echo "$response" | jq -r '.authorized // empty' 2>/dev/null)
473488

474489
if [ "$authorized" = "true" ] || [ "$authorized" = "false" ]; then
475490
log_success "Server successfully enrolled and verified"
476491
else
477-
local error=$(echo "$response" | jq -r '.error // empty' 2>/dev/null)
478-
if [ -n "$error" ]; then
479-
log_warn "Verification returned error: $error"
492+
local err
493+
err=$(echo "$response" | jq -r '.error // empty' 2>/dev/null)
494+
if [ -n "$err" ]; then
495+
log_warn "Verification returned error: $err"
480496
fi
481497
fi
482498
}

0 commit comments

Comments
 (0)