summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorMorten Tokle <mortent@yahooinc.com>2023-01-24 23:22:00 +0100
committerMorten Tokle <mortent@yahooinc.com>2023-01-24 23:22:00 +0100
commitbdddeb15c1ff070045b76010cae12c5bedf95cf0 (patch)
treee42f89fa34fde3282a7c1c07fb0254e013c07e82 /controller-api
parent3e5e45f78b32a833e47ba314d2df840092a6aaaf (diff)
Support updating athenz domain meta
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzDbMock.java12
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/ZmsClientMock.java26
2 files changed, 36 insertions, 2 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzDbMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzDbMock.java
index 63dfff95c03..9a9c2af2d5d 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzDbMock.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzDbMock.java
@@ -28,7 +28,11 @@ public class AthenzDbMock {
}
public Domain getOrCreateDomain(AthenzDomain domain) {
- return domains.computeIfAbsent(domain, Domain::new);
+ return this.getOrCreateDomain(domain, Map.of());
+ }
+
+ public Domain getOrCreateDomain(AthenzDomain domain, Map<String, Object> attributes) {
+ return domains.computeIfAbsent(domain, Domain::new).withAttributes(attributes);
}
public AthenzDbMock addHostedOperator(AthenzIdentity athenzIdentity) {
@@ -46,6 +50,7 @@ public class AthenzDbMock {
public final List<Role> roles = new ArrayList<>();
public final Map<String, Policy> policies = new HashMap<>();
public boolean isVespaTenant = false;
+ public final Map<String, Object> attributes = new HashMap<>();
public Domain(AthenzDomain name) {
this.name = name;
@@ -72,6 +77,11 @@ public class AthenzDbMock {
return this;
}
+ public Domain withAttributes(Map<String, Object> attributes) {
+ this.attributes.putAll(attributes);
+ return this;
+ }
+
/**
* Simulates establishing Vespa tenancy in Athens.
*/
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/ZmsClientMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/ZmsClientMock.java
index d5e815912c5..ed185f8af32 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/ZmsClientMock.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/ZmsClientMock.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.athenz;
import com.yahoo.vespa.athenz.api.AthenzAssertion;
import com.yahoo.vespa.athenz.api.AthenzDomain;
+import com.yahoo.vespa.athenz.api.AthenzDomainMeta;
import com.yahoo.vespa.athenz.api.AthenzGroup;
import com.yahoo.vespa.athenz.api.AthenzIdentity;
import com.yahoo.vespa.athenz.api.AthenzPolicy;
@@ -139,6 +140,25 @@ public class ZmsClientMock implements ZmsClient {
}
@Override
+ public AthenzDomainMeta getDomainMeta(AthenzDomain domain) {
+ return Optional.ofNullable(athenz.domains.get(domain))
+ .map(d -> d.attributes)
+ .map(attrs -> {
+ if (attrs.containsKey("account")) {
+ return new AthenzDomainMeta((String)attrs.get("account"), domain.getName());
+ }
+ return null;
+ })
+ .orElse(null);
+ }
+
+ @Override
+ public void updateDomain(AthenzDomain domain, Map<String, Object> attributes) {
+ if (!athenz.domains.containsKey(domain)) throw new IllegalStateException("Domain does not exist: " + domain.getName());
+ athenz.domains.get(domain).withAttributes(attributes);
+ }
+
+ @Override
public boolean hasAccess(AthenzResourceName resource, String action, AthenzIdentity identity) {
log("hasAccess(resource=%s, action=%s, identity=%s)", resource, action, identity);
if (resource.getDomain().equals(this.controllerIdentity.getDomain())) {
@@ -268,7 +288,11 @@ public class ZmsClientMock implements ZmsClient {
}
@Override
- public void createSubdomain(AthenzDomain parent, String name, Map<String, Object> attributes) {}
+ public void createSubdomain(AthenzDomain parent, String name, Map<String, Object> attributes) {
+ AthenzDomain domain = new AthenzDomain(parent, name);
+ if (athenz.domains.containsKey(domain)) throw new IllegalStateException("Subdomain already exists: %s".formatted(domain.getName()));
+ athenz.getOrCreateDomain(domain, attributes);
+ }
@Override
public AthenzRoleInformation getFullRoleInformation(AthenzRole role) {