Skip to content
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

Add mechanism to get caller identity. #4

Merged
merged 3 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Dropping a requirement of a major version of a dependency is a new contract.
## [Unreleased]
[Unreleased]: https://bitbucket.org/atlassian/aws-resources/branches/compare/master%0Drelease-1.11.2

### Added
- Add `Aws.sts`.
- Add `Aws.callerIdentity`.

## [1.11.2] - 2023-03-07
[1.11.2]: https://bitbucket.org/atlassian/aws-resources/branches/compare/release-1.11.2%0Drelease-1.11.1

Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/com/atlassian/performance/tools/aws/api/Aws.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import com.amazonaws.services.rds.AmazonRDS
import com.amazonaws.services.rds.AmazonRDSClientBuilder
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.securitytoken.AWSSecurityTokenService
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder
import com.amazonaws.services.securitytoken.model.GetCallerIdentityRequest
import com.amazonaws.services.securitytoken.model.GetCallerIdentityResult
import com.atlassian.performance.tools.aws.*
import com.atlassian.performance.tools.aws.api.ami.AmiProvider
import com.atlassian.performance.tools.aws.api.ami.CanonicalAmiProvider
Expand Down Expand Up @@ -83,6 +86,10 @@ class Aws private constructor(
.withRegion(region)
.withCredentials(credentialsProvider)
.build()
val sts: AWSSecurityTokenService = AWSSecurityTokenServiceClientBuilder.standard()
.withRegion(region)
.withCredentials(credentialsProvider)
.build()
private val scrollingCloudformation = ScrollingCloudformation(cloudformation)
internal val batchingCfn =
InternalBatchingCloudformation(scrollingCloudformation, batchingCloudformationRefreshPeriod)
Expand Down Expand Up @@ -148,6 +155,10 @@ class Aws private constructor(
.filter(availabilityZoneFilter)
}

val callerIdentity: GetCallerIdentityResult by lazy {
dagguh marked this conversation as resolved.
Show resolved Hide resolved
sts.getCallerIdentity(GetCallerIdentityRequest())
}

init {
if (region !in regionsWithHousekeeping) {
val message = """
Expand Down Expand Up @@ -413,3 +424,4 @@ class Aws private constructor(
)
}
}

1 change: 1 addition & 0 deletions src/main/resources/iam-policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"sts:GetCallerIdentity",
"support:CreateCase"
],
"Resource": "*"
Expand Down