Skip to content

Commit

Permalink
fix fabric8io#4708 refining what is possible via the requestconfig
Browse files Browse the repository at this point in the history
also trying to clean up the logic related to how the config is (or not)
modified
  • Loading branch information
shawkins committed Feb 6, 2023
1 parent f498488 commit 66798c0
Show file tree
Hide file tree
Showing 39 changed files with 273 additions and 453 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#### New Features

#### _**Note**_: Breaking changes
* Fix #4708: The signature of the Interceptor methods changed to pass the full HttpRequest, rather than just the headers, and explicitly pass request tags - in particular the RequestConfig. To simplify authentication concerns the following fields have been removed from RequestConfig: username, password, oauthToken, and oauthTokenProvider. Not all HttpClient implementation support setting the connectionTimeout at a request level, thus it was removed from the RequestConfig as well.

### 6.4.1 (2023-01-31)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import io.fabric8.kubernetes.client.http.BasicBuilder;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpHeaders;
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.Interceptor;
import io.fabric8.kubernetes.client.http.StandardHttpClientBuilder;
import io.fabric8.kubernetes.client.http.TlsVersion;
Expand Down Expand Up @@ -71,7 +71,7 @@ public HttpClient build() {
this.interceptors.put("PROXY-AUTH", new Interceptor() {

@Override
public void before(BasicBuilder builder, HttpHeaders headers) {
public void before(BasicBuilder builder, HttpRequest httpRequest, RequestTags tags) {
builder.setHeader("Proxy-Authorization", proxyAuthorization);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ default <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperat

/**
* Creates a new client based upon the current except with a different
* {@link RequestConfig}. This client will use independent resources,
* and should be closed appropriately
* {@link RequestConfig}. It uses the same resources as the current client, thus
* closing it will close the original client.
*
* @param requestConfig
* @return a new client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public class Config {
private String keyStoreFile;
private String keyStorePassphrase;
private AuthProviderConfig authProvider;
private String username;
private String password;
private volatile String oauthToken;
private OAuthTokenProvider oauthTokenProvider;
private long websocketPingInterval = DEFAULT_WEBSOCKET_PING_INTERVAL;
private int connectionTimeout = 10 * 1000;
private int maxConcurrentRequests = DEFAULT_MAX_CONCURRENT_REQUESTS;
private int maxConcurrentRequestsPerHost = DEFAULT_MAX_CONCURRENT_REQUESTS_PER_HOST;

private RequestConfig requestConfig = new RequestConfig();

Expand All @@ -184,12 +192,8 @@ public class Config {
/**
* fields not used but needed for builder generation.
*/
private String username;
private String password;
private String oauthToken;
private int watchReconnectInterval = 1000;
private int watchReconnectLimit = -1;
private int connectionTimeout = 10 * 1000;
private int uploadConnectionTimeout = DEFAULT_UPLOAD_CONNECTION_TIMEOUT;
private int uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT;
private int requestRetryBackoffLimit;
Expand All @@ -199,11 +203,7 @@ public class Config {
private long scaleTimeout = DEFAULT_SCALE_TIMEOUT;
private int loggingInterval = DEFAULT_LOGGING_INTERVAL;
private long websocketTimeout = DEFAULT_WEBSOCKET_TIMEOUT;
private long websocketPingInterval = DEFAULT_WEBSOCKET_PING_INTERVAL;
private int maxConcurrentRequests = DEFAULT_MAX_CONCURRENT_REQUESTS;
private int maxConcurrentRequestsPerHost = DEFAULT_MAX_CONCURRENT_REQUESTS_PER_HOST;
private String impersonateUsername;
private OAuthTokenProvider oauthTokenProvider;

/**
* @deprecated use impersonateGroups instead
Expand Down Expand Up @@ -363,11 +363,16 @@ public Config(String masterUrl, String apiVersion, String namespace, boolean tru
this.clientKeyData = clientKeyData;
this.clientKeyAlgo = clientKeyAlgo;
this.clientKeyPassphrase = clientKeyPassphrase;

this.requestConfig = new RequestConfig(username, password, oauthToken, watchReconnectLimit, watchReconnectInterval,
connectionTimeout, rollingTimeout, requestTimeout, scaleTimeout, loggingInterval, websocketTimeout,
websocketPingInterval, oauthTokenProvider,
requestRetryBackoffLimit, requestRetryBackoffInterval, uploadConnectionTimeout, uploadRequestTimeout);
this.username = username;
this.password = password;
this.oauthToken = oauthToken;
this.websocketPingInterval = websocketPingInterval;
this.connectionTimeout = connectionTimeout;

this.requestConfig = new RequestConfig(watchReconnectLimit, watchReconnectInterval,
rollingTimeout, requestTimeout, scaleTimeout, loggingInterval, websocketTimeout,
requestRetryBackoffLimit, requestRetryBackoffInterval, uploadConnectionTimeout,
uploadRequestTimeout);
this.requestConfig.setImpersonateUsername(impersonateUsername);
this.requestConfig.setImpersonateGroups(impersonateGroups);
this.requestConfig.setImpersonateExtras(impersonateExtras);
Expand Down Expand Up @@ -969,29 +974,32 @@ public static String getKeyAlgorithm(String clientKeyFile, String clientKeyData)

@JsonProperty("oauthToken")
public String getOauthToken() {
return getRequestConfig().getOauthToken();
if (this.oauthTokenProvider != null) {
return this.oauthTokenProvider.getToken();
}
return oauthToken;
}

public void setOauthToken(String oauthToken) {
this.requestConfig.setOauthToken(oauthToken);
this.oauthToken = oauthToken;
}

@JsonProperty("password")
public String getPassword() {
return getRequestConfig().getPassword();
return password;
}

public void setPassword(String password) {
this.requestConfig.setPassword(password);
this.password = password;
}

@JsonProperty("username")
public String getUsername() {
return getRequestConfig().getUsername();
return username;
}

public void setUsername(String username) {
this.requestConfig.setUsername(username);
this.username = username;
}

@JsonProperty("impersonateUsername")
Expand Down Expand Up @@ -1164,11 +1172,11 @@ public static ConfigBuilder builder() {

@JsonProperty("connectionTimeout")
public int getConnectionTimeout() {
return getRequestConfig().getConnectionTimeout();
return connectionTimeout;
}

public void setConnectionTimeout(int connectionTimeout) {
this.requestConfig.setConnectionTimeout(connectionTimeout);
this.connectionTimeout = connectionTimeout;
}

@JsonProperty("uploadConnectionTimeout")
Expand Down Expand Up @@ -1326,11 +1334,11 @@ public void setWebsocketTimeout(long websocketTimeout) {

@JsonProperty("websocketPingInterval")
public long getWebsocketPingInterval() {
return getRequestConfig().getWebsocketPingInterval();
return websocketPingInterval;
}

public void setWebsocketPingInterval(long websocketPingInterval) {
this.requestConfig.setWebsocketPingInterval(websocketPingInterval);
this.websocketPingInterval = websocketPingInterval;
}

public int getMaxConcurrentRequests() {
Expand Down Expand Up @@ -1371,10 +1379,6 @@ public RequestConfig getRequestConfig() {
return this.requestConfig;
}

public static void setRequestConfig(Config config, RequestConfig requestConfig) {
config.requestConfig = requestConfig;
}

public void setTrustStorePassphrase(String trustStorePassphrase) {
this.trustStorePassphrase = trustStorePassphrase;
}
Expand Down Expand Up @@ -1413,11 +1417,11 @@ public String getKeyStoreFile() {

@JsonIgnore
public OAuthTokenProvider getOauthTokenProvider() {
return this.getRequestConfig().getOauthTokenProvider();
return this.oauthTokenProvider;
}

public void setOauthTokenProvider(OAuthTokenProvider oauthTokenProvider) {
this.requestConfig.setOauthTokenProvider(oauthTokenProvider);
this.oauthTokenProvider = oauthTokenProvider;
}

@JsonProperty("customHeaders")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,17 @@
import static io.fabric8.kubernetes.client.Config.DEFAULT_SCALE_TIMEOUT;
import static io.fabric8.kubernetes.client.Config.DEFAULT_UPLOAD_CONNECTION_TIMEOUT;
import static io.fabric8.kubernetes.client.Config.DEFAULT_UPLOAD_REQUEST_TIMEOUT;
import static io.fabric8.kubernetes.client.Config.DEFAULT_WEBSOCKET_PING_INTERVAL;
import static io.fabric8.kubernetes.client.Config.DEFAULT_WEBSOCKET_TIMEOUT;

public class RequestConfig {

private String username;
private String password;
private volatile String oauthToken;
private OAuthTokenProvider oauthTokenProvider;
private String impersonateUsername;

private String[] impersonateGroups = new String[0];

private Map<String, List<String>> impersonateExtras = new HashMap<>();
private int watchReconnectInterval = 1000;
private int watchReconnectLimit = -1;
private int connectionTimeout = 10 * 1000;
private int uploadConnectionTimeout = DEFAULT_UPLOAD_CONNECTION_TIMEOUT;
private int uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT;
private int requestRetryBackoffLimit = DEFAULT_REQUEST_RETRY_BACKOFFLIMIT;
Expand All @@ -56,83 +50,27 @@ public class RequestConfig {
private long scaleTimeout = DEFAULT_SCALE_TIMEOUT;
private int loggingInterval = DEFAULT_LOGGING_INTERVAL;
private long websocketTimeout = DEFAULT_WEBSOCKET_TIMEOUT;
private long websocketPingInterval = DEFAULT_WEBSOCKET_PING_INTERVAL;

RequestConfig() {
}

/**
* For backward compatibility
* Use RequestConfigBuilder instead
*
* @param username user name
* @param password password
* @param oauthToken oauthToken
* @param watchReconnectLimit watch reconnect limit
* @param watchReconnectInterval watch reconnect interval
* @param connectionTimeout connection timeout
* @param rollingTimeout rolling timeout
* @param requestTimeout request timeout
* @param scaleTimeout scale timeout
* @param loggingInterval logging interval
* @param websocketTimeout web socket timeout
* @param maxConcurrentRequestsPerHost max concurrent requests per host
*/
@Deprecated
public RequestConfig(String username, String password, String oauthToken,
int watchReconnectLimit, int watchReconnectInterval,
int connectionTimeout, long rollingTimeout, int requestTimeout, long scaleTimeout, int loggingInterval,
long websocketTimeout, long websocketPingInterval,
int maxConcurrentRequests, int maxConcurrentRequestsPerHost) {
this(username, password, oauthToken, watchReconnectLimit, watchReconnectInterval, connectionTimeout, rollingTimeout,
requestTimeout, scaleTimeout, loggingInterval,
websocketTimeout, websocketPingInterval, null,
DEFAULT_REQUEST_RETRY_BACKOFFLIMIT, DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL,
DEFAULT_UPLOAD_CONNECTION_TIMEOUT, DEFAULT_UPLOAD_REQUEST_TIMEOUT);
}

@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false)
public RequestConfig(String username, String password, String oauthToken,
int watchReconnectLimit, int watchReconnectInterval,
int connectionTimeout, long rollingTimeout, int requestTimeout, long scaleTimeout, int loggingInterval,
long websocketTimeout, long websocketPingInterval,
OAuthTokenProvider oauthTokenProvider,
int requestRetryBackoffLimit, int requestRetryBackoffInterval, int uploadConnectionTimeout, int uploadRequestTimeout) {
this.username = username;
this.oauthToken = oauthToken;
this.password = password;
public RequestConfig(int watchReconnectLimit, int watchReconnectInterval, long rollingTimeout, int requestTimeout,
long scaleTimeout, int loggingInterval, long websocketTimeout, int requestRetryBackoffLimit,
int requestRetryBackoffInterval, int uploadConnectionTimeout, int uploadRequestTimeout) {
this.watchReconnectLimit = watchReconnectLimit;
this.watchReconnectInterval = watchReconnectInterval;
this.connectionTimeout = connectionTimeout;
this.rollingTimeout = rollingTimeout;
this.requestTimeout = requestTimeout;
this.scaleTimeout = scaleTimeout;
this.websocketTimeout = websocketTimeout;
this.loggingInterval = loggingInterval;
this.websocketPingInterval = websocketPingInterval;
this.oauthTokenProvider = oauthTokenProvider;
this.requestRetryBackoffLimit = requestRetryBackoffLimit;
this.requestRetryBackoffInterval = requestRetryBackoffInterval;
this.uploadConnectionTimeout = uploadConnectionTimeout;
this.uploadRequestTimeout = uploadRequestTimeout;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public int getWatchReconnectInterval() {
return watchReconnectInterval;
}
Expand All @@ -141,25 +79,6 @@ public void setWatchReconnectInterval(int watchReconnectInterval) {
this.watchReconnectInterval = watchReconnectInterval;
}

public String getOauthToken() {
if (oauthTokenProvider != null) {
return oauthTokenProvider.getToken();
}
return oauthToken;
}

public void setOauthToken(String oauthToken) {
this.oauthToken = oauthToken;
}

public OAuthTokenProvider getOauthTokenProvider() {
return oauthTokenProvider;
}

public void setOauthTokenProvider(OAuthTokenProvider oauthTokenProvider) {
this.oauthTokenProvider = oauthTokenProvider;
}

public int getWatchReconnectLimit() {
return watchReconnectLimit;
}
Expand Down Expand Up @@ -192,14 +111,6 @@ public void setRequestRetryBackoffInterval(int requestRetryBackoffInterval) {
this.requestRetryBackoffInterval = requestRetryBackoffInterval;
}

public int getConnectionTimeout() {
return connectionTimeout;
}

public void setConnectionTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}

public int getUploadConnectionTimeout() {
return uploadConnectionTimeout;
}
Expand Down Expand Up @@ -248,14 +159,6 @@ public void setWebsocketTimeout(long websocketTimeout) {
this.websocketTimeout = websocketTimeout;
}

public long getWebsocketPingInterval() {
return websocketPingInterval;
}

public void setWebsocketPingInterval(long websocketPingInterval) {
this.websocketPingInterval = websocketPingInterval;
}

public void setImpersonateUsername(String impersonateUsername) {
this.impersonateUsername = impersonateUsername;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.fabric8.kubernetes.client.http;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.RequestConfig;
import io.fabric8.kubernetes.client.utils.HttpClientUtils;

import java.net.InetSocketAddress;
Expand Down Expand Up @@ -60,7 +59,7 @@ default boolean isDefault() {

/**
* The priority of the implementation. The higher the priority the more likely it will be used.
*
*
* @return the priority.
*/
default int priority() {
Expand Down Expand Up @@ -101,12 +100,9 @@ interface DerivedClientBuilder {
DerivedClientBuilder authenticatorNone();

/**
* Supply an {@link RequestConfig} via a {@link Config} to {@link Interceptor#withConfig(Config)}
*
* @param config
* @return this Builder instance.
* Will be provided to all interceptors
*/
DerivedClientBuilder requestConfig(Config config);
DerivedClientBuilder tag(Object value);
}

interface Builder extends DerivedClientBuilder {
Expand Down
Loading

0 comments on commit 66798c0

Please sign in to comment.