Created
March 13, 2024 16:50
-
-
Save robindiddams/6c019f3b5408c2d5d3564ae61800c28b to your computer and use it in GitHub Desktop.
This file contains 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 () { | |
output=$(sdm access catalog) | |
array=() | |
if [[ $output =~ ^ID.*Name.*Healthy.*Type.*Authentication.*Access.*Tags ]] | |
then | |
while IFS= read -r line | |
do | |
local resource_id=$(echo "$line" | awk '{print $1}') | |
local resource_name=$(echo "$line" | awk '{print $2}') | |
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}') | |
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 | |
sdm access to $resourceId --duration 2h --reason "$reason" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here are some suggestions for improving it:
Here's an improved version of your script incorporating these suggestions:
Please replace the comments with actual usage scenarios or integrate it into your script where appropriate. Also, make sure to test thoroughly after making changes.