Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhu2000 authored Jan 10, 2025
2 parents 42d07b5 + 2161b87 commit c21f0d2
Show file tree
Hide file tree
Showing 2,501 changed files with 203,376 additions and 165,539 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you have any question regarding licenses, just visit our [FAQ](https://airbyt
------------------------------------------------------------------------------------
MIT License

Copyright (c) 2020-2024 Airbyte, Inc.
Copyright (c) 2020-2025 Airbyte, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion LICENSE_SHORT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package io.airbyte.analytics

import io.airbyte.config.ScopeType
import jakarta.inject.Singleton
import java.util.UUID

private const val ACTION_GRACE_PERIOD_STARTED = "grace_period_started"
private const val ACTION_GRACE_PERIOD_ENDED = "grace_period_ended"
private const val ACTION_GRACE_PERIOD_UPDATED = "grace_period_updated"
private const val ACTION_GRACE_PERIOD_CANCELED = "grace_period_canceled"
private const val ACTION_PAYMENT_SETUP_COMPLETED = "payment_setup_completed"
private const val METADATA_GRACE_PERIOD_END_AT_SECONDS = "grace_period_end_at_seconds"
private const val METADATA_REASON = "reason"
private const val METADATA_PAYMENT_PROVIDER_ID = "payment_provider_id"

/**
* This helper provides convenience wrappers around the tracking client for billing-related events.
*/
@Singleton
class BillingTrackingHelper(
private val trackingClient: TrackingClient,
) {
fun trackGracePeriodStarted(
organizationId: UUID,
paymentProviderId: String,
gracePeriodEndAtSeconds: Long,
reason: String,
) {
trackingClient.track(
organizationId,
ScopeType.ORGANIZATION,
ACTION_GRACE_PERIOD_STARTED,
mapOf(
METADATA_PAYMENT_PROVIDER_ID to paymentProviderId,
METADATA_GRACE_PERIOD_END_AT_SECONDS to gracePeriodEndAtSeconds.toString(),
METADATA_REASON to reason,
),
)
}

fun trackGracePeriodEnded(
organizationId: UUID,
paymentProviderId: String,
) {
trackingClient.track(
organizationId,
ScopeType.ORGANIZATION,
ACTION_GRACE_PERIOD_ENDED,
mapOf(
METADATA_PAYMENT_PROVIDER_ID to paymentProviderId,
),
)
}

fun trackGracePeriodUpdated(
organizationId: UUID,
paymentProviderId: String,
gracePeriodEndAtSeconds: Long,
) {
trackingClient.track(
organizationId,
ScopeType.ORGANIZATION,
ACTION_GRACE_PERIOD_UPDATED,
mapOf(
METADATA_PAYMENT_PROVIDER_ID to paymentProviderId,
METADATA_GRACE_PERIOD_END_AT_SECONDS to gracePeriodEndAtSeconds.toString(),
),
)
}

fun trackGracePeriodCanceled(
organizationId: UUID,
paymentProviderId: String,
reason: String,
) {
trackingClient.track(
organizationId,
ScopeType.ORGANIZATION,
ACTION_GRACE_PERIOD_CANCELED,
mapOf(
METADATA_PAYMENT_PROVIDER_ID to paymentProviderId,
METADATA_REASON to reason,
),
)
}

fun trackPaymentSetupCompleted(
organizationId: UUID,
paymentProviderId: String,
) {
trackingClient.track(
organizationId,
ScopeType.ORGANIZATION,
ACTION_PAYMENT_SETUP_COMPLETED,
mapOf(
METADATA_PAYMENT_PROVIDER_ID to paymentProviderId,
),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.analytics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.analytics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.analytics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.analytics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.analytics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.analytics
Expand Down
36 changes: 17 additions & 19 deletions airbyte-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@ plugins {
id("io.airbyte.gradle.jvm.lib")
}

airbyte {
spotless {
excludes = listOf(
project(":oss:airbyte-api:workload-api").file("src/main/openapi/workload-openapi.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api.yaml").path,

project(":oss:airbyte-api:server-api").file("src/main/openapi/api_sdk.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_terraform.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_connections.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_sources.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_destinations.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_streams.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_jobs.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_workspaces.yaml").path,
)
}
dependencies {
project.subprojects.forEach { implementation(project(it.path)) }
}

dependencies {
project.subprojects.forEach { subProject ->
implementation(project(subProject.path))
airbyte {
spotless {
excludes =
listOf(
project(":oss:airbyte-api:workload-api").file("src/main/openapi/workload-openapi.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_sdk.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_terraform.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_connections.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_sources.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_destinations.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_streams.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_jobs.yaml").path,
project(":oss:airbyte-api:server-api").file("src/main/openapi/api_documentation_workspaces.yaml").path,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.api.client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.api.client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.api.client.auth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.api.client.auth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.api.client.auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package io.airbyte.api.client.auth
import io.github.oshai.kotlinlogging.KotlinLogging
import io.micronaut.context.annotation.Requires
import io.micronaut.http.HttpHeaders
import io.micronaut.http.exceptions.HttpException
import io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsClient
import jakarta.inject.Named
import jakarta.inject.Singleton
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import reactor.core.publisher.Mono
import reactor.util.retry.Retry
import java.time.Duration

private val logger = KotlinLogging.logger {}

Expand All @@ -26,25 +29,36 @@ private val logger = KotlinLogging.logger {}
class KeycloakAccessTokenInterceptor(
@Named("keycloak") private val clientCredentialsClient: ClientCredentialsClient,
) : AirbyteApiInterceptor {
override fun intercept(chain: Interceptor.Chain): Response =
private fun fetchAccessToken(): Mono<String?> {
return Mono.defer { Mono.from(clientCredentialsClient.requestToken()) }
.map { it.accessToken }
.retryWhen(
Retry
.backoff(3, Duration.ofSeconds(1))
.filter { it is HttpException },
)
}

override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest: Request = chain.request()
val builder: Request.Builder = originalRequest.newBuilder()

try {
logger.debug { "Intercepting request to add Keycloak access token..." }
val originalRequest: Request = chain.request()
val builder: Request.Builder = originalRequest.newBuilder()
val tokenResponse = Mono.from(clientCredentialsClient.requestToken()).block()
val accessToken = tokenResponse?.accessToken
val accessToken = fetchAccessToken().block()
if (accessToken != null) {
builder.addHeader(HttpHeaders.AUTHORIZATION, "Bearer $accessToken")
logger.debug { "Added access token to header $accessToken" }
chain.proceed(builder.build())
} else {
logger.error { "Failed to obtain access token from Keycloak" }
chain.proceed(originalRequest)
}
} catch (e: Exception) {
logger.error(e) { "Failed to add Keycloak access token to request" }
// do not throw exception, just proceed with the original request and let the request fail
// authorization downstream.
chain.proceed(chain.request())
return chain.proceed(originalRequest)
}

return chain.proceed(builder.build())
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
* Copyright (c) 2020-2025 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.api.client.config
Expand Down
Loading

0 comments on commit c21f0d2

Please sign in to comment.