use of io.fabric8.kubernetes.client.http.HttpClient 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);
}
use of io.fabric8.kubernetes.client.http.HttpClient 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);
}
use of io.fabric8.kubernetes.client.http.HttpClient in project kubernetes-client by fabric8io.
the class OpenIDConnectionUtils method getOIDCDiscoveryDocumentAsMap.
/**
* OpenID providers publish their metadata at a well-known URL OpenID providers publish their metadata
* at a well-known URL which looks like this: https://[base-server-url]/.well-known/openid-configuration
* This method performs an Http Get at this public URL and fetches response as a HashMap
*
* @param client HttpClient for doing HTTP Get to well known URL of OpenID provider
* @param issuer OpenID Connect provider issuer URL
* @return a HashMap of Discovery document
*/
static Map<String, Object> getOIDCDiscoveryDocumentAsMap(HttpClient client, String issuer) {
HttpRequest request = client.newHttpRequestBuilder().uri(getWellKnownUrlForOpenIDIssuer(issuer)).build();
try {
HttpResponse<String> response = client.send(request, String.class);
if (response.isSuccessful() && response.body() != null) {
return convertJsonStringToMap(response.body());
} else {
// Don't produce an error that's too huge (e.g. if we get HTML back for some reason).
String responseBody = response.body();
LOGGER.warn("oidc: failed to query metadata endpoint: {} {}", response.code(), responseBody);
}
} catch (IOException e) {
LOGGER.warn("Could not refresh OIDC token, failure in getting refresh URL", e);
}
return Collections.emptyMap();
}
use of io.fabric8.kubernetes.client.http.HttpClient in project kubernetes-client by fabric8io.
the class OpenIDConnectionUtils method refreshOidcToken.
/**
* Issue Token Refresh HTTP Request to OIDC Provider
*
* @param client Http Client for issuing HTTP request
* @param clientId client id
* @param refreshToken refresh token
* @param clientSecret client secret
* @param tokenURL OpenID Connection provider's token refresh url
* @return response as HashMap
* @throws IOException in case of any error in contacting OIDC provider
*/
static Map<String, Object> refreshOidcToken(HttpClient client, String clientId, String refreshToken, String clientSecret, String tokenURL) throws IOException {
HttpRequest request = getTokenRefreshHttpRequest(client, tokenURL, clientId, refreshToken, clientSecret);
HttpResponse<String> response = client.send(request, String.class);
String body = response.body();
if (body != null) {
// Get response body as string
if (response.isSuccessful()) {
// Deserialize response body into a Map and return
return convertJsonStringToMap(body);
} else {
// Log error response body
LOGGER.warn("Response: {}", body);
}
}
return Collections.emptyMap();
}
use of io.fabric8.kubernetes.client.http.HttpClient in project kubernetes-client by fabric8io.
the class BaseOperationTest method testHttpRetryWithLessFailuresThanRetries.
@Test
void testHttpRetryWithLessFailuresThanRetries() throws MalformedURLException, IOException {
final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 2);
BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").withRequestRetryBackoffLimit(3).build()).withPlural("pods").withName("test-pod").withHttpClient(mockClient));
baseOp.setType(Pod.class);
// When
Pod result = baseOp.get();
// Then
assertNotNull(result);
assertEquals(3, httpExecutionCounter.get(), "Expected 3 calls: 2 failures and 1 success!");
}
Aggregations