use of io.fabric8.kubernetes.client.http.HttpHeaders in project kubernetes-client by fabric8io.
the class HttpClientUtils method createApplicableInterceptors.
public static Map<String, io.fabric8.kubernetes.client.http.Interceptor> createApplicableInterceptors(Config config, HttpClient.Factory factory) {
Map<String, io.fabric8.kubernetes.client.http.Interceptor> interceptors = new LinkedHashMap<>();
// Header Interceptor
interceptors.put(HEADER_INTERCEPTOR, new Interceptor() {
@Override
public void before(BasicBuilder builder, HttpHeaders headers) {
if (Utils.isNotNullOrEmpty(config.getUsername()) && Utils.isNotNullOrEmpty(config.getPassword())) {
builder.header("Authorization", basicCredentials(config.getUsername(), config.getPassword()));
} else if (Utils.isNotNullOrEmpty(config.getOauthToken())) {
builder.header("Authorization", "Bearer " + config.getOauthToken());
}
if (config.getCustomHeaders() != null && !config.getCustomHeaders().isEmpty()) {
for (Map.Entry<String, String> entry : config.getCustomHeaders().entrySet()) {
builder.header(entry.getKey(), entry.getValue());
}
}
if (config.getUserAgent() != null && !config.getUserAgent().isEmpty()) {
builder.setHeader("User-Agent", config.getUserAgent());
}
}
});
// Impersonator Interceptor
interceptors.put(ImpersonatorInterceptor.NAME, new ImpersonatorInterceptor(config));
// Token Refresh Interceptor
interceptors.put(TokenRefreshInterceptor.NAME, new TokenRefreshInterceptor(config, factory));
// Backwards Compatibility Interceptor
String shouldDisableBackwardsCompatibilityInterceptor = Utils.getSystemPropertyOrEnvVar(KUBERNETES_BACKWARDS_COMPATIBILITY_INTERCEPTOR_DISABLE, "false");
if (!Boolean.parseBoolean(shouldDisableBackwardsCompatibilityInterceptor)) {
interceptors.put(BackwardsCompatibilityInterceptor.NAME, new BackwardsCompatibilityInterceptor());
}
return interceptors;
}
use of io.fabric8.kubernetes.client.http.HttpHeaders in project kubernetes-client by fabric8io.
the class JdkHttpClientBuilderImpl method build.
@Override
public HttpClient build() {
if (httpClient != null) {
return new JdkHttpClientImpl(this, httpClient);
}
java.net.http.HttpClient.Builder builder = clientFactory.createNewHttpClientBuilder();
if (connectTimeout != null) {
builder.connectTimeout(connectTimeout);
}
if (sslContext != null) {
builder.sslContext(sslContext);
}
if (followRedirects) {
builder.followRedirects(Redirect.ALWAYS);
}
if (proxyAddress != null) {
builder.proxy(ProxySelector.of(proxyAddress));
} else {
builder.proxy(java.net.http.HttpClient.Builder.NO_PROXY);
}
if (proxyAuthorization != null) {
this.interceptors.put("PROXY-AUTH", new Interceptor() {
@Override
public void before(BasicBuilder builder, HttpHeaders headers) {
builder.setHeader("Proxy-Authorization", proxyAuthorization);
}
});
}
if (preferHttp11) {
builder.version(Version.HTTP_1_1);
}
if (tlsVersions != null && tlsVersions.length > 0) {
builder.sslParameters(new SSLParameters(null, Arrays.asList(tlsVersions).stream().map(TlsVersion::javaName).toArray(String[]::new)));
}
clientFactory.additionalConfig(builder);
return new JdkHttpClientImpl(this, builder.build());
}
use of io.fabric8.kubernetes.client.http.HttpHeaders in project kubernetes-client by fabric8io.
the class ImpersonatorInterceptor method before.
@Override
public void before(BasicBuilder builder, HttpHeaders headers) {
RequestConfig requestConfig = config.getRequestConfig();
if (isNotNullOrEmpty(requestConfig.getImpersonateUsername())) {
builder.header("Impersonate-User", requestConfig.getImpersonateUsername());
String[] impersonateGroups = requestConfig.getImpersonateGroups();
if (isNotNullOrEmpty(impersonateGroups)) {
for (String group : impersonateGroups) {
builder.header("Impersonate-Group", group);
}
}
Map<String, List<String>> impersonateExtras = requestConfig.getImpersonateExtras();
if (isNotNullOrEmpty(impersonateExtras)) {
Collection<?> keys = impersonateExtras.keySet();
for (Object key : keys) {
List<String> values = impersonateExtras.get(key);
if (values != null) {
for (String value : values) {
builder.header("Impersonate-Extra-" + key, value);
}
}
}
}
}
}
use of io.fabric8.kubernetes.client.http.HttpHeaders in project jkube by eclipse.
the class ProbeHandler method getHTTPGetAction.
// ========================================================================================
private HTTPGetAction getHTTPGetAction(String getUrl, Map<String, String> headers) {
if (getUrl == null || !getUrl.subSequence(0, 4).toString().equalsIgnoreCase("http")) {
return null;
}
try {
URL url = new URL(getUrl);
List<HTTPHeader> httpHeaders = convertMapToHTTPHeaderList(headers);
return new HTTPGetAction(url.getHost(), httpHeaders.isEmpty() ? null : httpHeaders, url.getPath(), new IntOrString(url.getPort()), url.getProtocol().toUpperCase());
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid URL " + getUrl + " given for HTTP GET readiness check");
}
}
Aggregations