Skip to content

Commit a78e1f0

Browse files
committed
Allowed it to support an AWS Secret.
1 parent b62a96c commit a78e1f0

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

Management-Utilities/Workload-Factory-API-Samples/fsxn_credentials_set

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ usage() {
1717
1818
This script is used to set the credentials for an FSxN file system.
1919
20-
usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_ID -r aws_region -f filesystem_ID -u user_ID -p password
20+
usage: $(basename $0) -t refresh_token -a blueXP_account_ID -c credentials_ID -r aws_region -f filesystem_ID -u user_ID -p password -s secret_arn
2121
2222
Where: refresh_token - Is a refresh token used to obtain an access token needed
2323
to run the Workload Factory APIs. You can obtain a refresh
@@ -29,8 +29,12 @@ Where: refresh_token - Is a refresh token used to obtain an access token needed
2929
credentials you have access to.
3030
aws_region - Is the AWS region where the file system is located.
3131
filesystem_ID - Is the ID of the FSxN file system.
32-
user_ID - Is the user ID to set for the FSxN file system.
33-
password - Is the password to set for the FSxN file system.
32+
user_ID* - Is the user ID to set for the FSxN file system.
33+
password* - Is the password to set for the FSxN file system.
34+
secret_arn* - Is the ARN of the Secrets Manager secret that contains the
35+
credentials for the FSxN file system.
36+
37+
*NOTE: Only user_id and password OR secret_arn can be be provided at the same time.
3438
3539
Instead of passing parameters on the command line, you can set the
3640
following environment variables:
@@ -71,7 +75,7 @@ fi
7175
. "$wf_utils"
7276
#
7377
# Process command line options.
74-
while getopts "ht:a:c:r:f:u:p:" opt; do
78+
while getopts "ht:a:c:r:f:u:p:s:" opt; do
7579
case $opt in
7680
t) REFRESH_TOKEN="$OPTARG" ;;
7781
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
@@ -80,6 +84,7 @@ while getopts "ht:a:c:r:f:u:p:" opt; do
8084
f) FILESYSTEM_ID="$OPTARG" ;;
8185
u) USER_ID="$OPTARG" ;;
8286
p) PASSWORD="$OPTARG" ;;
87+
s) SECRET_ARN="$OPTARG" ;;
8388
*) usage ;;
8489
esac
8590
done
@@ -96,10 +101,16 @@ You can get a list of credentials by running the "list_credentials" script
96101
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples\n\n'
97102
required_options["AWS_REGION"]='Error: The AWS region where the file system is located is required.\n\n'
98103
required_options["FILESYSTEM_ID"]='Error: The ID of the FSxN file system is required.\n\n'
99-
required_options["USER_ID"]='Error: The user ID to set for the FSxN file system is required.\n\n'
100-
required_options["PASSWORD"]='Error: The password to set for the FSxN file system is required.\n\n'
101104

102105
check_required_options
106+
107+
if [ -n "$USER_ID" -a -n "$PASSWORD" -a -n "$SECRET_ARN" ]; then
108+
echo "Error: You can only provide either user_id and password OR secret_arn at the same time." >&2
109+
usage
110+
elif [ -z "$USER_ID" -a -z "$PASSWORD" -a -z "$SECRET_ARN" ]; then
111+
echo "Error: You must provide either user_id and password OR secret_arn." >&2
112+
usage
113+
fi
103114
#
104115
# Check that the required commands are available.
105116
for cmd in jq curl; do
@@ -115,4 +126,9 @@ if [ -z "$token" ]; then
115126
echo "Error: Failed to obtain an access token. Exiting." >&2
116127
exit 1
117128
fi
118-
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/ontap-credentials" "$tmpout" "$tmperr" '{"user":"'${USER_ID}'","password":"'${PASSWORD}'","resetFsxAdminPassword":false}'
129+
130+
if [ -n "$SECRET_ARN" ]; then
131+
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/ontap-credentials" "$tmpout" "$tmperr" '{"secret":"'${SECRET_ARN}'"}'
132+
else
133+
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/credentials/${CREDENTIALS_ID}/regions/${AWS_REGION}/file-systems/${FILESYSTEM_ID}/ontap-credentials" "$tmpout" "$tmperr" '{"user":"'${USER_ID}'","password":"'${PASSWORD}'","resetFsxAdminPassword":false}'
134+
fi

0 commit comments

Comments
 (0)