This is an automated email from the ASF dual-hosted git repository.
dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 0b0cee641f [INLONG-8281][Manager] Add the tenant request header when
initializing the manager-client (#8291)
0b0cee641f is described below
commit 0b0cee641fc6c5ca9420a6db06ad2898191535e0
Author: castorqin <[email protected]>
AuthorDate: Sun Jun 25 11:02:24 2023 +0800
[INLONG-8281][Manager] Add the tenant request header when initializing the
manager-client (#8291)
Co-authored-by: castorqin <[email protected]>
---
.../org/apache/inlong/manager/client/api/ClientConfiguration.java | 2 ++
.../apache/inlong/manager/client/api/service/AuthInterceptor.java | 8 +++++---
.../org/apache/inlong/manager/client/api/util/ClientUtils.java | 3 ++-
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/ClientConfiguration.java
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/ClientConfiguration.java
index 4dcd689c1e..08750785ef 100644
---
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/ClientConfiguration.java
+++
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/ClientConfiguration.java
@@ -53,4 +53,6 @@ public class ClientConfiguration implements Serializable {
private boolean isUseTls = false;
private boolean retryOnConnectionFailure = true;
+
+ private String tenant = "public";
}
diff --git
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/AuthInterceptor.java
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/AuthInterceptor.java
index 822515bc02..d86edf8634 100644
---
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/AuthInterceptor.java
+++
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/AuthInterceptor.java
@@ -23,7 +23,7 @@ import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
-
+import java.util.function.Supplier;
/**
* AuthInterceptor
* Before okhttp call a request, uniformly encapsulate the relevant parameters
of authentication
@@ -32,10 +32,12 @@ public class AuthInterceptor implements Interceptor {
private final String username;
private final String password;
+ private final Supplier<String> tenantGetter;
- public AuthInterceptor(String username, String password) {
+ public AuthInterceptor(String username, String password, Supplier<String>
tenantGetter) {
this.username = username;
this.password = password;
+ this.tenantGetter = tenantGetter;
}
@Override
@@ -49,8 +51,8 @@ public class AuthInterceptor implements Interceptor {
Request newRequest = oldRequest.newBuilder()
.method(oldRequest.method(), oldRequest.body())
.url(builder.build())
+ .addHeader("tenant", tenantGetter.get())
.build();
-
return chain.proceed(newRequest);
}
}
diff --git
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/ClientUtils.java
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/ClientUtils.java
index ceaeca92ff..df4fdeb4e4 100644
---
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/ClientUtils.java
+++
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/ClientUtils.java
@@ -76,7 +76,8 @@ public class ClientUtils {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(
- new
AuthInterceptor(defaultAuthentication.getUsername(),
defaultAuthentication.getPassword()))
+ new
AuthInterceptor(defaultAuthentication.getUsername(),
defaultAuthentication.getPassword(),
+ configuration::getTenant))
.connectTimeout(configuration.getConnectTimeout(),
configuration.getTimeUnit())
.readTimeout(configuration.getReadTimeout(),
configuration.getTimeUnit())
.writeTimeout(configuration.getWriteTimeout(),
configuration.getTimeUnit())