-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: account id routing #1111
feat: account id routing #1111
Changes from all commits
6861aa8
7de2954
70c2239
96bbe11
4945447
58845b7
3498812
b049217
d7f723f
049139f
7b041a3
cef21fe
117fc7c
aeb854e
2808652
db456e8
bd9c411
ec7d9bc
5e7cb9e
b822b8c
c6f287d
eea4a84
3900c30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id": "873fb1ab-bfbb-4110-89cd-bf7ac352bc86", | ||
"type": "feature", | ||
"description": "⚠️ **IMPORTANT**: Enable account ID based endpoint routing for services that support it", | ||
"requiresMinorVersionBump": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "98b36000-c7c2-43e1-8bfe-ec7e93317f3a", | ||
"type": "misc", | ||
"description": "Upgrade dependencies to their latest versions, notably Kotlin 1.9.20" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.runtime.arns | ||
|
||
private const val ARN_COMPONENT_COUNT = 6 | ||
|
||
/** | ||
* Represents an [Amazon Resource Name (ARN)](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html). | ||
* | ||
* The following Arn formats are supported: | ||
* * `arn:partition:service:region:account-id:resource-id` | ||
* * `arn:partition:service:region:account-id:resource-type/resource-id` | ||
* * `arn:partition:service:region:account-id:resource-type:resource-id` | ||
* * `arn:partition:service:region:account-id:resource-type:resource-id:qualifier` | ||
* * `arn:partition:service:region:account-id:resource-type:resource-id/qualifier` | ||
* | ||
* The exact format of an ARN depends on the service and resource type. Some resource ARNs can include a path or | ||
* wildcard. To look up the ARN format for a specific AWS resource, open the | ||
* [Service Authorization Reference](https://docs.aws.amazon.com/service-authorization/latest/reference/), | ||
* open the page for the service, and navigate to the resource types table. | ||
*/ | ||
internal class Arn( | ||
public val partition: String, | ||
public val service: String, | ||
public val region: String?, | ||
public val accountId: String?, | ||
public val resource: String, | ||
) { | ||
public companion object { | ||
|
||
public inline operator fun invoke(block: Builder.() -> Unit): Arn = Builder().apply(block).build() | ||
|
||
/** | ||
* Parse a string into an [Arn] | ||
*/ | ||
public fun parse(arn: String): Arn { | ||
val parts = arn.split(':', limit = ARN_COMPONENT_COUNT) | ||
require(parts.size == ARN_COMPONENT_COUNT) { "Malformed ARN ($arn) does not have the expected number of components" } | ||
require(parts[0] == "arn") { "Malformed ARN - does not start with `arn:`" } | ||
require(parts[1].isNotBlank()) { "Malformed ARN - no AWS partition specified" } | ||
require(parts[2].isNotBlank()) { "Malformed ARN - no AWS service specified" } | ||
|
||
return Arn { | ||
partition = parts[1] | ||
service = parts[2] | ||
region = parts[3].takeIf(String::isNotBlank) | ||
accountId = parts[4].takeIf(String::isNotBlank) | ||
resource = parts[5] | ||
} | ||
} | ||
} | ||
|
||
internal constructor(builder: Builder) : this( | ||
builder.partition!!, | ||
builder.service!!, | ||
builder.region, | ||
builder.accountId, | ||
builder.resource!!, | ||
) | ||
|
||
init { | ||
require(region == null || region.isNotBlank()) { "ARN region must not be blank" } | ||
require(accountId == null || accountId.isNotBlank()) { "ARN accountId must not be blank" } | ||
} | ||
|
||
override fun toString(): String = buildString { | ||
append("arn:$partition:$service:") | ||
if (region != null) { | ||
append(region) | ||
} | ||
append(":") | ||
if (accountId != null) { | ||
append(accountId) | ||
} | ||
append(":$resource") | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is Arn) return false | ||
if (partition != other.partition) return false | ||
if (service != other.service) return false | ||
if (region != other.region) return false | ||
if (accountId != other.accountId) return false | ||
return resource == other.resource | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = partition.hashCode() | ||
result = 31 * result + service.hashCode() | ||
result = 31 * result + (region?.hashCode() ?: 0) | ||
result = 31 * result + (accountId?.hashCode() ?: 0) | ||
result = 31 * result + resource.hashCode() | ||
return result | ||
} | ||
Comment on lines
+80
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If this is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be, I didn't refactor this when moving from public to internal though and didn't see a reason to. |
||
|
||
public class Builder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was originally public. My understanding is that any client who sees the declaring class sees its public members. Because the outer class visibility is |
||
public var partition: String? = null | ||
public var service: String? = null | ||
public var region: String? = null | ||
public var accountId: String? = null | ||
public var resource: String? = null | ||
|
||
@PublishedApi | ||
internal fun build(): Arn { | ||
Comment on lines
+106
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. N, this was originally all |
||
require(!partition.isNullOrBlank()) { "ARN partition must not be null or blank" } | ||
require(!service.isNullOrBlank()) { "ARN service must not be null or blank" } | ||
requireNotNull(resource) { "ARN resource must not be null" } | ||
return Arn(this) | ||
} | ||
Comment on lines
+106
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Why validate some of the fields in the builder and the other fields in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because it has a constructor that can be used independent of the builder. The builder itself has nullable fields but the constructor doesn't. We only validate the things the builder needs to be responsible for here and elsewhere. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Why
public
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered elsewhere