-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Parker Mossman <[email protected]>
- Loading branch information
Showing
36 changed files
with
605 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...mons-micronaut/src/main/kotlin/io/airbyte/micronaut/config/EditionPropertySourceLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.airbyte.micronaut.config | ||
|
||
import io.micronaut.context.env.AbstractPropertySourceLoader | ||
import io.micronaut.context.env.PropertySource | ||
import io.micronaut.context.env.yaml.YamlPropertySourceLoader | ||
import io.micronaut.core.io.ResourceLoader | ||
import java.util.Optional | ||
|
||
/** | ||
* Loads properties based on the edition of Airbyte. | ||
* Looks for a file named `application-edition-<edition>.yml` where `<edition>` is the value of the | ||
* `AIRBYTE_EDITION` environment variable. | ||
* This loader is registered in META-INF/services/io.micronaut.context.env.PropertySourceLoader | ||
* so that it is automatically picked up by Micronaut. | ||
*/ | ||
class EditionPropertySourceLoader( | ||
private val airbyteEdition: String? = System.getenv(AIRBYTE_EDITION_ENV_VAR), | ||
) : YamlPropertySourceLoader() { | ||
companion object { | ||
const val AIRBYTE_EDITION_ENV_VAR = "AIRBYTE_EDITION" | ||
} | ||
|
||
override fun getOrder(): Int = AbstractPropertySourceLoader.DEFAULT_POSITION + 10 | ||
|
||
override fun load( | ||
name: String?, | ||
resourceLoader: ResourceLoader?, | ||
): Optional<PropertySource> { | ||
if (airbyteEdition.isNullOrEmpty()) { | ||
return Optional.empty() | ||
} | ||
|
||
val fileName = "application-edition-" + airbyteEdition.lowercase() | ||
return super.load(fileName, resourceLoader) | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...ronaut/src/main/resources/META-INF/services/io.micronaut.context.env.PropertySourceLoader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
io.airbyte.micronaut.config.AirbytePropertySourceLoader | ||
io.airbyte.micronaut.config.AirbytePropertySourceLoader | ||
io.airbyte.micronaut.config.EditionPropertySourceLoader |
43 changes: 43 additions & 0 deletions
43
...-micronaut/src/test/kotlin/io/airbyte/micronaut/config/EditionPropertySourceLoaderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.airbyte.micronaut.config | ||
|
||
import io.micronaut.core.io.ResourceLoader | ||
import io.mockk.Called | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
|
||
class EditionPropertySourceLoaderTest { | ||
private val resourceLoader = mockk<ResourceLoader>(relaxed = true) | ||
|
||
@Test | ||
fun `should return empty optional when AIRBYTE_EDITION is not set`() { | ||
val loader = EditionPropertySourceLoader(null) | ||
|
||
val result = loader.load("test", resourceLoader) | ||
|
||
assertTrue(result.isEmpty) | ||
verify { resourceLoader wasNot Called } | ||
} | ||
|
||
@Test | ||
fun `should return empty optional when AIRBYTE_EDITION is empty`() { | ||
val loader = EditionPropertySourceLoader("") | ||
|
||
val result = loader.load("test", resourceLoader) | ||
|
||
assertTrue(result.isEmpty) | ||
verify { resourceLoader wasNot Called } | ||
} | ||
|
||
@Test | ||
fun `should attempt to load correct file when AIRBYTE_EDITION is set`() { | ||
val loader = EditionPropertySourceLoader("community") | ||
|
||
loader.load("test", resourceLoader) | ||
|
||
// ensures underlying loader is called with correct file name and extensions | ||
verify { resourceLoader.getResourceAsStream("application-edition-community.yml") } | ||
verify { resourceLoader.getResourceAsStream("application-edition-community.yaml") } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...c/main/kotlin/io/airbyte/server/config/community/auth/CommunityAuthLogoutEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.airbyte.server.config.community.auth | ||
|
||
import io.airbyte.api.problems.model.generated.ProblemMessageData | ||
import io.airbyte.api.problems.throwable.generated.UnprocessableEntityProblem | ||
import io.airbyte.data.services.AuthRefreshTokenService | ||
import io.micronaut.context.event.ApplicationEventListener | ||
import io.micronaut.security.authentication.Authentication | ||
import io.micronaut.security.event.LogoutEvent | ||
import jakarta.inject.Singleton | ||
|
||
@Singleton | ||
class CommunityAuthLogoutEventListener( | ||
private val refreshTokenService: AuthRefreshTokenService, | ||
) : ApplicationEventListener<LogoutEvent> { | ||
override fun onApplicationEvent(event: LogoutEvent) { | ||
val sessionId = | ||
(event.source as? Authentication) | ||
?.attributes | ||
?.get(SESSION_ID) | ||
?.toString() | ||
?: throw UnprocessableEntityProblem(ProblemMessageData().message("Could not retrieve session ID from authentication context")) | ||
|
||
refreshTokenService.revokeAuthRefreshToken(sessionId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.