Implement overlapping environments
@@ -7,10 +7,27 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.owasp.wrongsecrets.RuntimeEnvironment.Environment.AWS;
+import static org.owasp.wrongsecrets.RuntimeEnvironment.Environment.DOCKER;
+import static org.owasp.wrongsecrets.RuntimeEnvironment.Environment.GCP;
+import static org.owasp.wrongsecrets.RuntimeEnvironment.Environment.K8S;
+import static org.owasp.wrongsecrets.RuntimeEnvironment.Environment.VAULT;
@Component
public class RuntimeEnvironment {
+ private static Map<Environment, List<Environment>> envToOverlappingEnvs = Map.of(
+ DOCKER, List.of(DOCKER),
+ GCP, List.of(DOCKER, K8S, VAULT),
+ AWS, List.of(DOCKER, K8S, VAULT),
+ VAULT, List.of(DOCKER, K8S),
+ K8S, List.of(DOCKER)
+ );
+
public enum Environment {
DOCKER("Docker"), GCP("gcp"), AWS("aws"), VAULT("k8s-with-vault"), K8S("k8s");
@@ -38,6 +55,8 @@ public class RuntimeEnvironment {
}
public boolean isFitFor(Challenge challenge) {
- return challenge.supportedRuntimeEnvironments().contains(runtimeEnvironment);
+ return challenge.supportedRuntimeEnvironments().contains(runtimeEnvironment) ||
+ !Collections.disjoint(envToOverlappingEnvs.get(runtimeEnvironment), challenge.supportedRuntimeEnvironments());
}
+
}
