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

Updated AWSSQS in the report-sink service to use the WebIdentityTokenFileCredentialsProvider #272

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.apache.qpid.proton.TimeoutException
import software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider
import java.nio.file.Path

/**
* The `AWSSQServiceConfiguration` class configures and initializes connection AWS SQS based on settings provided in an `ApplicationConfig`.
Expand All @@ -28,16 +30,28 @@ import org.apache.qpid.proton.TimeoutException
class AWSSQServiceConfiguration(config: ApplicationConfig, configurationPath: String? = null) {
private val configPath = if (configurationPath != null) "$configurationPath." else ""
val queueURL: String = config.tryGetString("${configPath}sqs.url") ?: ""
private val accessKeyID = config.tryGetString("${configPath}access_key_id") ?: ""
private val roleArn: String = config.tryGetString("${configPath}role_arn") ?: ""
private val webIdentityTokenFile: String = config.tryGetString("${configPath}web_identity_token_file") ?: ""
private val accessKeyId = config.tryGetString("${configPath}access_key_id") ?: ""
private val secretAccessKey = config.tryGetString("${configPath}secret_access_key") ?: ""
private val region = config.tryGetString("${configPath}region") ?: "us-east-1"
private val endpoint: Url? = config.tryGetString("${configPath}endpoint")?.let { Url.parse(it) }

fun createSQSClient(): SqsClient{
return SqsClient{
credentialsProvider = StaticCredentialsProvider {
accessKeyId = [email protected]
secretAccessKey = [email protected]
return SqsClient {

if (accessKeyId.isNotEmpty() && secretAccessKey.isNotEmpty()) {
StaticCredentialsProvider {
accessKeyId = [email protected]
secretAccessKey = [email protected]
}
} else if (webIdentityTokenFile.isNotEmpty() && roleArn.isNotEmpty()) {
WebIdentityTokenFileCredentialsProvider.builder()
.roleArn(roleArn)
.webIdentityTokenFile(webIdentityTokenFile.let { Path.of(it) })
.build()
} else {
throw IllegalArgumentException("No valid credentials provided.")
}
region = [email protected]
endpointUrl = [email protected]
Expand Down
Loading