in kyuubi-relocated-hive-metastore-client/src/main/java/org/apache/kyuubi/shaded/hive/metastore/HiveMetaStoreClient.java [349:396]
protected HttpClientBuilder createHttpClientBuilder() throws MetaException {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
String authType = MetastoreConf.getVar(conf, ConfVars.METASTORE_CLIENT_AUTH_MODE);
Map<String, String> additionalHeaders = getAdditionalHeaders();
if (authType.equalsIgnoreCase("jwt")) {
// fetch JWT token from environment and set it in Auth Header in HTTP request
String jwtToken = System.getenv("HMS_JWT");
if (jwtToken == null || jwtToken.isEmpty()) {
LOG.debug("No jwt token set in environment variable: HMS_JWT");
throw new MetaException(
"For auth mode JWT, valid signed jwt token must be provided in the "
+ "environment variable HMS_JWT");
}
httpClientBuilder.addInterceptorFirst(
new HttpRequestInterceptor() {
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext)
throws HttpException, IOException {
httpRequest.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + jwtToken);
for (Map.Entry<String, String> entry : additionalHeaders.entrySet()) {
httpRequest.addHeader(entry.getKey(), entry.getValue());
}
}
});
} else {
String user = MetastoreConf.getVar(conf, ConfVars.METASTORE_CLIENT_PLAIN_USERNAME);
if (user == null || user.equals("")) {
try {
user = UserGroupInformation.getCurrentUser().getShortUserName();
} catch (IOException e) {
throw new MetaException("Failed to get client username from UGI");
}
}
final String httpUser = user;
httpClientBuilder.addInterceptorFirst(
new HttpRequestInterceptor() {
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext)
throws HttpException, IOException {
httpRequest.addHeader(MetaStoreUtils.USER_NAME_HTTP_HEADER, httpUser);
for (Map.Entry<String, String> entry : additionalHeaders.entrySet()) {
httpRequest.addHeader(entry.getKey(), entry.getValue());
}
}
});
}
return httpClientBuilder;
}