Skip to content

Commit 9e952dd

Browse files
📝 Add docstrings to general-improvements-and-typo-fixes
Docstrings generation was requested by @RoseSecurity. * #980 (comment) The following files were modified: * `rootfs/etc/profile.d/aws.sh` * `rootfs/etc/profile.d/fzf.sh` * `rootfs/etc/profile.d/prompt.sh` * `rootfs/templates/wrapper-body.sh`
1 parent 5020c07 commit 9e952dd

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

rootfs/etc/profile.d/aws.sh

100755100644
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export AWS_REGION_ABBREVIATION_TYPE=${AWS_REGION_ABBREVIATION_TYPE:-fixed}
77
export AWS_DEFAULT_SHORT_REGION=${AWS_DEFAULT_SHORT_REGION:-$(aws-region --"${AWS_REGION_ABBREVIATION_TYPE}" "${AWS_DEFAULT_REGION:-us-west-2}")}
88
export GEODESIC_AWS_HOME
99

10+
# _aws_config_home locates or creates the AWS configuration directory, exports GEODESIC_AWS_HOME (and may set AWS_CONFIG_FILE), ensures the directory and config file exist with secure permissions, and returns 1 on failure to create a usable directory.
1011
function _aws_config_home() {
1112
for dir in "${GEODESIC_AWS_HOME}" "${LOCAL_HOME}/.aws" "${HOME}/.aws"; do
1213
if [ -d "${dir}" ]; then
@@ -80,7 +81,7 @@ function aws_choose_role() {
8081
}
8182

8283
# Usage: aws_sdk_assume_role <role> [command...]
83-
# If no command is given, a subshell is started with the role.
84+
# aws_sdk_assume_role sets ASSUME_ROLE and AWS_PROFILE to the specified role (or an interactively chosen role if none specified) and either launches a login subshell that preserves shell history or executes a given command with that profile, then restores the previous ASSUME_ROLE.
8485
function aws_sdk_assume_role() {
8586
local role=$1
8687
shift
@@ -108,7 +109,12 @@ function aws_sdk_assume_role() {
108109
}
109110

110111
# Asks AWS what the currently active identity is and
111-
# sets environment variables accordingly
112+
# export_current_aws_role sets ASSUME_ROLE to reflect the currently active AWS identity.
113+
# It inspects the current STS caller identity and the active profile (AWS_PROFILE or AWS_VAULT),
114+
# attempts to map the active ARN to a more descriptive profile name by consulting the AWS config
115+
# and credentials files (handling normal IAM roles and Identity Center/SSO roles), warns and
116+
# exports a redacted marker when the environment profile disagrees with the active identity,
117+
# and unsets ASSUME_ROLE and returns when no identity can be determined.
112118
function export_current_aws_role() {
113119
local role_name role_names
114120
# Could be a primary or assumed role. If we have assumed a role, cut off the session name.
@@ -251,7 +257,9 @@ function export_current_aws_role() {
251257

252258
# Keep track of AWS credentials and updates to AWS role environment variables.
253259
# When changes are noticed, update prompt with current role.
254-
unset GEODESIC_AWS_ROLE_CACHE # clear out value inherited from supershell
260+
unset GEODESIC_AWS_ROLE_CACHE # refresh_current_aws_role_if_needed checks whether the active AWS role context has changed and updates cached state if necessary.
261+
#
262+
# It computes a fingerprint from the exported AWS_PROFILE, the modification time of the shared credentials file, and AWS_ACCESS_KEY_ID; if the fingerprint differs from GEODESIC_AWS_ROLE_CACHE it calls export_current_aws_role and updates GEODESIC_AWS_ROLE_CACHE with the new fingerprint.
255263
function refresh_current_aws_role_if_needed() {
256264
local is_exported="^declare -[^ x]*x[^ x]* "
257265
local aws_profile=$(declare -p AWS_PROFILE 2>/dev/null)
@@ -268,4 +276,4 @@ function refresh_current_aws_role_if_needed() {
268276
# so only use refresh_current_aws_role_if_needed if they are disabled or overridden
269277
if [[ ($AWS_OKTA_ENABLED != "true" && ${AWS_VAULT_ENABLED:-false} != "true") || -n $AWS_PROFILE ]]; then
270278
PROMPT_HOOKS+=("refresh_current_aws_role_if_needed")
271-
fi
279+
fi

rootfs/etc/profile.d/fzf.sh

100755100644
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ fi
1010

1111
# A lot of terminals (including Apple's) do not support 24-bit color and the mapping from 24-bit to 8-bit is horrible.
1212
# So most of the color schemes are limited to the 256 ANSI colors that nearly every terminal supports.
13-
# Color schemes that only render properly with 24_bit color support are suffixed with _24
13+
# _set_fzf_default_opts builds and exports FZF_DEFAULT_OPTS based on the given color scheme.
14+
# The first argument selects the color scheme (e.g., solar_24, solarized_dark, solarized_light, mild, dark, light, 16, bw); when omitted or unrecognized, a mild/default palette is used.
1415

1516
function _set_fzf_default_opts() {
1617
local gray1="232"
@@ -75,4 +76,4 @@ _set_fzf_default_opts "$FZF_COLORS"
7576
# Requires fzf v0.18.0 or later
7677
if [[ $PROMPT_STYLE == plain && ! $FZF_DEFAULT_OPTS =~ --no-unicode ]]; then
7778
FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS:+${FZF_DEFAULT_OPTS} }--no-unicode"
78-
fi
79+
fi

rootfs/etc/profile.d/prompt.sh

100755100644
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function reload() {
6363
# Define our own prompt
6464
PROMPT_HOOKS+=("geodesic_prompt")
6565
KUBE_PS1_SYMBOL_ENABLE=${KUBE_PS1_SYMBOL_ENABLE:-false}
66+
# geodesic_prompt Constructs and installs the interactive shell prompt (PS1) using configured style, role, secrets, Terraform and Kubernetes state, and optional banner.
67+
#
68+
# geodesic_prompt selects glyphs and marks based on PROMPT_STYLE (plain, unicode, fancy, or default), computes a level indicator from SHLVL, and sets status/role indicators based on ASSUME_ROLE.
69+
# It detects active secret environment variables listed in PROMPT_SECRET_ENVS and appends an indicator if any are set, integrates Terraform prompt lines when GEODESIC_TF_PROMPT_ACTIVE is enabled, and adapts the kube prompt prefix for KUBE_PS1.
70+
# The final PS1 includes an optional BANNER line (with namespace when configured) followed by the directory/host/role segment and prompt glyphs; when no BANNER is defined, PS1 contains only the Terraform and directory segments.
6671
function geodesic_prompt() {
6772

6873
case $PROMPT_STYLE in
@@ -211,4 +216,4 @@ function geodesic_prompt_style() {
211216
unset PROMPT_STYLE
212217
;;
213218
esac
214-
}
219+
}

rootfs/templates/wrapper-body.sh

100755100644
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,12 @@ function _running_shell_pids() {
264264
debug_and_run --noerr docker exec "${DOCKER_NAME}" list-wrapper-shells
265265
}
266266

267+
# _our_shell_pid prints the wrapper shell PID inside the container for the current WRAPPER_PID.
267268
function _our_shell_pid() {
268269
debug_and_run --noerr docker exec "${DOCKER_NAME}" list-wrapper-shells "$WRAPPER_PID" || true
269270
}
270271

272+
# _running_shell_count echoes the number of running shell PIDs detected in the current container.
271273
function _running_shell_count() {
272274
local count
273275
mapfile -t count < <(_running_shell_pids || true)
@@ -285,7 +287,7 @@ function _on_container_exit() {
285287
[ -n "${ON_CONTAINER_EXIT}" ] && command -v "${ON_CONTAINER_EXIT}" >/dev/null && debug_and_run "${ON_CONTAINER_EXIT}"
286288
}
287289

288-
# Call this function to wait for the container to exit, after all other shells have exited.
290+
# wait_for_container_exit waits for the Docker container to exit after other shells have terminated, triggers appropriate exit hooks, and prints guidance or forces termination if the container remains running.
289291
function wait_for_container_exit() {
290292
local i n shells
291293
n=15
@@ -320,6 +322,7 @@ function wait_for_container_exit() {
320322
fi
321323
}
322324

325+
# run_exit_hooks coordinates shutdown after the terminal detaches: it waits for other interactive shells (if any), reports status to the user, and invokes container- and shell-exit hooks while waiting for the container to terminate.
323326
function run_exit_hooks() {
324327
# This runs as soon as the terminal is detached. It may take moments for the shell to actually exit.
325328
# It can then take at least a second for the init process to quit.
@@ -653,6 +656,7 @@ function use() {
653656
true
654657
}
655658

659+
# _polite_stop sends SIGTERM to the Docker container matching NAME, waits up to 8 seconds for it to exit, and re-sends SIGTERM (exiting with code 138) if the container does not stop.
656660
_polite_stop() {
657661
name="$1"
658662
[ -n "$name" ] || return 1
@@ -676,6 +680,7 @@ _polite_stop() {
676680
return 138
677681
}
678682

683+
# stop stops a running geodesic container: if a container name is provided as the first target it requests a graceful shutdown of that container; otherwise it finds containers matching DOCKER_NAME and stops the single match, reports none found, or returns an error when multiple matches exist.
679684
function stop() {
680685
exec 1>&2
681686
name=${targets[1]}
@@ -711,4 +716,4 @@ elif [ -z "${targets[0]}" ] || [ "${targets[0]}" = "use" ]; then
711716
use "${targets[@]}"
712717
else
713718
help
714-
fi
719+
fi

0 commit comments

Comments
 (0)