Skip to content

Commit

Permalink
Simplify CanonicalOwnerIdRegistry impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dagguh committed Jun 10, 2024
1 parent afdde11 commit 1c4cf57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package com.atlassian.performance.tools.aws

import com.amazonaws.regions.Regions
import com.amazonaws.regions.Regions.*

/**
* Based on https://ubuntu.com/server/docs/cloud-images/amazon-ec2
* Based on https://documentation.ubuntu.com/aws/en/latest/aws-how-to/instances/find-ubuntu-images/#ownership-verification
*/
internal object CanonicalOwnerIdRegistry {
const val default = "099720109477"
val byRegion = Regions.values().associate {
it to when(it) {
Regions.GovCloud -> "513442679011"
Regions.CN_NORTH_1,
Regions.CN_NORTHWEST_1 -> "837727238323"
else -> default
}
fun forRegion(region: Regions?) = when (region) {
GovCloud -> "513442679011"
CN_NORTH_1, CN_NORTHWEST_1 -> "837727238323"
else -> "099720109477"
}

fun forRegion(region: Regions?) = byRegion[region] ?: default
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CanonicalImageIdByNameResolverTest {
assertThat(savedRequest).isNotNull
assertThat(savedRequest!!.filters).contains(
Filter("name", listOf(queriedImageName)),
Filter("owner-id", listOf(CanonicalOwnerIdRegistry.byRegion[region]))
Filter("owner-id", listOf(CanonicalOwnerIdRegistry.forRegion(region)))
)
}
}
Expand All @@ -63,7 +63,7 @@ class CanonicalImageIdByNameResolverTest {
assertThat(savedRequest).isNotNull
assertThat(savedRequest!!.filters).contains(
Filter("name", listOf(queriedImageName)),
Filter("owner-id", listOf(CanonicalOwnerIdRegistry.default))
Filter("owner-id", listOf("099720109477"))
)
}

Expand Down

0 comments on commit 1c4cf57

Please sign in to comment.