Skip to content

Commit

Permalink
Do not log env-var-script property of getCluster
Browse files Browse the repository at this point in the history
Also remove a spurious warning caused by SAL renaming one of the
possible values of the `state` property.

Fixes #43
  • Loading branch information
rudi committed Nov 12, 2024
1 parent 1de513e commit dd64607
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -759,13 +758,29 @@ public boolean defineCluster(String appID, String clusterName, ObjectNode cluste
}

/**
* Get the definition of a cluster created by {@link #defineCluster}.
* Get the definition of a cluster created by {@link #defineCluster}.<p>
*
* NOTE: the {@code env-var-script} key returned by SAL contains
* potentially sensitive information, and is removed by this method.
*
* @param appID The application ID.
* @param clusterName The cluster name, as given in {@link defineCluster}.
* @return The cluster definition, or null in case of error.
*/
public JsonNode getCluster(String appID, String clusterName) {
return getCluster(appID, clusterName, true);
}

/**
* Get the definition of a cluster created by {@link #defineCluster}.<p>
*
* @param appID The application ID.
* @param clusterName The cluster name, as given in {@link defineCluster}.
* @param removeEnvVars true if the {@code env-var-script} key should be
* removed. This is strongly recommended for security reasons.
* @return The cluster definition, or null in case of error.
*/
public JsonNode getCluster(String appID, String clusterName, boolean removeEnvVars) {
Context context = getContext(); if (context == null) { log.error("Trying to send request before Connector gave us a context (internal error)"); return null; }
Map<String, Object> msg = Map.of("metaData", Map.of("user", "admin", "clusterName", clusterName));
SyncedPublisher getCluster = new SyncedPublisher(
Expand All @@ -775,6 +790,9 @@ public JsonNode getCluster(String appID, String clusterName) {
context.registerPublisher(getCluster);
Map<String, Object> response = getCluster.sendSync(msg, appID, null, false);
JsonNode payload = extractPayloadFromExnResponse(response, "getCluster");
if (removeEnvVars && payload.isObject()) {
((ObjectNode)payload).remove("env-var-script");
}
return payload.isMissingNode() ? null : payload;
} finally {
context.unregisterPublisher(getCluster.key());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ private static boolean waitForClusterDeploymentFinished(ExnConnector conn, Strin
return false;
} else {
if (!status.equals("submited" /* [sic] */)
&& !status.equals("submitted" /* SAL fixed the spelling at some point */)
&& !status.equals("scaling")) {
// Better paranoid than sorry
log.warn("Unknown 'status' value in getCluster result: {}", status);
Expand Down

0 comments on commit dd64607

Please sign in to comment.