Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Nov 9, 2023
1 parent 13f0b0d commit 7f35b30
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.cryostat.MainModule;
import io.cryostat.configuration.CredentialsManager;
import io.cryostat.core.log.Logger;
import io.cryostat.core.sys.Environment;
import io.cryostat.discovery.DiscoveryStorage;
import io.cryostat.discovery.PluginInfo;
import io.cryostat.discovery.RegistrationException;
Expand All @@ -61,6 +62,7 @@
class DiscoveryRegistrationHandler extends AbstractV2RequestHandler<Map<String, Object>> {

static final String PATH = "discovery";
private final Environment env;
private final DiscoveryStorage storage;
private final Lazy<WebServer> webServer;
private final Set<PlatformDetectionStrategy<?>> selectedStrategies;
Expand All @@ -72,6 +74,7 @@ class DiscoveryRegistrationHandler extends AbstractV2RequestHandler<Map<String,
DiscoveryRegistrationHandler(
AuthManager auth,
CredentialsManager credentialsManager,
Environment env,
DiscoveryStorage storage,
Lazy<WebServer> webServer,
@Named(PlatformModule.SELECTED_PLATFORMS)
Expand All @@ -81,6 +84,7 @@ class DiscoveryRegistrationHandler extends AbstractV2RequestHandler<Map<String,
Gson gson,
Logger logger) {
super(auth, credentialsManager, gson);
this.env = env;
this.storage = storage;
this.webServer = webServer;
this.selectedStrategies = selectedStrategies;
Expand Down Expand Up @@ -187,7 +191,7 @@ public IntermediateResponse<Map<String, Object>> handle(RequestParameters params
// but in the future if any more strategies also provide entries then the order here may be
// undefined and the map entries may collide and be overwritten. There should be some
// prefixing scheme to prevent collisions.
selectedStrategies.forEach(s -> mergedEnv.putAll(s.environment()));
selectedStrategies.forEach(s -> mergedEnv.putAll(s.environment(env)));
return new IntermediateResponse<Map<String, Object>>()
.statusCode(201)
.addHeader(HttpHeaders.LOCATION, String.format("%s/%s", path(), pluginId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package io.cryostat.platform.internal;

import java.util.HashMap;
import java.util.Map;

import io.cryostat.core.log.Logger;
import io.cryostat.core.net.JFRConnectionToolkit;
import io.cryostat.core.sys.Environment;
Expand Down Expand Up @@ -48,13 +45,4 @@ protected boolean testAvailability(KubernetesClient client) {
protected OpenShiftClient createClient() {
return super.createClient().adapt(OpenShiftClient.class);
}

@Override
public Map<String, String> environment() {
Map<String, String> map = new HashMap<>(super.environment());
if (env.hasEnv("INSIGHTS_PROXY")) {
map.put("INSIGHTS_SVC", env.getEnv("INSIGHTS_PROXY"));
}
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package io.cryostat.platform.internal;

import java.util.HashMap;
import java.util.Map;

import io.cryostat.core.sys.Environment;
import io.cryostat.net.AuthManager;
import io.cryostat.platform.PlatformClient;

Expand All @@ -27,7 +29,11 @@ public interface PlatformDetectionStrategy<T extends PlatformClient> {

AuthManager getAuthManager();

default Map<String, String> environment() {
return Map.of();
default Map<String, String> environment(Environment env) {
Map<String, String> map = new HashMap<>();
if (env.hasEnv("INSIGHTS_PROXY")) {
map.put("INSIGHTS_SVC", env.getEnv("INSIGHTS_PROXY"));
}
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package io.cryostat.platform.internal;

import java.net.URI;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -146,12 +144,6 @@ public AuthManager getAuthManager() {
return authMgr.get();
}

// FIXME remove this, just for testing purposes
@Override
public Map<String, String> environment() {
return Map.of("TEST", UUID.randomUUID().toString());
}

private static String getSocketPath() {
long uid = new UnixSystem().getUid();
String socketPath = String.format("/run/user/%d/podman/podman.sock", uid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.cryostat.MainModule;
import io.cryostat.configuration.CredentialsManager;
import io.cryostat.core.log.Logger;
import io.cryostat.core.sys.Environment;
import io.cryostat.discovery.DiscoveryStorage;
import io.cryostat.net.AuthManager;
import io.cryostat.net.security.ResourceAction;
Expand Down Expand Up @@ -58,6 +59,7 @@ class DiscoveryRegistrationHandlerTest {
AbstractV2RequestHandler<Map<String, Object>> handler;
@Mock AuthManager auth;
@Mock CredentialsManager credentialsManager;
@Mock Environment env;
@Mock DiscoveryStorage storage;
@Mock WebServer webServer;
@Mock DiscoveryJwtHelper jwt;
Expand All @@ -70,6 +72,7 @@ void setup() {
new DiscoveryRegistrationHandler(
auth,
credentialsManager,
env,
storage,
() -> webServer,
// TODO inject some selectedStrategies and test the env map
Expand Down

0 comments on commit 7f35b30

Please sign in to comment.