diff --git a/.doc_gen/metadata/medical-imaging_metadata.yaml b/.doc_gen/metadata/medical-imaging_metadata.yaml new file mode 100644 index 00000000000..613c0b96d7d --- /dev/null +++ b/.doc_gen/metadata/medical-imaging_metadata.yaml @@ -0,0 +1,73 @@ +# zexi 0.4.0 +medical-imaging_CreateDatastore: + title: Create a data store using the &AHI; SDK + title_abbrev: Create a data store + synopsis: create a data store. + category: + languages: + Bash: + versions: + - sdk_version: 2 + github: aws-cli/bash-linux/medical-imaging + sdkguide: + excerpts: + - description: + snippet_tags: + - aws-cli.bash-linux.medical-imaging.errecho + - aws-cli.bash-linux.medical-imaging.CreateDatastore + services: + medical-imaging: {CreateDatastore} +medical-imaging_DeleteDatastore: + title: Delete a data store using the &AHI; SDK + title_abbrev: Delete a data store + synopsis: delete a data store. + category: + languages: + Bash: + versions: + - sdk_version: 2 + github: aws-cli/bash-linux/medical-imaging + sdkguide: + excerpts: + - description: + snippet_tags: + - aws-cli.bash-linux.medical-imaging.errecho + - aws-cli.bash-linux.medical-imaging.DeleteDatastore + services: + medical-imaging: {DeleteDatastore} +medical-imaging_ListDatastores: + title: List a data stores using the &AHI; SDK + title_abbrev: List data stores + synopsis: list a data stores. + category: + languages: + Bash: + versions: + - sdk_version: 2 + github: aws-cli/bash-linux/medical-imaging + sdkguide: + excerpts: + - description: + snippet_tags: + - aws-cli.bash-linux.medical-imaging.errecho + - aws-cli.bash-linux.medical-imaging.ListDatastores + services: + medical-imaging: {ListDatastores} +medical-imaging_GetDatastore: + title: Get data store properties using the &AHI; SDK + title_abbrev: Get data store properties + synopsis: get data store properties. + category: + languages: + Bash: + versions: + - sdk_version: 2 + github: aws-cli/bash-linux/medical-imaging + sdkguide: + excerpts: + - description: + snippet_tags: + - aws-cli.bash-linux.medical-imaging.errecho + - aws-cli.bash-linux.medical-imaging.GetDatastore + services: + medical-imaging: {GetDatastore} diff --git a/.doc_gen/metadata/services.yaml b/.doc_gen/metadata/services.yaml index bb9c5bca0a0..d30df4bf9d2 100644 --- a/.doc_gen/metadata/services.yaml +++ b/.doc_gen/metadata/services.yaml @@ -670,6 +670,21 @@ mediapackage: tags: product_categories: {'Media Services'} version: mediapackage-2017-10-12 +medical-imaging: + long: '&AHIlong;' + short: '&AHI;' + sort: HealthImaging + expanded: + long: AWS HealthImaging + short: HealthImaging + blurb: is a HIPAA-eligible service that helps health care providers and their medical imaging ISV partners store, transform, and apply machine learning to medical images. + guide: + subtitle: User Guide + url: healthimaging/latest/devguide/what-is.html + api_ref: healthimaging/latest/APIReference/Welcome.html + tags: + product_categories: {'Machine Learning'} + version: medical-imaging-2023-07-19 migration-hub: long: '&MHBlong;' short: '&MHB;' diff --git a/aws-cli/README.md b/aws-cli/README.md index 66dedb510dd..283e27f15fb 100644 --- a/aws-cli/README.md +++ b/aws-cli/README.md @@ -25,19 +25,24 @@ To run these examples, you'll need: ## Running the examples Examples are typically written as functions in shell script files that can be -sourced from other files. Most are accompanied by a unit or integration test -script that you can run to validate that each example works. The test scripts -include setup and teardown to create and destroy any prerequisite resources. -We take care that all AWS resources that the example creates are also destroyed -to avoid incurring any unwanted costs. When you're done with an example, we do -recommend that you check the resources in your account to ensure that the +sourced from other files. When you're done with an example, we do +recommend that you check the resources in your account to ensure that the teardown worked as expected and didn't accidentally leave any resources behind. -To run the examples, you need to create a shared credentials file. For more -information about how to set up a shared credentials file, see [Configuration +To run the examples, you need to create a shared credentials file. For more +information about how to set up a shared credentials file, see [Configuration and Credential File Settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) in the _AWS CLI User Guide_. +### Tests + +Most examples are accompanied by a unit or integration test +script that you can run to validate that each example works. The test scripts +include setup and teardown to create and destroy any prerequisite resources. +We take care that all AWS resources that the example creates are also destroyed +to avoid incurring any unwanted costs. + + ## AWS CLI downloads For information about how to download and install the AWS CLI, see [Installing diff --git a/aws-cli/bash-linux/README.md b/aws-cli/bash-linux/README.md index db5e621db89..fc2ff26a5e4 100644 --- a/aws-cli/bash-linux/README.md +++ b/aws-cli/bash-linux/README.md @@ -27,11 +27,7 @@ To run these examples, you need: ## Running the examples Examples are typically written as functions in shell script files that can be -sourced from other files. Most are accompanied by a unit or integration test -script that you can run to validate that each example works. The test scripts -include setup and teardown to create and destroy any prerequisite resources. -We take care that all AWS resources that the example creates are also destroyed -to avoid incurring any unwanted costs. When you're done with an example, we do +sourced from other files. When you're done with an example, we do recommend that you check the resources in your account to ensure that the teardown worked as expected and didn't accidentally leave any resources behind. @@ -40,6 +36,14 @@ information about how to set up a shared credentials file, see [Configuration and Credential File Settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) in the _AWS CLI User Guide_. +### Tests + +Most examples are accompanied by a unit or integration test +script that you can run to validate that each example works. The test scripts +include setup and teardown to create and destroy any prerequisite resources. +We take care that all AWS resources that the example creates are also destroyed +to avoid incurring any unwanted costs. + ## AWS CLI downloads For information about how to download and install the AWS CLI, see [Installing diff --git a/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh b/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh index a571d22b420..c73cda3dded 100755 --- a/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh +++ b/aws-cli/bash-linux/iam/iam_create_user_assume_role_scenario.sh @@ -288,7 +288,7 @@ function sts_assume_role() { --role-session-name "$role_session_name" \ --role-arn "$role_arn" \ --output text \ - --query "Credentials.{AccessKeyId: AccessKeyId ,SecretAccessKey: SecretAccessKey ,SessionToken: SessionToken}") + --query "Credentials.[AccessKeyId, SecretAccessKey, SessionToken]") local error_code=${?} @@ -358,8 +358,7 @@ function iam_create_user_assume_role() { return 1 fi - # shellcheck disable=SC2206 - local access_key_values=($access_key_response) # Convert to array. + IFS=$'\t ' read -r -a access_key_values <<<"$access_key_response" local key_name=${access_key_values[0]} local key_secret=${access_key_values[1]} @@ -492,8 +491,7 @@ function iam_create_user_assume_role() { return 1 fi - # shellcheck disable=SC2206 - credentials=(${credentials}) # Convert to array. + IFS=$'\t ' read -r -a credentials <<<"$credentials" export AWS_ACCESS_KEY_ID=${credentials[0]} export AWS_SECRET_ACCESS_KEY=${credentials[1]} diff --git a/aws-cli/bash-linux/iam/tests/test_iam_examples.sh b/aws-cli/bash-linux/iam/tests/test_iam_examples.sh index 72f82c7a516..486321b4d90 100755 --- a/aws-cli/bash-linux/iam/tests/test_iam_examples.sh +++ b/aws-cli/bash-linux/iam/tests/test_iam_examples.sh @@ -18,9 +18,6 @@ ############################################################################### # Set default values. -# bashsupport disable=BP5001 -INTERACTIVE=false -VERBOSE=false ############################################################################### # function main @@ -28,6 +25,11 @@ VERBOSE=false # This function runs the IAM examples' tests. ############################################################################### function main() { + # bashsupport disable=BP2001 + export INTERACTIVE=false + # bashsupport disable=BP2001 + export VERBOSE=false + source ./test_general.sh { local current_directory @@ -125,8 +127,8 @@ function main() { 0 test_count=$((test_count + 1)) - # shellcheck disable=SC2206 - local user_values=($test_command_response) + local user_values + IFS=$'\t ' read -r -a user_values <<<"$test_command_response" if [[ "${#user_values[@]}" -lt "2" ]]; then test_failed "Listing users returned less than 2 users." fi @@ -152,9 +154,8 @@ function main() { "iam_create_user_access_key -u $user_name " \ 0 test_count=$((test_count + 1)) - - # shellcheck disable=SC2206 - local access_key_values=($test_command_response) + local access_key_values + IFS=$'\t ' read -r -a access_key_values <<<"$test_command_response" local key_name2=${access_key_values[0]} run_test "$test_count. Listing access keys without user" \ @@ -166,8 +167,8 @@ function main() { "iam_list_access_keys -u $user_name " \ 0 test_count=$((test_count + 1)) - # shellcheck disable=SC2206 - local access_key_values=($test_command_response) + + IFS=$'\t ' read -r -a access_key_values <<<"$test_command_response" if [[ "${#access_key_values[@]}" -ne "2" ]]; then test_failed "Listing access keys returned incorrect number of keys." fi @@ -258,7 +259,7 @@ function main() { test_count=$((test_count + 1)) # bashsupport disable=BP2001 - mock_input="True" + export mock_input="True" # bashsupport disable=BP2001 export mock_input_array=("iamtestcli_scenario") diff --git a/aws-cli/bash-linux/medical-imaging/README.md b/aws-cli/bash-linux/medical-imaging/README.md new file mode 100644 index 00000000000..97dc467fdc2 --- /dev/null +++ b/aws-cli/bash-linux/medical-imaging/README.md @@ -0,0 +1,78 @@ + +# HealthImaging code examples for the Command Line Interface with Bash script + +## Overview + +Shows how to use the AWS Command Line Interface with Bash script to work with AWS HealthImaging. + + + + +*HealthImaging is a HIPAA-eligible service that helps health care providers and their medical imaging ISV partners store, transform, and apply machine learning to medical images.* + +## ⚠ Important + +* Running this code might result in charges to your AWS account. +* Running the tests might result in charges to your AWS account. +* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege). +* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). + + + + +## Code examples + +### Prerequisites + +For prerequisites, see the [README](../../README.md#Prerequisites) in the `aws-cli` folder. + + + + + +### Single actions + +Code excerpts that show you how to call individual service functions. + +* [Create a data store](medical_imaging_operations.sh#L22) (`CreateDatastore`) +* [Delete a data store](medical_imaging_operations.sh#L267) (`DeleteDatastore`) +* [Get data store properties](medical_imaging_operations.sh#L196) (`GetDatastore`) +* [List data stores](medical_imaging_operations.sh#L91) (`ListDatastores`) + +## Run the examples + +### Instructions + + + + + + + +### Tests + +⚠ Running tests might result in charges to your AWS account. + + +To find instructions for running these tests, see the [README](../../README.md#Tests) +in the `aws-cli` folder. + + + + + + +## Additional resources + +* [HealthImaging User Guide](https://docs.aws.amazon.com/healthimaging/latest/devguide/what-is.html) +* [HealthImaging API Reference](https://docs.aws.amazon.com/healthimaging/latest/APIReference/Welcome.html) +* [Command Line Interface with Bash script HealthImaging reference](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/medical-imaging/index.html) + + + + +--- + +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/aws-cli/bash-linux/medical-imaging/awsdocs_general.sh b/aws-cli/bash-linux/medical-imaging/awsdocs_general.sh new file mode 100644 index 00000000000..68faf524a08 --- /dev/null +++ b/aws-cli/bash-linux/medical-imaging/awsdocs_general.sh @@ -0,0 +1,133 @@ +#!/bin/bash +#bashsupport disable=BP5001 + +################################################################################ +## +## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +## SPDX-License-Identifier: Apache-2.0 +## +################################################################################ + +################################################################################ +## +## Before running this AWS CLI example, set up your development environment, including your credentials. +## +## For more information, see the following documentation topic: +## +## https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +## +################################################################################ +# +############################################################################## +# +# This script contains general purpose functions that are used throughout +# the AWS Command Line Interface (AWS CLI) code samples that are maintained +# in the repo at https://github.com/awsdocs/aws-doc-sdk-examples +# +# Set global defaults: +# bashsupport disable=BP5006 +VERBOSE=false + +# snippet-start:[aws-cli.bash-linux.medical-imaging.errecho] +############################################################################### +# function errecho +# +# This function outputs everything sent to it to STDERR (standard error output). +############################################################################### +function errecho() { + printf "%s\n" "$*" 2>&1 +} +# snippet-end:[aws-cli.bash-linux.medical-imaging.errecho] + +# snippet-start:[aws-cli.bash-linux.medical-imaging.iecho] +############################################################################### +# function iecho +# +# This function enables the script to display the specified text only if +# the global variable $VERBOSE is set to true. +############################################################################### +function iecho() { + if [[ $VERBOSE == true ]]; then + echo "$@" + fi +} +# snippet-end:[aws-cli.bash-linux.medical-imaging.iecho] + +############################################################################### +# function ipause +# +# This function enables the script to pause after each command if interactive +# mode is set (by including -i on the script invocation command). +############################################################################### +function ipause() { + if [[ $INTERACTIVE == true ]]; then + read -r -p "Press ENTER to continue..." + fi +} + +# Initialize the shell's RANDOM variable. +RANDOM=$$ +############################################################################### +# function generate_random_name +# +# This function generates a random file name with using the specified root +# followed by 4 groups that each have 4 digits. +# The default root name is "test". +function generate_random_name() { + + local rootname="test" + if [[ -n $1 ]]; then + rootname=$1 + fi + + # Initialize the filename variable. + local filename="$rootname" + # Configure random number generator to issue numbers between 1000 and 9999, inclusive. + local diff + diff=$((9999 - 1000 + 1)) + + # bashsupport disable=BP2001 + for _ in {1..4}; do + local rnd + rnd=$(($((RANDOM % diff)) + X)) + # Make sure that the number is 4 digits long. + while [ "${#rnd}" -lt 4 ]; do rnd="0$rnd"; done + filename+="-$rnd" + done + echo "$filename" +} + +############################################################################## +# function aws_cli_error_log() +# +# This function is used to log the error messages from the AWS CLI. +# +# The function expects the following argument: +# $1 - The error code returned by the AWS CLI. +# +# Returns: +# 0: - Success. +# +############################################################################## +function aws_cli_error_log() { + local err_code=$1 + errecho "Error code : $err_code" + if [ "$err_code" == 1 ]; then + errecho " One or more S3 transfers failed." + elif [ "$err_code" == 2 ]; then + errecho " Command line failed to parse." + elif [ "$err_code" == 130 ]; then + errecho " Process received SIGINT." + elif [ "$err_code" == 252 ]; then + errecho " Command syntax invalid." + elif [ "$err_code" == 253 ]; then + errecho " The system environment or configuration was invalid." + elif [ "$err_code" == 254 ]; then + errecho " The service returned an error." + elif [ "$err_code" == 255 ]; then + errecho " 255 is a catch-all error." + fi + + return 0 + +} diff --git a/aws-cli/bash-linux/medical-imaging/medical_imaging_operations.sh b/aws-cli/bash-linux/medical-imaging/medical_imaging_operations.sh new file mode 100644 index 00000000000..7db18a889ce --- /dev/null +++ b/aws-cli/bash-linux/medical-imaging/medical_imaging_operations.sh @@ -0,0 +1,279 @@ +#!/bin/bash + +############################################################################## +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +# +############################################################################### + +############################################################################### +# +# Before running this AWS CLI example, set up your development environment, including your credentials. +# +# For more information, see the following documentation topic: +# +# https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +# +############################################################################### + +source ./awsdocs_general.sh + +# snippet-start:[aws-cli.bash-linux.medical-imaging.CreateDatastore] +############################################################################### +# function imaging_create_datastore +# +# This function creates an AWS HealthImaging data store for importing DICOM P10 files. +# +# Parameters: +# -n data_store_name - The name of the data store. +# +# Returns: +# The datastore ID. +# And: +# 0 - If successful. +# 1 - If it fails. +############################################################################### +function imaging_create_datastore() { + local datastore_name response + local option OPTARG # Required to use getopts command in a function. + + # bashsupport disable=BP5008 + function usage() { + echo "function imaging_create_datastore" + echo "Creates an AWS HealthImaging data store for importing DICOM P10 files." + echo " -n data_store_name - The name of the data store." + echo "" + } + + # Retrieve the calling parameters. + while getopts "n:h" option; do + case "${option}" in + n) datastore_name="${OPTARG}" ;; + h) + usage + return 0 + ;; + \?) + echo "Invalid parameter" + usage + return 1 + ;; + esac + done + export OPTIND=1 + + if [[ -z "$datastore_name" ]]; then + errecho "ERROR: You must provide a datastore name with the -n parameter." + usage + return 1 + fi + + response=$(aws medical-imaging create-datastore \ + --datastore-name "$datastore_name" \ + --output text \ + --query 'datastoreId') + + local error_code=${?} + + if [[ $error_code -ne 0 ]]; then + aws_cli_error_log $error_code + errecho "ERROR: AWS reports medical-imaging create-datastore operation failed.$response" + return 1 + fi + + echo "$response" + + return 0 +} +# snippet-end:[aws-cli.bash-linux.medical-imaging.CreateDatastore] + +# snippet-start:[aws-cli.bash-linux.medical-imaging.ListDatastores] +############################################################################### +# function imaging_list_datastores +# +# List the HealthImaging data stores in the account. +# +# Returns: +# [[datastore_name, datastore_id, datastore_status]] +# And: +# 0 - If successful. +# 1 - If it fails. +############################################################################### +function imaging_list_datastores() { + local option OPTARG # Required to use getopts command in a function. + local error_code + # bashsupport disable=BP5008 + function usage() { + echo "function imaging_list_datastores" + echo "Lists the AWS HealthImaging data stores in the account." + echo "" + } + + # Retrieve the calling parameters. + while getopts "h" option; do + case "${option}" in + h) + usage + return 0 + ;; + \?) + echo "Invalid parameter" + usage + return 1 + ;; + esac + done + export OPTIND=1 + + local response + response=$(aws medical-imaging list-datastores \ + --output text \ + --query "datastoreSummaries[*][datastoreName, datastoreId, datastoreStatus]") + error_code=${?} + + if [[ $error_code -ne 0 ]]; then + aws_cli_error_log $error_code + errecho "ERROR: AWS reports list-datastores operation failed.$response" + return 1 + fi + + echo "$response" + + return 0 +} +# snippet-end:[aws-cli.bash-linux.medical-imaging.ListDatastores] + +# snippet-start:[aws-cli.bash-linux.medical-imaging.GetDatastore] +############################################################################### +# function imaging_get_datastore +# +# Get a datastore properties. +# +# Parameters: +# -i data_store_id - The ID of the data store. +# +# Returns: +# [datastore_name, datastore_id, datastore_status, datastore_arn, created_at, updated_at] +# And: +# 0 - If successful. +# 1 - If it fails. +############################################################################### +function imaging_get_datastore() { + local datastore_id option OPTARG # Required to use getopts command in a function. + local error_code + # bashsupport disable=BP5008 + function usage() { + echo "function imaging_get_datastore" + echo "Gets a datastore properties." + echo " -i datastore_id - The ID of the data store." + echo "" + } + + # Retrieve the calling parameters. + while getopts "i:h" option; do + case "${option}" in + i) datastore_id="${OPTARG}" ;; + h) + usage + return 0 + ;; + \?) + echo "Invalid parameter" + usage + return 1 + ;; + esac + done + export OPTIND=1 + + if [[ -z "$datastore_id" ]]; then + errecho "ERROR: You must provide a datastore ID with the -i parameter." + usage + return 1 + fi + + local response + + response=$( + aws medical-imaging get-datastore \ + --datastore-id "$datastore_id" \ + --output text \ + --query "[ datastoreProperties.datastoreName, datastoreProperties.datastoreId, datastoreProperties.datastoreStatus, datastoreProperties.datastoreArn, datastoreProperties.createdAt, datastoreProperties.updatedAt]" + ) + error_code=${?} + + if [[ $error_code -ne 0 ]]; then + aws_cli_error_log $error_code + errecho "ERROR: AWS reports list-datastores operation failed.$response" + return 1 + fi + + echo "$response" + + return 0 +} +# snippet-end:[aws-cli.bash-linux.medical-imaging.GetDatastore] + +# snippet-start:[aws-cli.bash-linux.medical-imaging.DeleteDatastore] +############################################################################### +# function imaging_delete_datastore +# +# This function deletes an AWS HealthImaging data store. +# +# Parameters: +# -i datastore_id - The ID of the data store. +# +# Returns: +# 0 - If successful. +# 1 - If it fails. +############################################################################### +function imaging_delete_datastore() { + local datastore_id response + local option OPTARG # Required to use getopts command in a function. + + # bashsupport disable=BP5008 + function usage() { + echo "function imaging_delete_datastore" + echo "Deletes an AWS HealthImaging data store." + echo " -i datastore_id - The ID of the data store." + echo "" + } + + # Retrieve the calling parameters. + while getopts "i:h" option; do + case "${option}" in + i) datastore_id="${OPTARG}" ;; + h) + usage + return 0 + ;; + \?) + echo "Invalid parameter" + usage + return 1 + ;; + esac + done + export OPTIND=1 + + if [[ -z "$datastore_id" ]]; then + errecho "ERROR: You must provide a datastore ID with the -i parameter." + usage + return 1 + fi + + response=$(aws medical-imaging delete-datastore \ + --datastore-id "$datastore_id") + + local error_code=${?} + + if [[ $error_code -ne 0 ]]; then + aws_cli_error_log $error_code + errecho "ERROR: AWS reports medical-imaging delete-datastore operation failed.$response" + return 1 + fi + + return 0 +} +# snippet-end:[aws-cli.bash-linux.medical-imaging.DeleteDatastore] diff --git a/aws-cli/bash-linux/medical-imaging/tests/test_general.sh b/aws-cli/bash-linux/medical-imaging/tests/test_general.sh new file mode 100644 index 00000000000..d4b96e01e35 --- /dev/null +++ b/aws-cli/bash-linux/medical-imaging/tests/test_general.sh @@ -0,0 +1,90 @@ +#!/bin/bash +#bashsupport disable=BP5001 + +################################################################################ +## +## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +## SPDX-License-Identifier: Apache-2.0 +## +################################################################################ + +################################################################################ +## +## Before running this AWS CLI example, set up your development environment, including your credentials. +## +## For more information, see the following documentation topic: +## +## https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +## +################################################################################ +# +############################################################################## +# +# This script contains general purpose functions that are used for testing +# the AWS Command Line Interface (AWS CLI) code samples that are maintained +# in the repo at https://github.com/awsdocs/aws-doc-sdk-examples +# + +test_command_response="" + +############################################################################### +# function run_test +# +# This function is used to perform a command and compare its output to both +# the expected error code and the expected output string. If there isn't a +# match, then the function invokes the test_failed function. +############################################################################### +function run_test() { + local description command expected_err_code expected_output + + description="$1" + command="$2" + expected_err_code="$3" + if [[ -n "$4" ]]; then expected_output="$4"; else expected_output=""; fi + + iecho -n "Running test: $description..." + test_command_response="$($command)" + local err="${?}" + + # Check to see if we got the expected error code. + if [[ "$expected_err_code" -ne "$err" ]]; then + test_failed "The test \"$description\" returned an unexpected error code: $err" + fi + + # Check the error message, if we provided other than "". + if [[ -n "$expected_output" ]]; then + local match + match=$(echo "$test_command_response" | grep "$expected_output") + # If there was no match (it's an empty string), then fail. + if [[ -z "$match" ]]; then + test_failed "The test \"$description\" returned an unexpected output: $test_command_response" + fi + fi + + iecho "OK" + ipause +} + +############################################################################### +# function test_failed +# +# This function is used to terminate a failed test and to warn the customer +# about possible undeleted resources that could incur costs to their account. +############################################################################### +function test_failed() { + + errecho "" + errecho "===TEST FAILED===" + errecho "$@" + errecho "" + errecho " One or more of the tests failed to complete successfully. If there were any" + errecho " tests after the one that failed, they didn't run. As a result, you might have" + errecho " resources still active in your account." + errecho "" + errecho "IMPORTANT:" + errecho " Resources created by this script can incur charges to your AWS account. If the" + errecho " script did not complete successfully, then you must review and manually delete" + errecho " any resources created by this script that were not automatically removed." + errecho "" + exit 1 +} diff --git a/aws-cli/bash-linux/medical-imaging/tests/test_medical_imaging_examples.sh b/aws-cli/bash-linux/medical-imaging/tests/test_medical_imaging_examples.sh new file mode 100755 index 00000000000..5ae1ed3863e --- /dev/null +++ b/aws-cli/bash-linux/medical-imaging/tests/test_medical_imaging_examples.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +############################################################################### +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +# +############################################################################### + +############################################################################### +# +# Before running this AWS CLI example, set up your development environment, including your credentials. +# +# For more information, see the following documentation topic: +# +# https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +# +############################################################################### + +############################################################################### +# function main +# +# This function runs the IAM examples' tests. +############################################################################### +function main() { +# Set default values. +# bashsupport disable=BP2001 +export INTERACTIVE=false +# bashsupport disable=BP2001 +export VERBOSE=false + + source ./test_general.sh + { + local current_directory + current_directory=$(pwd) + cd .. + source ./medical_imaging_operations.sh + # shellcheck disable=SC2164 + cd "$current_directory" + } + + ############################################################################### + # function usage + # + # This function prints usage information for the script. + ############################################################################### + function usage() { + echo "This script tests Amazon IAM operations in the AWS CLI." + echo "" + echo "To pause the script between steps, so you can see the results in the" + echo "AWS Management Console, include the parameter -i." + echo "" + echo "IMPORTANT: Running this script creates resources in your Amazon" + echo " account that can incur charges. It is your responsibility to" + echo " ensure that no resources are left in your account after the script" + echo " completes. If an error occurs during the operation of the script," + echo " then resources can remain that you might need to delete manually." + } + + local option OPTARG # Required to use getopts command in a function. + + # Retrieve the calling parameters + while getopts "ivh" option; do + case "${option}" in + i) + INTERACTIVE=true + VERBOSE=true + iecho + ;; + v) VERBOSE=true ;; + h) + usage + return 0 + ;; + \?) + echo "Invalid parameter" + usage + return 1 + ;; + esac + done + + if [ "$INTERACTIVE" == "true" ]; then iecho "Tests running in interactive mode."; fi + if [ "$VERBOSE" == "true" ]; then iecho "Tests running in verbose mode."; fi + + iecho "***************SETUP STEPS******************" + local datastore_name + datastore_name=$(generate_random_name iamtestcli) + iecho "datastore_name=$datastore_name" + iecho "**************END OF STEPS******************" + + local test_count=0 + + run_test "$test_count Create a datastore" \ + "imaging_create_datastore -n $datastore_name " \ + 0 + test_count=$((test_count + 1)) + + local datastore_id="$test_command_response" + + run_test "$test_count List datastores" \ + "imaging_list_datastores" \ + 0 + + local datastore_list="$test_command_response" + local data_store_found=false + local line + while IFS=$'\n' read -r line; do + IFS=$'\t' read -ra entries <<<"$line" + if [ "${entries[1]}" == "$datastore_id" ]; then + data_store_found=true + fi + if [ "${#entries[@]}" -ne 3 ]; then + test_failed "Incorrect number of entries in list datastores response. $datastore_list" + fi + done <<<"$datastore_list" + + if [ "$data_store_found" == "false" ]; then + test_failed "Datastore id $datastore_id not found in list datastores response. $datastore_list" + fi + + test_count=$((test_count + 1)) + + run_test "$test_count. Get a datastore" \ + "imaging_get_datastore -i $datastore_id " \ + 0 + + IFS=$'\t' read -ra datastore_get_result <<<"$test_command_response" + if [ "${#datastore_get_result[@]}" -ne 6 ]; then + test_failed "Incorrect number of entries in get datastore response. ${#datastore_get_result[@]}}" + fi + + local retrieved_datastore_id="${datastore_get_result[1]}" + if [ "$retrieved_datastore_id" != "$datastore_id" ]; then + test_failed "Incorrect datastore id in get datastore response. ${#datastore_get_result[@]}" + fi + + test_count=$((test_count + 1)) + + sleep 10 + + run_test "$test_count. Delete a datastore" \ + "imaging_delete_datastore -i $datastore_id " \ + 0 + test_count=$((test_count + 1)) + + echo "$test_count tests completed successfully." +} + +main