1 1 | /*
|
2 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 3 | * SPDX-License-Identifier: Apache-2.0
|
4 4 | */
|
5 5 | package aws.sdk.kotlin.e2etest
|
6 6 |
|
7 - | import aws.sdk.kotlin.e2etest.S3TestUtils.deleteBucketAndAllContents
|
8 - | import aws.sdk.kotlin.e2etest.S3TestUtils.getAccountId
|
9 - | import aws.sdk.kotlin.e2etest.S3TestUtils.getBucketWithPrefix
|
10 7 | import aws.sdk.kotlin.services.s3.S3Client
|
11 8 | import aws.sdk.kotlin.services.s3.deleteObject
|
12 9 | import aws.sdk.kotlin.services.s3.putObject
|
13 10 | import aws.sdk.kotlin.services.s3.withConfig
|
14 - | import aws.sdk.kotlin.services.s3control.S3ControlClient
|
15 - | import aws.sdk.kotlin.services.s3control.createMultiRegionAccessPoint
|
16 - | import aws.sdk.kotlin.services.s3control.deleteMultiRegionAccessPoint
|
17 - | import aws.sdk.kotlin.services.s3control.describeMultiRegionAccessPointOperation
|
18 - | import aws.sdk.kotlin.services.s3control.getMultiRegionAccessPoint
|
11 + | import aws.sdk.kotlin.services.s3control.*
|
19 12 | import aws.sdk.kotlin.services.s3control.model.Region
|
20 - | import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigner
|
13 + | import aws.sdk.kotlin.services.s3control.paginators.listMultiRegionAccessPointsPaginated
|
21 14 | import aws.smithy.kotlin.runtime.auth.awssigning.DefaultAwsSigner
|
22 15 | import aws.smithy.kotlin.runtime.auth.awssigning.crt.CrtAwsSigner
|
23 16 | import aws.smithy.kotlin.runtime.http.auth.SigV4AsymmetricAuthScheme
|
17 + | import aws.smithy.kotlin.runtime.testing.AfterAll
|
18 + | import aws.smithy.kotlin.runtime.testing.BeforeAll
|
19 + | import aws.smithy.kotlin.runtime.testing.TestInstance
|
20 + | import aws.smithy.kotlin.runtime.testing.TestLifecycle
|
21 + | import aws.smithy.kotlin.runtime.testing.parameterized
|
24 22 | import kotlinx.coroutines.delay
|
23 + | import kotlinx.coroutines.flow.toList
|
25 24 | import kotlinx.coroutines.runBlocking
|
26 25 | import kotlinx.coroutines.withTimeout
|
27 - | import org.junit.jupiter.api.AfterAll
|
28 - | import org.junit.jupiter.api.BeforeAll
|
29 - | import org.junit.jupiter.api.TestInstance
|
30 - | import org.junit.jupiter.params.ParameterizedTest
|
31 - | import org.junit.jupiter.params.provider.Arguments
|
32 - | import org.junit.jupiter.params.provider.MethodSource
|
33 - | import java.util.stream.Stream
|
34 - | import kotlin.random.Random
|
26 + | import kotlin.test.Test
|
35 27 | import kotlin.time.Duration
|
36 28 | import kotlin.time.Duration.Companion.minutes
|
37 29 | import kotlin.time.Duration.Companion.seconds
|
38 30 |
|
39 - | private const val MRAP_BUCKET_PREFIX = "s3-mrap-test-bucket-"
|
40 - | private val MULTI_REGION_ACCESS_POINT_NAME = "aws-sdk-for-kotlin-mrap-${Random.nextInt(0, 9999)}"
|
41 31 | private const val TEST_OBJECT_KEY = "test.txt"
|
42 32 |
|
43 - | @TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
44 - | class MutliRegionAccessPointTest {
|
33 + | @TestInstance(TestLifecycle.PER_CLASS)
|
34 + | class MultiRegionAccessPointTest {
|
45 35 | private lateinit var s3West: S3Client
|
46 36 | private lateinit var s3East: S3Client
|
47 37 | private lateinit var s3Control: S3ControlClient
|
48 38 |
|
49 39 | private lateinit var accountId: String
|
40 + | private lateinit var multiRegionAccessPointName: String
|
50 41 | private lateinit var multiRegionAccessPointArn: String
|
51 42 | private lateinit var usWestBucket: String
|
52 43 | private lateinit var usEastBucket: String
|
53 44 |
|
54 45 | @BeforeAll
|
55 46 | fun setup(): Unit = runBlocking {
|
56 - | s3West = S3Client { region = "us-west-2" }
|
57 - | s3East = S3Client { region = "us-east-2" }
|
47 + | s3West = S3TestUtils.createClient { region = "us-west-2" }
|
48 + | s3East = S3TestUtils.createClient { region = "us-east-2" }
|
58 49 | s3Control = S3ControlClient { region = "us-west-2" }
|
59 50 |
|
60 - | accountId = getAccountId()
|
61 - | usWestBucket = getBucketWithPrefix(s3West, MRAP_BUCKET_PREFIX, "us-west-2", accountId)
|
62 - | usEastBucket = getBucketWithPrefix(s3East, MRAP_BUCKET_PREFIX, "us-east-2", accountId)
|
51 + | accountId = S3TestUtils.getAccountId()
|
52 + | usWestBucket = S3TestUtils.createTestBucket(s3West, "mrap-west")
|
53 + | usEastBucket = S3TestUtils.createTestBucket(s3East, "mrap-east")
|
63 54 |
|
55 + | multiRegionAccessPointName = "s3-test-mrap-${S3TestUtils.testRunId}"
|
64 56 | multiRegionAccessPointArn = s3Control.createMultiRegionAccessPoint(
|
65 - | MULTI_REGION_ACCESS_POINT_NAME,
|
57 + | multiRegionAccessPointName,
|
66 58 | accountId,
|
67 59 | listOf(usWestBucket, usEastBucket),
|
68 60 | )
|
69 61 | }
|
70 62 |
|
71 63 | @AfterAll
|
72 64 | fun cleanup(): Unit = runBlocking {
|
73 - | s3Control.deleteMultiRegionAccessPoint(MULTI_REGION_ACCESS_POINT_NAME, accountId)
|
65 + | s3Control.deleteMultiRegionAccessPoint(multiRegionAccessPointName, accountId)
|
74 66 |
|
75 - | deleteBucketAndAllContents(s3West, usWestBucket)
|
76 - | deleteBucketAndAllContents(s3East, usEastBucket)
|
67 + | val resp = s3Control.listMultiRegionAccessPointsPaginated {
|
68 + | accountId = this@MultiRegionAccessPointTest.accountId
|
69 + | }.toList().flatMap { it.accessPoints.orEmpty() }
|
70 + |
|
71 + | val mrapManifest = buildString {
|
72 + | appendLine("Existing multi-region access points for account ID $accountId (${resp.size}):")
|
73 + | resp.forEach { accessPoint ->
|
74 + | appendLine("* ${accessPoint.name}:")
|
75 + | appendLine(" * Alias: ${accessPoint.alias}")
|
76 + | appendLine(" * Created: ${accessPoint.createdAt}")
|
77 + | appendLine(" * Status: ${accessPoint.status}")
|
78 + |
|
79 + | val regions = accessPoint.regions.orEmpty()
|
80 + | appendLine(" * Regions (${regions.size}):")
|
81 + |
|
82 + | regions.forEach { region ->
|
83 + | appendLine(" * ${region.region}: ${region.bucket} (account ID ${region.bucketAccountId})")
|
84 + | }
|
85 + | }
|
86 + | }
|
87 + | print(mrapManifest)
|
88 + |
|
89 + | S3TestUtils.deleteBucket(s3West, usWestBucket)
|
90 + | S3TestUtils.deleteBucket(s3East, usEastBucket)
|
77 91 |
|
78 92 | s3West.close()
|
79 93 | s3East.close()
|
80 94 | s3Control.close()
|
81 95 | }
|
82 96 |
|
83 - | @ParameterizedTest
|
84 - | @MethodSource("signerProvider")
|
85 - | fun testMultiRegionAccessPointOperation(signer: AwsSigner): Unit = runBlocking {
|
97 + | @Test
|
98 + | fun testMultiRegionAccessPointOperation(): Unit = parameterized(
|
99 + | listOf(DefaultAwsSigner, CrtAwsSigner),
|
100 + | ) { signer ->
|
101 + | runBlocking {
|
86 102 | println("Testing multi-region access point operations with $signer")
|
87 103 |
|
88 104 | val s3SigV4a = s3West.withConfig {
|
89 105 | authSchemes = listOf(SigV4AsymmetricAuthScheme(signer))
|
90 106 | }
|
91 107 |
|
92 108 | s3SigV4a.putObject {
|
93 109 | bucket = multiRegionAccessPointArn
|
94 110 | key = TEST_OBJECT_KEY
|
95 111 | }
|
96 112 |
|
97 113 | s3SigV4a.deleteObject {
|
98 114 | bucket = multiRegionAccessPointArn
|
99 115 | key = TEST_OBJECT_KEY
|
100 116 | }
|
101 117 | }
|
102 - |
|
103 - | fun signerProvider(): Stream<Arguments> = Stream.of(
|
104 - | Arguments.of(DefaultAwsSigner),
|
105 - | Arguments.of(CrtAwsSigner),
|
106 - | )
|
118 + | }
|
107 119 | }
|
108 120 |
|
109 121 | /**
|
110 122 | * Create a multi-region access point named [name] in account [accountId] with [buckets] buckets.
|
111 123 | * @return the ARN of the multi-region access point that was created
|
112 124 | */
|
113 125 | private suspend fun S3ControlClient.createMultiRegionAccessPoint(
|
114 126 | name: String,
|
115 127 | accountId: String,
|
116 128 | buckets: List<String>,
|