Last active
September 4, 2024 14:27
-
-
Save robindiddams/6c019f3b5408c2d5d3564ae61800c28b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# brew install gum | |
sdmreq() { | |
trap 'return 1' SIGINT | |
output=$(sdm access catalog) | |
array=() | |
# Check if output contains the expected header line | |
if [[ $output =~ ^ID.*Name.*Healthy.*Type.*Authentication.*Access.*Tags ]]; then | |
# Extract lines starting from the second line (excluding header) | |
while IFS= read -r line; do | |
# Extract resource ID and name from each line | |
local resource_id=$(echo "$line" | awk '{print $1}') | |
local resource_name=$(echo "$line" | awk '{print $2}') | |
# printf "$resource_name $resource_id\n" | |
array+=("$resource_name $resource_id") | |
done <<< "$(echo "$output" | tail -n +2)" | |
else | |
echo "Error: Unexpected output format from 'sdm access catalog' command." >&2 | |
return 1 | |
fi | |
choice=`gum choose "${array[@]}"` | |
if [ -z "$choice" ]; then | |
return 1 | |
fi | |
resourceId=$(echo "$choice" | awk '{print $2}') | |
resourceName=$(echo "$choice" | awk '{print $1}') | |
reason=$(gum input --value "I need access so that I can ") | |
if [ -z "$reason" ]; then | |
return 1 | |
fi | |
echo $resourceId | |
if [ -z "$resourceId" ]; then | |
echo "No resource selected" | |
return 1 | |
fi | |
duration=$(gum input --prompt "duration: " --placeholder "eg. 2h" --value 4h) | |
sdm access to $resourceId --duration $duration --reason "$reason" | |
echo "Requested!\n\tsdm connect $resourceName" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@robindiddams ^