From 9b5f253589d1da9538f4613f95500d0275798947 Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 7 Feb 2024 14:29:07 -0500 Subject: [PATCH 1/7] add apigateway files --- .gitignore | 5 + kotlin/services/apigateway/build.gradle.kts | 27 ++++- .../src/test/kotlin/APIGatewayTest.kt | 111 ++++++++++++++++++ 3 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 kotlin/services/apigateway/src/test/kotlin/APIGatewayTest.kt diff --git a/.gitignore b/.gitignore index f56bd3d387c..03662deba31 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,8 @@ rust_dev_preview .vectors # .snippets are created temporarily as build artifacts .snippets +# Ignore build-related files and directories in kotlin/services/ +kotlin/services/**/build/ +kotlin/services/**/gradle/ +kotlin/services/**/gradlew +kotlin/services/**/gradlew.bat \ No newline at end of file diff --git a/kotlin/services/apigateway/build.gradle.kts b/kotlin/services/apigateway/build.gradle.kts index 2a147b0cb15..c66333f8a15 100644 --- a/kotlin/services/apigateway/build.gradle.kts +++ b/kotlin/services/apigateway/build.gradle.kts @@ -1,13 +1,18 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.7.10" + kotlin("jvm") version "1.9.0" application } group = "me.scmacdon" version = "1.0-SNAPSHOT" +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + buildscript { repositories { maven("https://plugins.gradle.org/m2/") @@ -19,18 +24,28 @@ buildscript { repositories { mavenCentral() - jcenter() } apply(plugin = "org.jlleitschuh.gradle.ktlint") dependencies { - implementation("aws.sdk.kotlin:apigateway:1.0.0") - implementation("aws.sdk.kotlin:secretsmanager:1.0.0") + implementation("aws.sdk.kotlin:apigateway:1.0.30") + implementation("aws.sdk.kotlin:secretsmanager:1.0.30") implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0") implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0") - implementation("com.google.code.gson:gson:2.10") testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") + implementation("com.fasterxml.jackson.core:jackson-databind:2.14.2") + implementation("com.google.code.gson:gson:2.10") } tasks.withType() { - kotlinOptions.jvmTarget = "1.8" + kotlinOptions.jvmTarget = "17" +} +tasks.test { + useJUnitPlatform() + testLogging { + events("passed", "skipped", "failed") + } + + // Define the test source set + testClassesDirs += files("build/classes/kotlin/test") + classpath += files("build/classes/kotlin/main", "build/resources/main") } diff --git a/kotlin/services/apigateway/src/test/kotlin/APIGatewayTest.kt b/kotlin/services/apigateway/src/test/kotlin/APIGatewayTest.kt new file mode 100644 index 00000000000..a2b260bac7f --- /dev/null +++ b/kotlin/services/apigateway/src/test/kotlin/APIGatewayTest.kt @@ -0,0 +1,111 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider +import aws.sdk.kotlin.services.apigateway.ApiGatewayClient +import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient +import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest +import com.google.gson.Gson +import com.kotlin.gateway.createAPI +import com.kotlin.gateway.deleteAPI +import com.kotlin.gateway.getAllDeployments +import com.kotlin.gateway.getAllStages +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Order +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.TestMethodOrder +import java.util.Random + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestMethodOrder(OrderAnnotation::class) +class APIGatewayTest { + lateinit var apiGatewayClient: ApiGatewayClient + private var restApiId = "" + private var httpMethod = "" + private var restApiName = "" + private var stageName = "" + private var newApiId = "" + + @BeforeAll + fun setup() = runBlocking { + apiGatewayClient = ApiGatewayClient { region = "us-east-1" } + // Get values from AWS Secrets Manager. + val random = Random() + val randomNum = random.nextInt(10000 - 1 + 1) + 1 + val gson = Gson() + val json: String = getSecretValues() + val values: SecretValues = gson.fromJson(json, SecretValues::class.java) + restApiId = values.restApiId.toString() + httpMethod = values.httpMethod.toString() + restApiName = values.restApiName.toString() + randomNum + stageName = values.stageName.toString() + + /* + val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties") + val prop = Properties() + + // load the properties file. + prop.load(input) + + // Populate the data members required for all tests + restApiId = prop.getProperty("restApiId") + resourceId = prop.getProperty("resourceId") + httpMethod = prop.getProperty("httpMethod") + restApiName = prop.getProperty("restApiName") + stageName = prop.getProperty("stageName") + */ + } + + @Test + @Order(1) + fun createRestApiTest() = runBlocking { + newApiId = createAPI(restApiId).toString() + println("Test 2 passed") + } + + @Test + @Order(2) + fun getDeploymentsTest() = runBlocking { + getAllDeployments(newApiId) + println("Test 4 passed") + } + + @Test + @Order(3) + fun getAllStagesTest() = runBlocking { + getAllStages(newApiId) + println("Test 5 passed") + } + + @Test + @Order(4) + fun DeleteRestApi() = runBlocking { + deleteAPI(newApiId) + println("Test 6 passed") + } + + private suspend fun getSecretValues(): String { + val secretName = "test/apigateway" + val valueRequest = GetSecretValueRequest { + secretId = secretName + } + SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> + val valueResponse = secretClient.getSecretValue(valueRequest) + return valueResponse.secretString.toString() + } + } + + @Nested + @DisplayName("A class used to get test values from test/apigateway (an AWS Secrets Manager secret)") + internal class SecretValues { + val restApiId: String? = null + val restApiName: String? = null + val httpMethod: String? = null + val stageName: String? = null + } +} From 26dff882e5fee63ed23334c88add0b3e25712f3a Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 7 Feb 2024 14:38:34 -0500 Subject: [PATCH 2/7] add appsync files --- kotlin/services/appsync/build.gradle.kts | 8 +- .../appsync/src/test/kotlin/AppSyncTest.kt | 83 ++++++++++++------- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/kotlin/services/appsync/build.gradle.kts b/kotlin/services/appsync/build.gradle.kts index ac30a9be3b5..878516357f1 100644 --- a/kotlin/services/appsync/build.gradle.kts +++ b/kotlin/services/appsync/build.gradle.kts @@ -27,10 +27,10 @@ repositories { } apply(plugin = "org.jlleitschuh.gradle.ktlint") dependencies { - implementation("aws.sdk.kotlin:appsync:1.0.0") - implementation("aws.sdk.kotlin:sts:1.0.0") - implementation("aws.sdk.kotlin:s3:1.0.0") - implementation("aws.sdk.kotlin:secretsmanager:1.0.0") + implementation("aws.sdk.kotlin:appsync:1.0.30") + implementation("aws.sdk.kotlin:sts:1.0.30") + implementation("aws.sdk.kotlin:s3:1.0.30") + implementation("aws.sdk.kotlin:secretsmanager:1.0.30") implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0") implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0") implementation("com.google.code.gson:gson:2.10") diff --git a/kotlin/services/appsync/src/test/kotlin/AppSyncTest.kt b/kotlin/services/appsync/src/test/kotlin/AppSyncTest.kt index 0ca358bdfa5..e7f6968f309 100644 --- a/kotlin/services/appsync/src/test/kotlin/AppSyncTest.kt +++ b/kotlin/services/appsync/src/test/kotlin/AppSyncTest.kt @@ -1,37 +1,49 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider +import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient +import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest import com.example.appsync.createDS import com.example.appsync.createKey import com.example.appsync.deleteDS import com.example.appsync.deleteKey import com.example.appsync.getDS import com.example.appsync.getKeys +import com.google.gson.Gson import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.MethodOrderer.OrderAnnotation +import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Order import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestMethodOrder -import java.io.InputStream -import java.util.Properties @TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestMethodOrder(OrderAnnotation::class) class AppSyncTest { - private var apiId = "" private var dsName = "" private var dsRole = "" private var tableName = "" - private var keyId = "" // gets dynamically set in a test. - private var dsARN = "" // gets dynamically set in a test. + private var keyId = "" @BeforeAll - fun setup() { + fun setup() = runBlocking { + // Get test values from AWS Secrets Manager. + val gson = Gson() + val json = getSecretValues() + val values = gson.fromJson(json, SecretValues::class.java) + apiId = values.apiId.toString() + dsName = values.dsName.toString() + dsRole = values.dsRole.toString() + tableName = values.tableName.toString() + // Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests. + /* val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties") val prop = Properties() prop.load(input) @@ -39,68 +51,79 @@ class AppSyncTest { dsName = prop.getProperty("dsName") dsRole = prop.getProperty("dsRole") tableName = prop.getProperty("tableName") + */ } @Test @Order(1) - fun whenInitializingAWSService_thenNotNull() = runBlocking { - assertTrue(!apiId.isEmpty()) - assertTrue(!dsName.isEmpty()) - assertTrue(!dsRole.isEmpty()) - assertTrue(!tableName.isEmpty()) - println("Test 1 passed") - } - - @Test - @Order(2) fun CreateApiKey() = runBlocking { keyId = createKey(apiId).toString() assertTrue(!keyId.isEmpty()) - println("Test 2 passed") + println("Test 1 passed") } @Test - @Order(3) + @Order(2) fun CreateDataSource() = runBlocking { val dsARN = createDS(dsName, dsRole, apiId, tableName) if (dsARN != null) { - assertTrue(!dsARN.isEmpty()) + assertTrue(dsARN.isNotEmpty()) } - println("Test 3 passed") + println("Test 2 passed") } @Test - @Order(4) + @Order(3) fun GetDataSource() = runBlocking { getDS(apiId, dsName) - println("Test 4 passed") + println("Test 3 passed") } @Test - @Order(5) + @Order(4) fun ListGraphqlApis() = runBlocking { getKeys(apiId) - println("Test 5 passed") + println("Test 4 passed") } @Test - @Order(6) + @Order(5) fun ListApiKeys() = runBlocking { getKeys(apiId) - println("Test 6 passed") + println("Test 5 passed") } @Test - @Order(7) + @Order(6) fun DeleteDataSource() = runBlocking { deleteDS(apiId, dsName) - println("Test 7 passed") + println("Test 6 passed") } @Test - @Order(8) + @Order(7) fun DeleteApiKey() = runBlocking { deleteKey(keyId, apiId) - println("Test 8 passed") + println("Test 7 passed") + } + + private suspend fun getSecretValues(): String { + val secretName = "test/appsync" + val valueRequest = GetSecretValueRequest { + secretId = secretName + } + SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> + val valueResponse = secretClient.getSecretValue(valueRequest) + return valueResponse.secretString.toString() + } + } + + @Nested + @DisplayName("A class used to get test values from test/appsync (an AWS Secrets Manager secret)") + internal class SecretValues { + val apiId: String? = null + val dsName: String? = null + val dsRole: String? = null + val tableName: String? = null } } From 650c4fa88fe06845db691a089844f81ff68a9285 Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 7 Feb 2024 15:06:46 -0500 Subject: [PATCH 3/7] add athena files --- kotlin/services/athena/build.gradle.kts | 4 +- .../athena/src/test/kotlin/AthenaTest.kt | 115 ++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 kotlin/services/athena/src/test/kotlin/AthenaTest.kt diff --git a/kotlin/services/athena/build.gradle.kts b/kotlin/services/athena/build.gradle.kts index d9fba68e052..cbf32c6fb55 100644 --- a/kotlin/services/athena/build.gradle.kts +++ b/kotlin/services/athena/build.gradle.kts @@ -27,8 +27,8 @@ repositories { } apply(plugin = "org.jlleitschuh.gradle.ktlint") dependencies { - implementation("aws.sdk.kotlin:athena:1.0.0") - implementation("aws.sdk.kotlin:secretsmanager:1.0.0") + implementation("aws.sdk.kotlin:athena:1.0.30") + implementation("aws.sdk.kotlin:secretsmanager:1.0.30") implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0") implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0") implementation("com.google.code.gson:gson:2.10") diff --git a/kotlin/services/athena/src/test/kotlin/AthenaTest.kt b/kotlin/services/athena/src/test/kotlin/AthenaTest.kt new file mode 100644 index 00000000000..da81967f83e --- /dev/null +++ b/kotlin/services/athena/src/test/kotlin/AthenaTest.kt @@ -0,0 +1,115 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider +import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient +import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest +import com.google.gson.Gson +import com.kotlin.athena.createNamedQuery +import com.kotlin.athena.deleteQueryName +import com.kotlin.athena.listNamedQueries +import com.kotlin.athena.listQueryIds +import com.kotlin.athena.processResultRows +import com.kotlin.athena.submitAthenaQuery +import com.kotlin.athena.waitForQueryToComplete +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Order +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.TestMethodOrder + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestMethodOrder(OrderAnnotation::class) +class AthenaTest { + private var nameQuery: String? = null + private var queryString: String? = null + private var database: String? = null + private var outputLocation: String? = null + private var queryId: String? = null + + @BeforeAll + fun setup() = runBlocking { + // Get the values from AWS Secrets Manager. + val gson = Gson() + val json = getSecretValues() + val values = gson.fromJson(json, SecretValues::class.java) + nameQuery = values.nameQuery.toString() + queryString = values.queryString.toString() + database = values.database.toString() + outputLocation = values.outputLocation.toString() + + // Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests. + /* + val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties") + val prop = Properties() + prop.load(input) + nameQuery = prop.getProperty("nameQuery") + queryString = prop.getProperty("queryString") + database = prop.getProperty("database") + outputLocation = prop.getProperty("outputLocation") + */ + } + + @Test + @Order(1) + fun createNamedQueryTest() = runBlocking { + queryId = createNamedQuery(queryString.toString(), nameQuery.toString(), database.toString()) + queryId?.let { assertTrue(it.isNotEmpty()) } + println("Test 1 passed") + } + + @Test + @Order(2) + fun listNamedQueryTest() = runBlocking { + listNamedQueries() + println("Test 2 passed") + } + + @Test + @Order(3) + fun listQueryExecutionsTest() = runBlocking { + listQueryIds() + println("Test 3 passed") + } + + @Test + @Order(4) + fun startQueryExampleTest() = runBlocking { + val queryExecutionId = submitAthenaQuery(queryString.toString(), database.toString(), outputLocation.toString()) + waitForQueryToComplete(queryExecutionId) + processResultRows(queryExecutionId) + println("Test 4 passed") + } + + @Test + @Order(5) + fun deleteNamedQueryTest() = runBlocking { + deleteQueryName(queryId) + println("Test 5 passed") + } + + private suspend fun getSecretValues(): String { + val secretName = "test/athena" + val valueRequest = GetSecretValueRequest { + secretId = secretName + } + SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> + val valueResponse = secretClient.getSecretValue(valueRequest) + return valueResponse.secretString.toString() + } + } + + @Nested + @DisplayName("A class used to get test values from test/xray (an AWS Secrets Manager secret)") + internal class SecretValues { + val nameQuery: String? = null + val queryString: String? = null + val outputLocation: String? = null + val database: String? = null + } +} From 620331e22462cc33db75663d1d9aa5f2bf38909d Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 7 Feb 2024 15:15:23 -0500 Subject: [PATCH 4/7] add autoscale files --- kotlin/services/autoscale/build.gradle.kts | 4 +- .../src/test/kotlin/AutoScalingTest.kt | 153 ++++++++++++++++++ 2 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 kotlin/services/autoscale/src/test/kotlin/AutoScalingTest.kt diff --git a/kotlin/services/autoscale/build.gradle.kts b/kotlin/services/autoscale/build.gradle.kts index 8feae498fe5..a566d4ae062 100644 --- a/kotlin/services/autoscale/build.gradle.kts +++ b/kotlin/services/autoscale/build.gradle.kts @@ -27,8 +27,8 @@ repositories { } apply(plugin = "org.jlleitschuh.gradle.ktlint") dependencies { - implementation("aws.sdk.kotlin:autoscaling:1.0.0") - implementation("aws.sdk.kotlin:secretsmanager:1.0.0") + implementation("aws.sdk.kotlin:autoscaling:1.0.30") + implementation("aws.sdk.kotlin:secretsmanager:1.0.30") implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0") implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0") implementation("com.google.code.gson:gson:2.10") diff --git a/kotlin/services/autoscale/src/test/kotlin/AutoScalingTest.kt b/kotlin/services/autoscale/src/test/kotlin/AutoScalingTest.kt new file mode 100644 index 00000000000..422567976e2 --- /dev/null +++ b/kotlin/services/autoscale/src/test/kotlin/AutoScalingTest.kt @@ -0,0 +1,153 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider +import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient +import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest +import com.example.autoscaling.createAutoScalingGroup +import com.example.autoscaling.deleteSpecificAutoScalingGroup +import com.example.autoscaling.describeAccountLimits +import com.example.autoscaling.describeAutoScalingGroups +import com.example.autoscaling.describeAutoScalingInstance +import com.example.autoscaling.describeScalingActivities +import com.example.autoscaling.disableMetricsCollection +import com.example.autoscaling.enableMetricsCollection +import com.example.autoscaling.getAutoScalingGroups +import com.example.autoscaling.getSpecificAutoScaling +import com.example.autoscaling.setDesiredCapacity +import com.example.autoscaling.terminateInstanceInAutoScalingGroup +import com.example.autoscaling.updateAutoScalingGroup +import com.google.gson.Gson +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Order +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.TestMethodOrder +import java.io.IOException +import java.util.Random +import kotlin.system.exitProcess + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestMethodOrder(OrderAnnotation::class) +class AutoScalingTest { + private var groupName = "" + private var groupNameSc = "" + private var launchTemplateName = "" + private var vpcZoneId = "" + private var serviceLinkedRoleARN = "" + + @BeforeAll + @Throws(IOException::class) + fun setUp() = runBlocking { + val random = Random() + val randomNum = random.nextInt(10000 - 1 + 1) + 1 + // Get the values from AWS Secrets Manager. + val gson = Gson() + val json = getSecretValues() + val values = gson.fromJson(json, SecretValues::class.java) + groupName = values.groupName.toString() + randomNum + launchTemplateName = values.launchTemplateName.toString() + vpcZoneId = values.vpcZoneId.toString() + serviceLinkedRoleARN = values.serviceLinkedRoleARN.toString() + groupNameSc = values.groupNameSc.toString() + randomNum + // Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests. + /* + try { + AutoScalingTest::class.java.getClassLoader().getResourceAsStream("config.properties").use { input -> + val prop = Properties() + if (input == null) { + println("Sorry, unable to find config.properties") + return + } + prop.load(input) + groupName = prop.getProperty("groupName") + launchTemplateName = prop.getProperty("launchTemplateName") + subnetId = prop.getProperty("subnetId") + vpcZoneId = "subnet-0ddc451b8a8a1aa44" //prop.getProperty("vpcZoneId") + } + } catch (ex:IOException) { + ex.printStackTrace() + } + */ + } + + @Test + @Order(1) + fun testScenario() = runBlocking { + println("**** Create an Auto Scaling group named $groupName") + createAutoScalingGroup(groupName, launchTemplateName, serviceLinkedRoleARN, vpcZoneId) + + println("Wait 1 min for the resources, including the instance. Otherwise, an empty instance Id is returned") + delay(60000) + + val instanceId = getSpecificAutoScaling(groupName) + if (instanceId.compareTo("") == 0) { + println("Error - no instance Id value") + exitProcess(1) + } else { + println("The instance Id value is $instanceId") + } + + println("**** Describe Auto Scaling with the Id value $instanceId") + describeAutoScalingInstance(instanceId) + + println("**** Enable metrics collection $instanceId") + enableMetricsCollection(groupName) + + println("**** Update an Auto Scaling group to update max size to 3") + updateAutoScalingGroup(groupName, launchTemplateName, serviceLinkedRoleARN) + + println("**** Describe all Auto Scaling groups to show the current state of the groups") + describeAutoScalingGroups(groupName) + + println("**** Describe account details") + describeAccountLimits() + + println("Wait 1 min for the resources, including the instance. Otherwise, an empty instance Id is returned") + delay(60000) + + println("**** Set desired capacity to 2") + setDesiredCapacity(groupName) + + println("**** Get the two instance Id values and state") + getAutoScalingGroups(groupName) + + println("**** List the scaling activities that have occurred for the group") + describeScalingActivities(groupName) + + println("**** Terminate an instance in the Auto Scaling group") + terminateInstanceInAutoScalingGroup(instanceId) + + println("**** Stop the metrics collection") + disableMetricsCollection(groupName) + + println("**** Delete the Auto Scaling group") + deleteSpecificAutoScalingGroup(groupName) + } + + private suspend fun getSecretValues(): String { + val secretName = "test/autoscale" + val valueRequest = GetSecretValueRequest { + secretId = secretName + } + SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> + val valueResponse = secretClient.getSecretValue(valueRequest) + return valueResponse.secretString.toString() + } + } + + @Nested + @DisplayName("A class used to get test values from test/autoscale (an AWS Secrets Manager secret)") + internal class SecretValues { + val groupName: String? = null + val groupNameSc: String? = null + val launchTemplateName: String? = null + val vpcZoneId: String? = null + val serviceLinkedRoleARN: String? = null + } +} From c61bef74d2deec56a8b8afc67f25c3b62a01000f Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 7 Feb 2024 15:20:13 -0500 Subject: [PATCH 5/7] add cloudformation files --- .../services/cloudformation/build.gradle.kts | 4 +- .../src/test/kotlin/CloudFormationTest.kt | 103 ++++++++++++++++++ 2 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 kotlin/services/cloudformation/src/test/kotlin/CloudFormationTest.kt diff --git a/kotlin/services/cloudformation/build.gradle.kts b/kotlin/services/cloudformation/build.gradle.kts index b842f4c3624..bc69f3b9c88 100644 --- a/kotlin/services/cloudformation/build.gradle.kts +++ b/kotlin/services/cloudformation/build.gradle.kts @@ -27,8 +27,8 @@ repositories { } apply(plugin = "org.jlleitschuh.gradle.ktlint") dependencies { - implementation("aws.sdk.kotlin:cloudformation:1.0.0") - implementation("aws.sdk.kotlin:secretsmanager:1.0.0") + implementation("aws.sdk.kotlin:cloudformation:1.0.30") + implementation("aws.sdk.kotlin:secretsmanager:1.0.30") implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0") implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0") implementation("com.google.code.gson:gson:2.10") diff --git a/kotlin/services/cloudformation/src/test/kotlin/CloudFormationTest.kt b/kotlin/services/cloudformation/src/test/kotlin/CloudFormationTest.kt new file mode 100644 index 00000000000..ce01dcf7324 --- /dev/null +++ b/kotlin/services/cloudformation/src/test/kotlin/CloudFormationTest.kt @@ -0,0 +1,103 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider +import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient +import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest +import com.google.gson.Gson +import com.kotlin.cloudformation.createCFStack +import com.kotlin.cloudformation.deleteSpecificTemplate +import com.kotlin.cloudformation.describeAllStacks +import com.kotlin.cloudformation.getSpecificTemplate +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Order +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.TestMethodOrder + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestMethodOrder(OrderAnnotation::class) +class CloudFormationTest { + private var stackName = "" + private var roleARN = "" + private var location = "" + private var key = "" + private var value = "" + + @BeforeAll + fun setup() = runBlocking() { + // Get the values from AWS Secrets Manager. + val gson = Gson() + val json: String = getSecretValues() + val values = gson.fromJson(json, SecretValues::class.java) + stackName = values.stackName.toString() + roleARN = values.roleARN.toString() + location = values.location.toString() + key = values.key.toString() + value = values.value.toString() + + /* + val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties") + val prop = Properties() + prop.load(input) + stackName = prop.getProperty("stackName") + roleARN = prop.getProperty("roleARN") + location = prop.getProperty("location") + key = prop.getProperty("key") + value = prop.getProperty("value") + */ + } + + @Test + @Order(1) + fun createStackTest() = runBlocking { + createCFStack(stackName, roleARN, location, key, value) + println("Test 1 passed") + } + + @Test + @Order(2) + fun describeStacksTest() = runBlocking { + describeAllStacks() + println("Test 2 passed") + } + + @Test + @Order(3) + fun getTemplateTest() = runBlocking { + getSpecificTemplate(stackName) + println("Test 3 passed") + } + + @Test + @Order(4) + fun deleteStackTest() = runBlocking { + deleteSpecificTemplate(stackName) + println("Test 4 passed") + } + + private suspend fun getSecretValues(): String { + val secretName = "test/cloudformation" + val valueRequest = GetSecretValueRequest { + secretId = secretName + } + SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> + val valueResponse = secretClient.getSecretValue(valueRequest) + return valueResponse.secretString.toString() + } + } + + @Nested + @DisplayName("A class used to get test values from test/cloudformation (an AWS Secrets Manager secret)") + internal class SecretValues { + val stackName: String? = null + val roleARN: String? = null + val location: String? = null + val key: String? = null + val value: String? = null + } +} From 964bb649ed7ade3097b07cb57cbd17ee3f93cf5d Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 7 Feb 2024 15:27:33 -0500 Subject: [PATCH 6/7] add cloudtrail files --- kotlin/services/cloudtrail/build.gradle.kts | 4 +- .../src/test/kotlin/CloudtrailKotlinTest.kt | 119 ++++++++++++++++++ 2 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 kotlin/services/cloudtrail/src/test/kotlin/CloudtrailKotlinTest.kt diff --git a/kotlin/services/cloudtrail/build.gradle.kts b/kotlin/services/cloudtrail/build.gradle.kts index 28b4255e46e..619a58cc10b 100644 --- a/kotlin/services/cloudtrail/build.gradle.kts +++ b/kotlin/services/cloudtrail/build.gradle.kts @@ -27,8 +27,8 @@ repositories { } apply(plugin = "org.jlleitschuh.gradle.ktlint") dependencies { - implementation("aws.sdk.kotlin:cloudtrail:1.0.0") - implementation("aws.sdk.kotlin:secretsmanager:1.0.0") + implementation("aws.sdk.kotlin:cloudtrail:1.0.30") + implementation("aws.sdk.kotlin:secretsmanager:1.0.30") implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0") implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0") implementation("com.google.code.gson:gson:2.10") diff --git a/kotlin/services/cloudtrail/src/test/kotlin/CloudtrailKotlinTest.kt b/kotlin/services/cloudtrail/src/test/kotlin/CloudtrailKotlinTest.kt new file mode 100644 index 00000000000..ad82fc600c3 --- /dev/null +++ b/kotlin/services/cloudtrail/src/test/kotlin/CloudtrailKotlinTest.kt @@ -0,0 +1,119 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider +import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient +import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest +import com.google.gson.Gson +import com.kotlin.cloudtrail.createNewTrail +import com.kotlin.cloudtrail.deleteSpecificTrail +import com.kotlin.cloudtrail.describeSpecificTrails +import com.kotlin.cloudtrail.getSelectors +import com.kotlin.cloudtrail.lookupAllEvents +import com.kotlin.cloudtrail.setSelector +import com.kotlin.cloudtrail.startLog +import com.kotlin.cloudtrail.stopLog +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Order +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.TestMethodOrder + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@TestMethodOrder(OrderAnnotation::class) +class CloudtrailKotlinTest { + private var trailName = "" + private var s3BucketName = "" + + @BeforeAll + fun setup() = runBlocking { + val gson = Gson() + val json: String = getSecretValues() + val values: SecretValues = gson.fromJson(json, SecretValues::class.java) + trailName = values.trailName.toString() + s3BucketName = values.s3BucketName.toString() + + // Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests. + /* + val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties") + val prop = Properties() + + // load the properties file. + prop.load(input) + trailName = prop.getProperty("trailName") + s3BucketName = prop.getProperty("s3BucketName") + */ + } + + @Test + @Order(1) + fun createTrail() = runBlocking { + createNewTrail(trailName, s3BucketName) + println("Test 1 passed") + } + + @Test + @Order(2) + fun putEventSelectors() = runBlocking { + setSelector(trailName) + println("Test 2 passed") + } + + @Test + @Order(3) + fun getEventSelectors() = runBlocking { + getSelectors(trailName) + println("Test 3 passed") + } + + @Test + @Order(4) + fun lookupEvents() = runBlocking { + lookupAllEvents() + println("Test 4 passed") + } + + @Test + @Order(5) + fun describeTrails() = runBlocking { + describeSpecificTrails(trailName) + println("Test 5 passed") + } + + @Test + @Order(6) + fun startLogging() = runBlocking { + startLog(trailName) + stopLog(trailName) + println("Test 6 passed") + } + + @Test + @Order(7) + fun deleteTrail() = runBlocking { + deleteSpecificTrail(trailName) + println("Test 7 passed") + } + + private suspend fun getSecretValues(): String { + val secretName = "test/cloudtrail" + val valueRequest = GetSecretValueRequest { + secretId = secretName + } + SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> + val valueResponse = secretClient.getSecretValue(valueRequest) + return valueResponse.secretString.toString() + } + } + + @Nested + @DisplayName("A class used to get test values from test/cloudtrail (an AWS Secrets Manager secret)") + internal class SecretValues { + val trailName: String? = null + val s3BucketName: String? = null + } +} From fe0edb3b98fda5216dd20d6e5617b0e1dc527e7a Mon Sep 17 00:00:00 2001 From: scmacdon Date: Wed, 7 Feb 2024 16:00:41 -0500 Subject: [PATCH 7/7] add cloudwatch files --- kotlin/services/cloudwatch/build.gradle.kts | 5 +- .../src/test/kotlin/CloudWatchTest.kt | 311 ++++++------------ 2 files changed, 95 insertions(+), 221 deletions(-) diff --git a/kotlin/services/cloudwatch/build.gradle.kts b/kotlin/services/cloudwatch/build.gradle.kts index bc68e2bf1a1..0a50fd2b94a 100644 --- a/kotlin/services/cloudwatch/build.gradle.kts +++ b/kotlin/services/cloudwatch/build.gradle.kts @@ -25,10 +25,11 @@ buildscript { repositories { mavenCentral() } + apply(plugin = "org.jlleitschuh.gradle.ktlint") dependencies { - implementation("aws.sdk.kotlin:cloudwatch:1.0.0") - implementation("aws.sdk.kotlin:cloudwatchevents:1.0.0") + implementation("aws.sdk.kotlin:cloudwatch:1.0.30") + implementation("aws.sdk.kotlin:cloudwatchevents:1.0.30") implementation("aws.sdk.kotlin:cloudwatchlogs:1.0.0") implementation("aws.sdk.kotlin:secretsmanager:1.0.0") implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0") diff --git a/kotlin/services/cloudwatch/src/test/kotlin/CloudWatchTest.kt b/kotlin/services/cloudwatch/src/test/kotlin/CloudWatchTest.kt index 414f6990185..54e80709779 100644 --- a/kotlin/services/cloudwatch/src/test/kotlin/CloudWatchTest.kt +++ b/kotlin/services/cloudwatch/src/test/kotlin/CloudWatchTest.kt @@ -1,54 +1,32 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import com.kotlin.cloudwatch.DASHES -import com.kotlin.cloudwatch.addAnomalyDetector -import com.kotlin.cloudwatch.addMetricDataForAlarm -import com.kotlin.cloudwatch.addMetricToDashboard -import com.kotlin.cloudwatch.checkForMetricAlarm -import com.kotlin.cloudwatch.createAlarm -import com.kotlin.cloudwatch.createDashboardWithMetrics -import com.kotlin.cloudwatch.createNewCustomMetric -import com.kotlin.cloudwatch.deleteAlarm -import com.kotlin.cloudwatch.deleteAnomalyDetector +import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider +import aws.sdk.kotlin.services.secretsmanager.SecretsManagerClient +import aws.sdk.kotlin.services.secretsmanager.model.GetSecretValueRequest +import com.google.gson.Gson import com.kotlin.cloudwatch.deleteCWAlarm -import com.kotlin.cloudwatch.deleteDashboard import com.kotlin.cloudwatch.deleteSubFilter import com.kotlin.cloudwatch.desCWAlarms -import com.kotlin.cloudwatch.describeAlarms -import com.kotlin.cloudwatch.describeAnomalyDetectors import com.kotlin.cloudwatch.describeFilters import com.kotlin.cloudwatch.disableActions import com.kotlin.cloudwatch.enableActions -import com.kotlin.cloudwatch.getAlarmHistory -import com.kotlin.cloudwatch.getAndDisplayMetricStatistics -import com.kotlin.cloudwatch.getAndOpenMetricImage import com.kotlin.cloudwatch.getCWLogEvents -import com.kotlin.cloudwatch.getCustomMetricData import com.kotlin.cloudwatch.getMetData -import com.kotlin.cloudwatch.getMetricStatistics -import com.kotlin.cloudwatch.getSpecificMet -import com.kotlin.cloudwatch.listDashboards -import com.kotlin.cloudwatch.listMets -import com.kotlin.cloudwatch.listNameSpaces import com.kotlin.cloudwatch.putAlarm import com.kotlin.cloudwatch.putCWEvents import com.kotlin.cloudwatch.putCWLogEvents import com.kotlin.cloudwatch.putCWRule import com.kotlin.cloudwatch.putSubFilters import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.MethodOrderer.OrderAnnotation +import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Order import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestMethodOrder -import java.io.InputStream -import java.util.Properties -import java.util.Scanner -import kotlin.collections.ArrayList -import kotlin.system.exitProcess @TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestMethodOrder(OrderAnnotation::class) @@ -66,7 +44,6 @@ class CloudWatchTest { private var namespace = "" private var filterPattern = "" private var ruleName = "" - private var myDateSc = "" private var costDateWeekSc = "" private var dashboardNameSc = "" @@ -76,7 +53,34 @@ class CloudWatchTest { private var metricImageSc = "" @BeforeAll - fun setup() { + fun setup() = runBlocking { + // Get the values from AWS Secrets Manager. + val gson = Gson() + val json: String = getSecretValues() + val values = gson.fromJson(json, SecretValues::class.java) + logGroup = values.logGroup.toString() + alarmName = values.alarmName.toString() + streamName = values.streamName.toString() + ruleResource = values.ruleResource.toString() + metricId = values.metricId.toString() + filterName = values.filterName.toString() + destinationArn = values.destinationArn.toString() + roleArn = values.roleArn.toString() + filterPattern = values.filterPattern.toString() + instanceId = values.instanceId.toString() + ruleName = values.ruleName.toString() + ruleArn = values.ruleArn.toString() + namespace = values.namespace.toString() + myDateSc = values.myDateSc.toString() + costDateWeekSc = values.costDateWeekSc.toString() + dashboardNameSc = values.dashboardNameSc.toString() + dashboardJsonSc = values.dashboardJsonSc.toString() + dashboardAddSc = values.dashboardAddSc.toString() + settingsSc = values.settingsSc.toString() + metricImageSc = values.metricImageSc.toString() + + // Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests. + /* val input: InputStream = this.javaClass.getClassLoader().getResourceAsStream("config.properties") val prop = Properties() prop.load(input) @@ -100,265 +104,134 @@ class CloudWatchTest { dashboardAddSc = prop.getProperty("dashboardAddSc") settingsSc = prop.getProperty("settingsSc") metricImageSc = prop.getProperty("metricImageSc") + */ } @Test @Order(1) - fun whenInitializingAWSService_thenNotNull() { - Assertions.assertNotNull(logGroup) - Assertions.assertNotNull(alarmName) - Assertions.assertNotNull(streamName) - Assertions.assertNotNull(ruleResource) - Assertions.assertNotNull(metricId) - Assertions.assertNotNull(filterName) - Assertions.assertNotNull(destinationArn) - Assertions.assertNotNull(roleArn) - Assertions.assertNotNull(filterPattern) - Assertions.assertNotNull(instanceId) - Assertions.assertNotNull(ruleName) - Assertions.assertNotNull(ruleArn) - Assertions.assertNotNull(namespace) - println("Test 1 passed") - } - - @Test - @Order(2) fun createAlarmTest() = runBlocking { putAlarm(alarmName, instanceId) - println("Test 2 passed") + println("Test 1 passed") } @Test - @Order(3) + @Order(2) fun describeAlarmsTest() = runBlocking { desCWAlarms() - println("Test 3 passed") + println("Test 2 passed") } @Test - @Order(4) + @Order(3) fun createSubscriptionFiltersTest() = runBlocking { putSubFilters(filterName, filterPattern, logGroup, destinationArn) - println("Test 4 passed") + println("Test 3 passed") } @Test - @Order(5) + @Order(4) fun describeSubscriptionFiltersTest() = runBlocking { describeFilters(logGroup) - println("Test 5 passed") + println("Test 4 passed") } @Test - @Order(6) + @Order(5) fun disableAlarmActionsTest() = runBlocking { disableActions(alarmName) - println("Test 6 passed") + println("Test 5 passed") } @Test - @Order(7) + @Order(6) fun enableAlarmActionsTest() = runBlocking { enableActions(alarmName) - println("Test 7 passed") + println("Test 6 passed") } @Test - @Order(8) + @Order(7) fun getLogEventsTest() = runBlocking { getCWLogEvents(logGroup, streamName) - println("Test 8 passed") + println("Test 7 passed") } @Test - @Order(9) + @Order(8) fun putCloudWatchEventTest() = runBlocking { putCWEvents(ruleResource) - println("Test 9 passed") + println("Test 8 passed") } @Test - @Order(10) + @Order(9) fun getMetricDataTest() = runBlocking { getMetData() - println("Test 10 passed") + println("Test 9 passed") } @Test - @Order(11) + @Order(10) fun deleteSubscriptionFilterTest() = runBlocking { deleteSubFilter(filterName, logGroup) - println("Test 11 passed") + println("Test 10 passed") } @Test - @Order(12) + @Order(11) fun putRuleTest() = runBlocking { putCWRule(ruleName, ruleArn) - println("Test 12 passed") + println("Test 11 passed") } @Test - @Order(13) + @Order(12) fun putLogEvents() = runBlocking { putCWLogEvents(logGroup, streamName) - println("Test 13 passed") + println("Test 12 passed") } @Test - @Order(14) + @Order(13) fun deleteCWAlarmTest() = runBlocking { deleteCWAlarm(alarmName) - println("Test 14 passed") + println("Test 13 passed") } - @Test - @Order(16) - fun TestScenario() = runBlocking { - val inOb = Scanner(System.`in`) - val dataPoint = "10.0".toDouble() - println(DASHES) - println("1. List at least five available unique namespaces from Amazon CloudWatch. Select a CloudWatch namespace from the list.") - val list: ArrayList = listNameSpaces() - for (z in 0..4) { - println(" ${z + 1}. ${list[z]}") - } - - var selectedNamespace: String - var selectedMetrics = "" - var num = inOb.nextLine().toInt() - println("You selected $num") - - if (1 <= num && num <= 5) { - selectedNamespace = list[num - 1] - } else { - println("You did not select a valid option.") - exitProcess(1) - } - println("You selected $selectedNamespace") - println(DASHES) - - println(DASHES) - println("2. List available metrics within the selected namespace and select one from the list.") - val metList = listMets(selectedNamespace) - for (z in 0..4) { - println(" ${ z + 1}. ${metList?.get(z)}") + private suspend fun getSecretValues(): String { + val secretName = "test/cloudwatch" + val valueRequest = GetSecretValueRequest { + secretId = secretName } - num = inOb.nextLine().toInt() - if (1 <= num && num <= 5) { - selectedMetrics = metList!![num - 1] - } else { - println("You did not select a valid option.") - System.exit(1) + SecretsManagerClient { region = "us-east-1"; credentialsProvider = EnvironmentCredentialsProvider() }.use { secretClient -> + val valueResponse = secretClient.getSecretValue(valueRequest) + return valueResponse.secretString.toString() } - println("You selected $selectedMetrics") - val myDimension = getSpecificMet(selectedNamespace) - if (myDimension == null) { - println("Error - Dimension is null") - exitProcess(1) - } - println(DASHES) - - println(DASHES) - println("3. Get statistics for the selected metric over the last day.") - val metricOption: String - val statTypes = ArrayList() - statTypes.add("SampleCount") - statTypes.add("Average") - statTypes.add("Sum") - statTypes.add("Minimum") - statTypes.add("Maximum") - - for (t in 0..4) { - println(" ${t + 1}. ${statTypes[t]}") - } - println("Select a metric statistic by entering a number from the preceding list:") - num = inOb.nextLine().toInt() - if (1 <= num && num <= 5) { - metricOption = statTypes[num - 1] - } else { - println("You did not select a valid option.") - exitProcess(1) - } - println("You selected $metricOption") - getAndDisplayMetricStatistics(selectedNamespace, selectedMetrics, metricOption, myDateSc, myDimension) - println(DASHES) - - println(DASHES) - println("4. Get CloudWatch estimated billing for the last week.") - getMetricStatistics(costDateWeekSc) - println(DASHES) - - println(DASHES) - println("5. Create a new CloudWatch dashboard with metrics.") - createDashboardWithMetrics(dashboardNameSc, dashboardJsonSc) - println(DASHES) - - println(DASHES) - println("6. List dashboards using a paginator.") - listDashboards() - println(DASHES) - - println(DASHES) - println("7. Create a new custom metric by adding data to it.") - createNewCustomMetric(dataPoint) - println(DASHES) - - println(DASHES) - println("8. Add an additional metric to the dashboard.") - addMetricToDashboard(dashboardAddSc, dashboardNameSc) - println(DASHES) - - println(DASHES) - println("9. Create an alarm for the custom metric.") - val alarmName: String = createAlarm(settingsSc) - println(DASHES) - - println(DASHES) - println("10. Describe 10 current alarms.") - describeAlarms() - println(DASHES) - - println(DASHES) - println("11. Get current data for the new custom metric.") - getCustomMetricData(settingsSc) - println(DASHES) - - println(DASHES) - println("12. Push data into the custom metric to trigger the alarm.") - addMetricDataForAlarm(settingsSc) - println(DASHES) - - println(DASHES) - println("13. Check the alarm state using the action DescribeAlarmsForMetric.") - checkForMetricAlarm(settingsSc) - println(DASHES) - - println(DASHES) - println("14. Get alarm history for the new alarm.") - getAlarmHistory(settingsSc, myDateSc) - println(DASHES) - - println(DASHES) - println("15. Add an anomaly detector for the custom metric.") - addAnomalyDetector(settingsSc) - println(DASHES) - - println(DASHES) - println("16. Describe current anomaly detectors.") - describeAnomalyDetectors(settingsSc) - println(DASHES) - - println(DASHES) - println("17. Get a metric image for the custom metric.") - getAndOpenMetricImage(metricImageSc) - println(DASHES) + } - println(DASHES) - println("18. Clean up the Amazon CloudWatch resources.") - deleteDashboard(dashboardNameSc) - deleteAlarm(alarmName) - deleteAnomalyDetector(settingsSc) - println(DASHES) + @Nested + @DisplayName("A class used to get test values from test/cloudwatch (an AWS Secrets Manager secret)") + internal class SecretValues { + // Provide getter methods for each of the test values + val logGroup: String? = null + val alarmName: String? = null + val instanceId: String? = null + val streamName: String? = null + val ruleResource: String? = null + val metricId: String? = null + val filterName: String? = null + val destinationArn: String? = null + val roleArn: String? = null + val ruleArn: String? = null + val filterPattern: String? = null + val ruleName: String? = null + val namespace: String? = null + val myDateSc: String? = null + val costDateWeekSc: String? = null + val dashboardNameSc: String? = null + val dashboardJsonSc: String? = null + val dashboardAddSc: String? = null + val settingsSc: String? = null + val metricImageSc: String? = null } }