12
12
import io .airbyte .config .Configs .WorkerPlane ;
13
13
import io .micronaut .context .annotation .Factory ;
14
14
import io .micronaut .context .annotation .Value ;
15
+ import io .micronaut .context .annotation .Prototype ;
15
16
import java .io .FileInputStream ;
16
17
import java .net .http .HttpClient ;
17
18
import java .net .http .HttpClient .Version ;
21
22
import javax .inject .Named ;
22
23
import javax .inject .Singleton ;
23
24
import lombok .extern .slf4j .Slf4j ;
25
+ import io .micronaut .context .BeanProvider ;
26
+
24
27
25
28
/**
26
29
* Micronaut bean factory for API client singletons.
@@ -35,7 +38,7 @@ public class ApiClientBeanFactory {
35
38
public AirbyteApiClient airbyteApiClient (
36
39
@ Value ("${airbyte.internal.api.auth-header.name}" ) final String airbyteApiAuthHeaderName ,
37
40
@ Value ("${airbyte.internal.api.host}" ) final String airbyteApiHost ,
38
- @ Named ("internalApiAuthToken" ) final String internalApiAuthToken ,
41
+ @ Named ("internalApiAuthToken" ) final BeanProvider < String > internalApiAuthToken ,
39
42
@ Named ("internalApiScheme" ) final String internalApiScheme ) {
40
43
return new AirbyteApiClient (
41
44
new io .airbyte .api .client .invoker .generated .ApiClient ()
@@ -46,8 +49,10 @@ public AirbyteApiClient airbyteApiClient(
46
49
.setHttpClientBuilder (HttpClient .newBuilder ().version (Version .HTTP_1_1 ))
47
50
.setRequestInterceptor (builder -> {
48
51
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.
49
54
if (!airbyteApiAuthHeaderName .isBlank ()) {
50
- builder .setHeader (airbyteApiAuthHeaderName , internalApiAuthToken );
55
+ builder .setHeader (airbyteApiAuthHeaderName , internalApiAuthToken . get () );
51
56
}
52
57
}));
53
58
}
@@ -62,14 +67,15 @@ public String internalApiScheme(final WorkerPlane workerPlane) {
62
67
63
68
/**
64
69
* 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.
66
72
* <p>
67
73
* For Data Plane workers, generate a signed JWT as described here:
68
74
* https://cloud.google.com/endpoints/docs/openapi/service-account-authentication
69
75
* <p>
70
76
* Otherwise, use the AIRBYTE_API_AUTH_HEADER_VALUE from EnvConfigs.
71
77
*/
72
- @ Singleton
78
+ @ Prototype
73
79
@ Named ("internalApiAuthToken" )
74
80
public String internalApiAuthToken (
75
81
@ Value ("${airbyte.internal.api.auth-header.value}" ) final String airbyteApiAuthHeaderValue ,
0 commit comments