@@ -133,7 +133,7 @@ function iam_create_user() {
133133 # bashsupport disable=BP5008
134134 function usage() {
135135 echo " function iam_create_user"
136- echo " Creates an WS Identity and Access Management (IAM) user. You must supply a username:"
136+ echo " Creates an AWS Identity and Access Management (IAM) user. You must supply a username:"
137137 echo " -u user_name The name of the user. It must be unique within the account."
138138 echo " "
139139 }
@@ -663,7 +663,7 @@ function iam_delete_policy() {
663663 # bashsupport disable=BP5008
664664 function usage() {
665665 echo " function iam_delete_policy"
666- echo " Deletes an WS Identity and Access Management (IAM) policy"
666+ echo " Deletes an AWS Identity and Access Management (IAM) policy"
667667 echo " -n policy_arn -- The name of the IAM policy arn."
668668 echo " "
669669 }
@@ -733,7 +733,7 @@ function iam_delete_role() {
733733 # bashsupport disable=BP5008
734734 function usage() {
735735 echo " function iam_delete_role"
736- echo " Deletes an WS Identity and Access Management (IAM) role"
736+ echo " Deletes an AWS Identity and Access Management (IAM) role"
737737 echo " -n role_name -- The name of the IAM role."
738738 echo " "
739739 }
@@ -784,6 +784,123 @@ function iam_delete_role() {
784784}
785785# snippet-end:[aws-cli.bash-linux.iam.DeleteRole]
786786
787+ # snippet-start:[aws-cli.bash-linux.iam.UpdateAccessKey]
788+ # ##############################################################################
789+ # function iam_update_access_key
790+ #
791+ # This function can activate or deactivate an IAM access key for the specified IAM user.
792+ #
793+ # Parameters:
794+ # -u user_name -- The name of the user.
795+ # -k access_key -- The access key to update.
796+ # -a -- Activate the selected access key.
797+ # -d -- Deactivate the selected access key.
798+ #
799+ # Example:
800+ # # To deactivate the selected access key for IAM user Bob
801+ # iam_update_access_key -u Bob -k AKIAIOSFODNN7EXAMPLE -d
802+ #
803+ # Returns:
804+ # 0 - If successful.
805+ # 1 - If it fails.
806+ # ##############################################################################
807+ function iam_update_access_key() {
808+ local user_name access_key status response
809+ local option OPTARG # Required to use getopts command in a function.
810+ local activate_flag=false deactivate_flag=false
811+
812+ # bashsupport disable=BP5008
813+ function usage() {
814+ echo " function iam_update_access_key"
815+ echo " Updates the status of an AWS Identity and Access Management (IAM) access key for the specified IAM user"
816+ echo " -u user_name The name of the user."
817+ echo " -k access_key The access key to update."
818+ echo " -a Activate the access key."
819+ echo " -d Deactivate the access key."
820+ echo " "
821+ }
822+
823+ # Retrieve the calling parameters.
824+ while getopts " u:k:adh" option; do
825+ case " ${option} " in
826+ u) user_name=" ${OPTARG} " ;;
827+ k) access_key=" ${OPTARG} " ;;
828+ a) activate_flag=true ;;
829+ d) deactivate_flag=true ;;
830+ h)
831+ usage
832+ return 0
833+ ;;
834+ \? )
835+ echo " Invalid parameter"
836+ usage
837+ return 1
838+ ;;
839+ esac
840+ done
841+ export OPTIND=1
842+
843+ # Validate input parameters
844+ if [[ -z " $user_name " ]]; then
845+ errecho " ERROR: You must provide a username with the -u parameter."
846+ usage
847+ return 1
848+ fi
849+
850+ if [[ -z " $access_key " ]]; then
851+ errecho " ERROR: You must provide an access key with the -k parameter."
852+ usage
853+ return 1
854+ fi
855+
856+ # Ensure that only -a or -d is specified
857+ if [[ " $activate_flag " == true && " $deactivate_flag " == true ]]; then
858+ errecho " ERROR: You cannot specify both -a (activate) and -d (deactivate) at the same time."
859+ usage
860+ return 1
861+ fi
862+
863+ # If neither -a nor -d is provided, return an error
864+ if [[ " $activate_flag " == false && " $deactivate_flag " == false ]]; then
865+ errecho " ERROR: You must specify either -a (activate) or -d (deactivate)."
866+ usage
867+ return 1
868+ fi
869+
870+ # Determine the status based on the flag
871+ if [[ " $activate_flag " == true ]]; then
872+ status=" Active"
873+ elif [[ " $deactivate_flag " == true ]]; then
874+ status=" Inactive"
875+ fi
876+
877+ iecho " Parameters:\n"
878+ iecho " Username: $user_name "
879+ iecho " Access key: $access_key "
880+ iecho " New status: $status "
881+ iecho " "
882+
883+ # Update the access key status
884+ response=$( aws iam update-access-key \
885+ --user-name " $user_name " \
886+ --access-key-id " $access_key " \
887+ --status " $status " 2>&1 )
888+
889+ local error_code=${?}
890+
891+ if [[ $error_code -ne 0 ]]; then
892+ aws_cli_error_log $error_code
893+ errecho " ERROR: AWS reports update-access-key operation failed.\n$response "
894+ return 1
895+ fi
896+
897+ iecho " update-access-key response: $response "
898+ iecho
899+
900+ return 0
901+ }
902+ # snippet-end:[aws-cli.bash-linux.iam.UpdateAccessKey]
903+
787904# snippet-start:[aws-cli.bash-linux.iam.DeleteAccessKey]
788905# ##############################################################################
789906# function iam_delete_access_key
@@ -805,7 +922,7 @@ function iam_delete_access_key() {
805922 # bashsupport disable=BP5008
806923 function usage() {
807924 echo " function iam_delete_access_key"
808- echo " Deletes an WS Identity and Access Management (IAM) access key for the specified IAM user"
925+ echo " Deletes an AWS Identity and Access Management (IAM) access key for the specified IAM user"
809926 echo " -u user_name The name of the user."
810927 echo " -k access_key The access key to delete."
811928 echo " "
@@ -885,7 +1002,7 @@ function iam_delete_user() {
8851002 # bashsupport disable=BP5008
8861003 function usage() {
8871004 echo " function iam_delete_user"
888- echo " Deletes an WS Identity and Access Management (IAM) user. You must supply a username:"
1005+ echo " Deletes an AWS Identity and Access Management (IAM) user. You must supply a username:"
8891006 echo " -u user_name The name of the user."
8901007 echo " "
8911008 }
0 commit comments