Search in sources :

Example 1 with HttpHeaders

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;
}
Also used : HttpHeaders(io.fabric8.kubernetes.client.http.HttpHeaders) LinkedHashMap(java.util.LinkedHashMap) BasicBuilder(io.fabric8.kubernetes.client.http.BasicBuilder) Interceptor(io.fabric8.kubernetes.client.http.Interceptor)

Example 2 with HttpHeaders

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());
}
Also used : HttpHeaders(io.fabric8.kubernetes.client.http.HttpHeaders) SSLParameters(javax.net.ssl.SSLParameters) HttpClient(io.fabric8.kubernetes.client.http.HttpClient) BasicBuilder(io.fabric8.kubernetes.client.http.BasicBuilder) Interceptor(io.fabric8.kubernetes.client.http.Interceptor)

Example 3 with HttpHeaders

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);
                    }
                }
            }
        }
    }
}
Also used : RequestConfig(io.fabric8.kubernetes.client.RequestConfig) List(java.util.List)

Example 4 with HttpHeaders

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");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) URL(java.net.URL) HTTPHeader(io.fabric8.kubernetes.api.model.HTTPHeader) HTTPGetAction(io.fabric8.kubernetes.api.model.HTTPGetAction)

Aggregations

BasicBuilder (io.fabric8.kubernetes.client.http.BasicBuilder)2 HttpHeaders (io.fabric8.kubernetes.client.http.HttpHeaders)2 Interceptor (io.fabric8.kubernetes.client.http.Interceptor)2 HTTPGetAction (io.fabric8.kubernetes.api.model.HTTPGetAction)1 HTTPHeader (io.fabric8.kubernetes.api.model.HTTPHeader)1 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 RequestConfig (io.fabric8.kubernetes.client.RequestConfig)1 HttpClient (io.fabric8.kubernetes.client.http.HttpClient)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 SSLParameters (javax.net.ssl.SSLParameters)1