use of io.fabric8.kubernetes.client.RequestConfig in project kubernetes-client by fabric8io.
the class UserImpersonationIT method should_be_able_to_create_a_project_impersonating_service_account.
@Test
public void should_be_able_to_create_a_project_impersonating_service_account() {
RequestConfig requestConfig = new RequestConfigBuilder().withImpersonateUsername(SERVICE_ACCOUNT).withImpersonateGroups("system:authenticated", "system:authenticated:oauth").withImpersonateExtras(Collections.singletonMap("scopes", Collections.singletonList("development"))).build();
// Create a project
ProjectRequest projectRequest = client.withRequestConfig(requestConfig).call(c -> c.projectrequests().create(new ProjectRequestBuilder().withNewMetadata().withName(NEW_PROJECT).endMetadata().build()));
// Grab the requester annotation
String requester = projectRequest.getMetadata().getAnnotations().get("openshift.io/requester");
assertThat(requester).isEqualTo(SERVICE_ACCOUNT);
}
use of io.fabric8.kubernetes.client.RequestConfig in project kubernetes-client by fabric8io.
the class RequestConfigTest method testOauthTokenSuppliedByProvider.
@Test
public void testOauthTokenSuppliedByProvider() throws InterruptedException {
server.expect().withPath("/api/v1/namespaces/test/pods/podName").andReturn(200, new PodBuilder().withNewMetadata().withName("testPodX").endMetadata().build()).always();
RequestConfig requestConfig = new RequestConfigBuilder().withOauthTokenProvider(tokenProvider).build();
tokenProvider.updateToken("token1");
sendRequest(requestConfig);
assertAuthorizationHeader("Bearer token1");
tokenProvider.updateToken("token2");
sendRequest(requestConfig);
assertAuthorizationHeader("Bearer token2");
}
use of io.fabric8.kubernetes.client.RequestConfig in project dropwizard-kubernetes by dropwizard.
the class KubernetesClientFactory method build.
public KubernetesClient build(final MetricRegistry metrics, final LifecycleEnvironment lifecycle, final HealthCheckRegistry healthChecks, final String appName, @Nullable final Tracing tracing) throws Exception {
final RequestConfig requestConf = requestConfig != null ? requestConfig.build() : null;
final Config k8sConfig = config.build(appName, requestConf);
if (httpClient == null) {
return new DefaultKubernetesClient(k8sConfig);
}
final OkHttpClient okHttpClient = httpClient.build(k8sConfig, metrics, name, requestConf, tracing);
final KubernetesClient client = new DefaultKubernetesClient(okHttpClient, k8sConfig);
// manage
lifecycle.manage(new KubernetesClientManager(client, name));
// health checks
final String healthCheckUrl = getHealthCheckUrl(k8sConfig);
final KubernetesClientHealthCheck healthCheck = new KubernetesClientHealthCheck(okHttpClient, name, healthCheckUrl);
healthChecks.register(name, healthCheck);
return client;
}
use of io.fabric8.kubernetes.client.RequestConfig in project dropwizard-kubernetes by dropwizard.
the class OkHttpClientFactoryTest method shouldBuildAConfigWithNoRequestConfig.
@Test
public void shouldBuildAConfigWithNoRequestConfig() throws Exception {
// given
final File yaml = new File(Resources.getResource("yaml/http/http-client.yaml").toURI());
final OkHttpClientFactory httpClientFactory = factory.build(yaml);
final Config config = new ConfigBuilder().build();
final RequestConfig requestConfig = new RequestConfigBuilder().build();
// when
final OkHttpClient httpClient = httpClientFactory.build(config, metrics, "app123", requestConfig, tracing);
// then
assertThat(httpClient).isInstanceOf(OkHttpClient.class);
assertThat(httpClient.interceptors().size()).isEqualTo(2);
assertThat(httpClient.proxy()).isNotNull();
assertThat(httpClient.followRedirects()).isFalse();
assertThat(httpClient.followRedirects()).isFalse();
}
use of io.fabric8.kubernetes.client.RequestConfig in project dropwizard-kubernetes by dropwizard.
the class ConfigFactory method build.
public Config build(final String appName, @Nullable final RequestConfig requestConfig) {
final Config config = Config.autoConfigure(currentContext);
if (masterUrl != null) {
config.setMasterUrl(masterUrl);
}
if (apiVersion != null) {
config.setApiVersion(apiVersion);
}
if (namespace != null) {
config.setNamespace(namespace);
}
if (userAgent != null) {
config.setUserAgent(userAgent);
} else {
config.setUserAgent(appName);
}
if (requestConfig != null) {
config.setLoggingInterval(requestConfig.getLoggingInterval());
config.setRollingTimeout(requestConfig.getRollingTimeout());
config.setScaleTimeout(requestConfig.getScaleTimeout());
config.setWatchReconnectInterval(requestConfig.getWatchReconnectInterval());
config.setWatchReconnectLimit(requestConfig.getWatchReconnectLimit());
config.setConnectionTimeout(requestConfig.getConnectionTimeout());
config.setRequestTimeout(requestConfig.getRequestTimeout());
config.setRollingTimeout(requestConfig.getRollingTimeout());
config.setScaleTimeout(requestConfig.getScaleTimeout());
config.setWebsocketTimeout(requestConfig.getWebsocketTimeout());
config.setWebsocketPingInterval(requestConfig.getWebsocketPingInterval());
config.setMaxConcurrentRequests(requestConfig.getMaxConcurrentRequests());
config.setMaxConcurrentRequestsPerHost(requestConfig.getMaxConcurrentRequestsPerHost());
}
return config;
}
Aggregations