Search in sources :

Example 1 with ImpersonatorInterceptor

use of io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor in project che-server by eclipse-che.

the class OpenShiftClientFactory method clientForConfig.

private OkHttpClient clientForConfig(Config config) {
    OkHttpClient clientHttpClient = getHttpClient().newBuilder().authenticator(Authenticator.NONE).build();
    OkHttpClient.Builder builder = clientHttpClient.newBuilder();
    builder.interceptors().clear();
    return builder.addInterceptor(new OpenShiftOAuthInterceptor(clientHttpClient, OpenShiftConfig.wrap(config))).addInterceptor(new ImpersonatorInterceptor(config)).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ImpersonatorInterceptor(io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor) OpenShiftOAuthInterceptor(io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor)

Example 2 with ImpersonatorInterceptor

use of io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor in project che-server by eclipse-che.

the class KubernetesClientFactory method create.

/**
 * Creates instance of {@link KubernetesClient} that uses an {@link OkHttpClient} instance derived
 * from the shared {@code httpClient} instance in which interceptors are overridden to
 * authenticate with the credentials (user/password or Oauth token) contained in the {@code
 * config} parameter.
 */
protected BaseKubernetesClient<?> create(Config config) {
    OkHttpClient clientHttpClient = httpClient.newBuilder().authenticator(Authenticator.NONE).build();
    OkHttpClient.Builder builder = clientHttpClient.newBuilder();
    builder.interceptors().clear();
    builder.addInterceptor(buildKubernetesInterceptor(config)).addInterceptor(new ImpersonatorInterceptor(config));
    initializeRequestTracing(builder);
    clientHttpClient = builder.build();
    return new UnclosableKubernetesClient(clientHttpClient, config);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ImpersonatorInterceptor(io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor)

Example 3 with ImpersonatorInterceptor

use of io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor in project devspaces-images by redhat-developer.

the class KubernetesClientFactory method create.

/**
 * Creates instance of {@link KubernetesClient} that uses an {@link OkHttpClient} instance derived
 * from the shared {@code httpClient} instance in which interceptors are overridden to
 * authenticate with the credentials (user/password or Oauth token) contained in the {@code
 * config} parameter.
 */
protected BaseKubernetesClient<?> create(Config config) {
    OkHttpClient clientHttpClient = httpClient.newBuilder().authenticator(Authenticator.NONE).build();
    OkHttpClient.Builder builder = clientHttpClient.newBuilder();
    builder.interceptors().clear();
    builder.addInterceptor(buildKubernetesInterceptor(config)).addInterceptor(new ImpersonatorInterceptor(config));
    initializeRequestTracing(builder);
    clientHttpClient = builder.build();
    return new UnclosableKubernetesClient(clientHttpClient, config);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ImpersonatorInterceptor(io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor)

Example 4 with ImpersonatorInterceptor

use of io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor 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 5 with ImpersonatorInterceptor

use of io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor in project devspaces-images by redhat-developer.

the class OpenShiftClientFactory method clientForConfig.

private OkHttpClient clientForConfig(Config config) {
    OkHttpClient clientHttpClient = getHttpClient().newBuilder().authenticator(Authenticator.NONE).build();
    OkHttpClient.Builder builder = clientHttpClient.newBuilder();
    builder.interceptors().clear();
    return builder.addInterceptor(new OpenShiftOAuthInterceptor(clientHttpClient, OpenShiftConfig.wrap(config))).addInterceptor(new ImpersonatorInterceptor(config)).build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ImpersonatorInterceptor(io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor) OpenShiftOAuthInterceptor(io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor)

Aggregations

ImpersonatorInterceptor (io.fabric8.kubernetes.client.utils.ImpersonatorInterceptor)4 OkHttpClient (okhttp3.OkHttpClient)4 OpenShiftOAuthInterceptor (io.fabric8.openshift.client.internal.OpenShiftOAuthInterceptor)2 BasicBuilder (io.fabric8.kubernetes.client.http.BasicBuilder)1 HttpHeaders (io.fabric8.kubernetes.client.http.HttpHeaders)1 Interceptor (io.fabric8.kubernetes.client.http.Interceptor)1 LinkedHashMap (java.util.LinkedHashMap)1