Skip to content

Commit b18da5b

Browse files
authored
Merge pull request #173 from oracle/remove-httpclient-unused-principal
remove unused principal field from HttpClient
2 parents 3e2a770 + 24c5b74 commit b18da5b

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

operator/src/main/java/oracle/kubernetes/operator/http/HttpClient.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ public class HttpClient {
3535
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
3636

3737
private Client httpClient;
38-
private String principal;
3938
private String encodedCredentials;
4039

4140
private static final String HTTP_PROTOCOL = "http://";
4241

4342
// for debugging
4443
private static final String SERVICE_URL = System.getProperty("oracle.kubernetes.operator.http.HttpClient.SERVICE_URL");
4544

46-
private HttpClient(Client httpClient, String principal, String encodedCredentials) {
45+
private HttpClient(Client httpClient, String encodedCredentials) {
4746
this.httpClient = httpClient;
48-
this.principal = principal;
4947
this.encodedCredentials = encodedCredentials;
5048
}
5149

@@ -144,14 +142,13 @@ public Result executePostUrlOnServiceClusterIP(String requestUrl, String service
144142

145143
/**
146144
* Asynchronous {@link Step} for creating an authenticated HTTP client targeted at a server instance
147-
* @param principal Principal
148145
* @param namespace Namespace
149146
* @param adminSecretName Admin secret name
150147
* @param next Next processing step
151148
* @return step to create client
152149
*/
153-
public static Step createAuthenticatedClientForServer(String principal, String namespace, String adminSecretName, Step next) {
154-
return new AuthenticatedClientForServerStep(namespace, adminSecretName, new WithSecretDataStep(principal, next));
150+
public static Step createAuthenticatedClientForServer(String namespace, String adminSecretName, Step next) {
151+
return new AuthenticatedClientForServerStep(namespace, adminSecretName, new WithSecretDataStep(next));
155152
}
156153

157154
private static class AuthenticatedClientForServerStep extends Step {
@@ -172,11 +169,9 @@ public NextAction apply(Packet packet) {
172169
}
173170

174171
private static class WithSecretDataStep extends Step {
175-
private final String principal;
176172

177-
public WithSecretDataStep(String principal, Step next) {
173+
public WithSecretDataStep(Step next) {
178174
super(next);
179-
this.principal = principal;
180175
}
181176

182177
@Override
@@ -189,7 +184,7 @@ public NextAction apply(Packet packet) {
189184
username = secretData.get(SecretHelper.ADMIN_SERVER_CREDENTIALS_USERNAME);
190185
password = secretData.get(SecretHelper.ADMIN_SERVER_CREDENTIALS_PASSWORD);
191186
}
192-
packet.put(KEY, createAuthenticatedClient(principal, username, password));
187+
packet.put(KEY, createAuthenticatedClient(username, password));
193188

194189
Arrays.fill(username, (byte) 0);
195190
Arrays.fill(password, (byte) 0);
@@ -199,12 +194,11 @@ public NextAction apply(Packet packet) {
199194

200195
/**
201196
* Create authenticated client specifically targeted at an admin server
202-
* @param principal Principal
203197
* @param namespace Namespace
204198
* @param adminSecretName Admin secret name
205199
* @return authenticated client
206200
*/
207-
public static HttpClient createAuthenticatedClientForServer(String principal, String namespace, String adminSecretName) {
201+
public static HttpClient createAuthenticatedClientForServer(String namespace, String adminSecretName) {
208202
SecretHelper secretHelper = new SecretHelper(namespace);
209203
Map<String, byte[]> secretData =
210204
secretHelper.getSecretData(SecretHelper.SecretType.AdminCredentials, adminSecretName);
@@ -215,18 +209,16 @@ public static HttpClient createAuthenticatedClientForServer(String principal, St
215209
username = secretData.get(SecretHelper.ADMIN_SERVER_CREDENTIALS_USERNAME);
216210
password = secretData.get(SecretHelper.ADMIN_SERVER_CREDENTIALS_PASSWORD);
217211
}
218-
return createAuthenticatedClient(principal, username, password);
212+
return createAuthenticatedClient(username, password);
219213
}
220214

221215
/**
222216
* Create authenticated HTTP client
223-
* @param principal Principal
224217
* @param username Username
225218
* @param password Password
226219
* @return authenticated client
227220
*/
228-
public static HttpClient createAuthenticatedClient(String principal,
229-
final byte[] username,
221+
public static HttpClient createAuthenticatedClient(final byte[] username,
230222
final byte[] password) {
231223
// build client with authentication information.
232224
Client client = ClientBuilder.newClient();
@@ -238,18 +230,17 @@ public static HttpClient createAuthenticatedClient(String principal,
238230
System.arraycopy(password, 0, usernameAndPassword, username.length + 1, password.length);
239231
encodedCredentials = java.util.Base64.getEncoder().encodeToString(usernameAndPassword);
240232
}
241-
return new HttpClient(client, principal, encodedCredentials);
233+
return new HttpClient(client, encodedCredentials);
242234
}
243235

244236
/**
245237
* Returns the URL to access the service; using the service clusterIP and port.
246238
*
247-
* @param principal The principal that will be used to call the Kubernetes API.
248239
* @param name The name of the Service that you want the URL for.
249240
* @param namespace The Namespace in which the Service you want the URL for is defined.
250-
* @return The URL of the Service, or null if it is not found or principal does not have sufficient permissions.
241+
* @return The URL of the Service, or null if it is not found
251242
*/
252-
public static String getServiceURL(String principal, String name, String namespace) {
243+
public static String getServiceURL(String name, String namespace) {
253244
try {
254245
CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
255246
return getServiceURL(factory.create().readService(name, namespace));

operator/src/main/java/oracle/kubernetes/operator/rest/RestBackendImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,14 @@ private ClusterStartup getClusterStartup(Domain domain, String cluster) {
337337

338338
private int getWLSConfiguredClusterSize(String adminServerServiceName, String cluster, String namespace, String adminSecretName) {
339339
WlsRetriever wlsConfigRetriever = WlsRetriever.create(namespace, adminServerServiceName, adminSecretName);
340-
WlsDomainConfig wlsDomainConfig = wlsConfigRetriever.readConfig(principal);
340+
WlsDomainConfig wlsDomainConfig = wlsConfigRetriever.readConfig();
341341
WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig(cluster);
342342
return wlsClusterConfig.getClusterSize();
343343
}
344344

345345
private Map<String, WlsClusterConfig> getWLSConfiguredClusters(String namespace, String adminServerServiceName, String adminSecretName) {
346346
WlsRetriever wlsConfigRetriever = WlsRetriever.create(namespace, adminServerServiceName, adminSecretName);
347-
WlsDomainConfig wlsDomainConfig = wlsConfigRetriever.readConfig(principal);
347+
WlsDomainConfig wlsDomainConfig = wlsConfigRetriever.readConfig();
348348
return wlsDomainConfig.getClusterConfigs();
349349
}
350350

operator/src/main/java/oracle/kubernetes/operator/wlsconfig/WlsRetriever.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ public ReadStep(RequestType requestType, Step next) {
125125
public NextAction apply(Packet packet) {
126126
try {
127127
DomainPresenceInfo info = packet.getSPI(DomainPresenceInfo.class);
128-
String principal = (String) packet.get(ProcessingConstants.PRINCIPAL);
129-
128+
130129
packet.putIfAbsent(START_TIME, Long.valueOf(System.currentTimeMillis()));
131130

132131
Domain dom = info.getDomain();
@@ -145,7 +144,7 @@ public NextAction apply(Packet packet) {
145144
String adminSecretName = spec.getAdminSecret() == null ? null : spec.getAdminSecret().getName();
146145

147146
Step getClient = HttpClient.createAuthenticatedClientForServer(
148-
principal, namespace, adminSecretName,
147+
namespace, adminSecretName,
149148
new WithHttpClientStep(requestType, namespace, sko.getService().get(), next));
150149
packet.remove(RETRY_COUNT);
151150
return doNext(getClient, packet);
@@ -287,20 +286,18 @@ public static String getRetrieveHealthSearchPayload() {
287286
* would repeatedly try to connect to the admin server to retrieve the configuration until the configured timeout
288287
* occurs.
289288
*
290-
* @param principal The principal that should be used to retrieve the configuration.
291-
*
292289
* @return A WlsClusterConfig object containing selected server configurations of all WLS servers configured in the
293290
* domain that belongs to a cluster. This method returns an empty configuration object even if it fails to retrieve
294291
* WLS configuration from the admin server.
295292
*/
296-
public WlsDomainConfig readConfig(String principal) {
293+
public WlsDomainConfig readConfig() {
297294

298295
LOGGER.entering();
299296

300297
long timeout = READ_CONFIG_TIMEOUT_MILLIS;
301298
ScheduledExecutorService executorService = ContainerResolver.getInstance().getContainer().getSPI(ScheduledExecutorService.class);
302299
long startTime = System.currentTimeMillis();
303-
Future<WlsDomainConfig> future = executorService.submit(() -> getWlsDomainConfig(principal, timeout));
300+
Future<WlsDomainConfig> future = executorService.submit(() -> getWlsDomainConfig(timeout));
304301
executorService.shutdown();
305302
WlsDomainConfig wlsConfig = null;
306303
try {
@@ -323,14 +320,13 @@ public WlsDomainConfig readConfig(String principal) {
323320
* Method called by the Callable that is submitted from the readConfig method for reading the WLS server
324321
* configurations
325322
*
326-
* @param principal The Service Account or User to use when accessing WebLogic.
327323
* @param timeout Maximum amount of time in millis to try to read configuration from the admin server before giving up
328324
* @return A WlsClusterConfig object containing selected server configurations of all WLS servers configured in the
329325
* cluster. Method returns empty configuration object if timeout occurs before the configuration could be read from
330326
* the admin server.
331327
* @throws Exception if an exception occurs in the attempt just prior to the timeout
332328
*/
333-
private WlsDomainConfig getWlsDomainConfig(String principal, long timeout) throws Exception {
329+
private WlsDomainConfig getWlsDomainConfig(long timeout) throws Exception {
334330
LOGGER.entering();
335331

336332
long stopTime = System.currentTimeMillis() + timeout;
@@ -342,8 +338,7 @@ private WlsDomainConfig getWlsDomainConfig(String principal, long timeout) throw
342338
LOGGER.info(MessageKeys.WLS_CONFIGURATION_READ_TRYING, timeRemaining);
343339
exception = null;
344340
try {
345-
connectAdminServer(principal);
346-
String serviceURL = HttpClient.getServiceURL(principal, asServiceName, namespace);
341+
String serviceURL = connectAndGetServiceURL();
347342
String jsonResult =
348343
httpClient.executePostUrlOnServiceClusterIP(WlsDomainConfig.getRetrieveServersSearchUrl(), serviceURL, WlsDomainConfig.getRetrieveServersSearchPayload()).getResponse();
349344
if (jsonResult != null) {
@@ -370,14 +365,17 @@ private WlsDomainConfig getWlsDomainConfig(String principal, long timeout) throw
370365
}
371366

372367
/**
373-
* Connect to the WebLogic Administration Server.
368+
* Connect to the WebLogic Administration Server and returns the service URL
374369
*
375-
* @param principal The principal that should be used to connect to the Admin Server.
370+
* @return serviceURL for issuing HTTP requests to the admin server
376371
*/
377-
public void connectAdminServer(String principal) {
372+
String connectAndGetServiceURL() {
378373
if (httpClient == null) {
379-
httpClient = HttpClient.createAuthenticatedClientForServer(principal, namespace, adminSecretName);
374+
httpClient = HttpClient.createAuthenticatedClientForServer(namespace, adminSecretName);
380375
}
376+
377+
return HttpClient.getServiceURL(asServiceName, namespace);
381378
}
382379

380+
383381
}

0 commit comments

Comments
 (0)