Skip to content

Commit f1524e0

Browse files
authored
use prototype for jwt signature because we need a new one (#16789)
* use prototype for jwt signature because we need a new one * add comments on why using provider and prototype:
1 parent 5d490de commit f1524e0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

airbyte-workers/src/main/java/io/airbyte/workers/config/ApiClientBeanFactory.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.airbyte.config.Configs.WorkerPlane;
1313
import io.micronaut.context.annotation.Factory;
1414
import io.micronaut.context.annotation.Value;
15+
import io.micronaut.context.annotation.Prototype;
1516
import java.io.FileInputStream;
1617
import java.net.http.HttpClient;
1718
import java.net.http.HttpClient.Version;
@@ -21,6 +22,8 @@
2122
import javax.inject.Named;
2223
import javax.inject.Singleton;
2324
import lombok.extern.slf4j.Slf4j;
25+
import io.micronaut.context.BeanProvider;
26+
2427

2528
/**
2629
* Micronaut bean factory for API client singletons.
@@ -35,7 +38,7 @@ public class ApiClientBeanFactory {
3538
public AirbyteApiClient airbyteApiClient(
3639
@Value("${airbyte.internal.api.auth-header.name}") final String airbyteApiAuthHeaderName,
3740
@Value("${airbyte.internal.api.host}") final String airbyteApiHost,
38-
@Named("internalApiAuthToken") final String internalApiAuthToken,
41+
@Named("internalApiAuthToken") final BeanProvider<String> internalApiAuthToken,
3942
@Named("internalApiScheme") final String internalApiScheme) {
4043
return new AirbyteApiClient(
4144
new io.airbyte.api.client.invoker.generated.ApiClient()
@@ -46,8 +49,10 @@ public AirbyteApiClient airbyteApiClient(
4649
.setHttpClientBuilder(HttpClient.newBuilder().version(Version.HTTP_1_1))
4750
.setRequestInterceptor(builder -> {
4851
builder.setHeader("User-Agent", "WorkerApp");
52+
// internalApiAuthToken is in BeanProvider because we want to create a new token each
53+
// time we send a request.
4954
if (!airbyteApiAuthHeaderName.isBlank()) {
50-
builder.setHeader(airbyteApiAuthHeaderName, internalApiAuthToken);
55+
builder.setHeader(airbyteApiAuthHeaderName, internalApiAuthToken.get());
5156
}
5257
}));
5358
}
@@ -62,14 +67,15 @@ public String internalApiScheme(final WorkerPlane workerPlane) {
6267

6368
/**
6469
* Generate an auth token based on configs. This is called by the Api Client's requestInterceptor
65-
* for each request.
70+
* for each request. Using Prototype annotation here to make sure each time it's used it will
71+
* generate a new JWT Signature if it's on data plane.
6672
* <p>
6773
* For Data Plane workers, generate a signed JWT as described here:
6874
* https://cloud.google.com/endpoints/docs/openapi/service-account-authentication
6975
* <p>
7076
* Otherwise, use the AIRBYTE_API_AUTH_HEADER_VALUE from EnvConfigs.
7177
*/
72-
@Singleton
78+
@Prototype
7379
@Named("internalApiAuthToken")
7480
public String internalApiAuthToken(
7581
@Value("${airbyte.internal.api.auth-header.value}") final String airbyteApiAuthHeaderValue,

0 commit comments

Comments
 (0)