From ae01f283a2f61e0a2c210af64407fa361f3b4b66 Mon Sep 17 00:00:00 2001 From: Edward Gao Date: Wed, 29 Jan 2025 13:20:21 -0800 Subject: [PATCH] Bulk Load CDK: micronaut nonsense (#52627) --- .../command/aws/AwsAssumeRoleCredentials.kt | 27 ++++++++++++++++--- .../connectors/destination-s3/metadata.yaml | 2 +- docs/integrations/destinations/s3.md | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/airbyte-cdk/bulk/toolkits/load-aws/src/main/kotlin/io/airbyte/cdk/load/command/aws/AwsAssumeRoleCredentials.kt b/airbyte-cdk/bulk/toolkits/load-aws/src/main/kotlin/io/airbyte/cdk/load/command/aws/AwsAssumeRoleCredentials.kt index f722c6f6160dc..9be27abf319e6 100644 --- a/airbyte-cdk/bulk/toolkits/load-aws/src/main/kotlin/io/airbyte/cdk/load/command/aws/AwsAssumeRoleCredentials.kt +++ b/airbyte-cdk/bulk/toolkits/load-aws/src/main/kotlin/io/airbyte/cdk/load/command/aws/AwsAssumeRoleCredentials.kt @@ -6,6 +6,8 @@ package io.airbyte.cdk.load.command.aws import io.micronaut.context.annotation.Requires import io.micronaut.context.annotation.Value +import io.micronaut.context.condition.Condition +import io.micronaut.context.condition.ConditionContext import javax.inject.Singleton // For some reason, micronaut doesn't handle plain `@Requires(property = "...")` when you declare @@ -14,9 +16,18 @@ import javax.inject.Singleton // but then tries to inject a null value to the field, which obviously throws an exception. // So instead, we declare the property as `${FOO_BAR:}` (i.e. default to empty string) // and set a property notEquals empty string requirement. -@Requires(property = ACCESS_KEY_PROPERTY, notEquals = "") -@Requires(property = SECRET_KEY_PROPERTY, notEquals = "") -@Requires(property = EXTERNAL_ID_PROPERTY, notEquals = "") + +// You might expect that after dealing with that mess, we could just declare three @Requires flags, +// like so: +// @Requires(property = ACCESS_KEY_PROPERTY, notEquals = "") +// @Requires(property = SECRET_KEY_PROPERTY, notEquals = "") +// @Requires(property = EXTERNAL_ID_PROPERTY, notEquals = "") + +// However, micronaut sometimes decides to not load the bean, when there are three different +// @Requires annotations. +// So instead we define a custom condition, which does the _exact same thing_, +// but lets us use only a single Requires annotation. +@Requires(condition = AssumeRoleCredentialsCondition::class) @Singleton data class AwsAssumeRoleCredentials( @Value("\${$ACCESS_KEY_PROPERTY}") val accessKey: String, @@ -29,3 +40,13 @@ data class AwsAssumeRoleCredentials( const val ACCESS_KEY_PROPERTY = "airbyte.destination.aws.assume-role.access-key" const val SECRET_KEY_PROPERTY = "airbyte.destination.aws.assume-role.secret-key" const val EXTERNAL_ID_PROPERTY = "airbyte.destination.aws.assume-role.external-id" + +private object AssumeRoleCredentialsCondition : Condition { + override fun matches(context: ConditionContext<*>): Boolean { + val accessKey = context.getProperty(ACCESS_KEY_PROPERTY, String::class.java).orElse("") + val secretKey = context.getProperty(SECRET_KEY_PROPERTY, String::class.java).orElse("") + val externalId = context.getProperty(EXTERNAL_ID_PROPERTY, String::class.java).orElse("") + + return accessKey.isNotEmpty() && secretKey.isNotEmpty() && externalId.isNotEmpty() + } +} diff --git a/airbyte-integrations/connectors/destination-s3/metadata.yaml b/airbyte-integrations/connectors/destination-s3/metadata.yaml index ab469471c635c..0632ee134f2f2 100644 --- a/airbyte-integrations/connectors/destination-s3/metadata.yaml +++ b/airbyte-integrations/connectors/destination-s3/metadata.yaml @@ -2,7 +2,7 @@ data: connectorSubtype: file connectorType: destination definitionId: 4816b78f-1489-44c1-9060-4b19d5fa9362 - dockerImageTag: 1.5.0-rc.15 + dockerImageTag: 1.5.0-rc.16 dockerRepository: airbyte/destination-s3 githubIssueLabel: destination-s3 icon: s3.svg diff --git a/docs/integrations/destinations/s3.md b/docs/integrations/destinations/s3.md index bbc10bcf7260f..88a5a64b79681 100644 --- a/docs/integrations/destinations/s3.md +++ b/docs/integrations/destinations/s3.md @@ -544,7 +544,8 @@ To see connector limitations, or troubleshoot your S3 connector, see more [in ou | Version | Date | Pull Request | Subject | |:------------|:-----------|:-----------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------| -| 1.5.0-rc.15 | 2025-01-23 | [52103](https://github.com/airbytehq/airbyte/pull/52103) | Make the connector use our non root base image. | +| 1.5.0-rc.16 | 2025-01-29 | [52610](https://github.com/airbytehq/airbyte/pull/52610) | Fix assume role behavior | +| 1.5.0-rc.15 | 2025-01-23 | [52103](https://github.com/airbytehq/airbyte/pull/52103) | Make the connector use our non root base image. | | 1.5.0-rc.14 | 2025-01-24 | [51600](https://github.com/airbytehq/airbyte/pull/51600) | Internal refactor | | 1.5.0-rc.13 | 2025-01-22 | [52076](https://github.com/airbytehq/airbyte/pull/52076) | Test improvements. | | 1.5.0-rc.12 | 2025-01-22 | [52072](https://github.com/airbytehq/airbyte/pull/52072) | Bug fix: Configure OpenStreamTask concurrency to handle connection to reduce http connection errors. |