diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2017-12-14 15:47:53 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2017-12-15 11:25:15 +0100 |
commit | 25e335782b31cb20ef19a36fc4c87e64411756e7 (patch) | |
tree | ccc5c69e735409be0d388f59ca9c8524a4e93b5b /controller-api | |
parent | b27bada7c6b22d83557c6592d8c00fea2a6c35fe (diff) |
Add utility method to create Athenz identity from string
Diffstat (limited to 'controller-api')
2 files changed, 33 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzUtils.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzUtils.java index 0ed5d86dd7e..62a7049a7c6 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzUtils.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzUtils.java @@ -23,4 +23,16 @@ public class AthenzUtils { } } + public static AthenzIdentity createAthenzIdentity(String fullName) { + int domainIdentityNameSeparatorIndex = fullName.lastIndexOf('.'); + if (domainIdentityNameSeparatorIndex == -1 + || domainIdentityNameSeparatorIndex == 0 + || domainIdentityNameSeparatorIndex == fullName.length() - 1) { + throw new IllegalArgumentException("Invalid Athenz identity: " + fullName); + } + AthenzDomain domain = new AthenzDomain(fullName.substring(0, domainIdentityNameSeparatorIndex)); + String identityName = fullName.substring(domainIdentityNameSeparatorIndex + 1, fullName.length()); + return createAthenzIdentity(domain, identityName); + } + } diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzUtilsTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzUtilsTest.java new file mode 100644 index 00000000000..f2db74a4c3d --- /dev/null +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/integration/athenz/AthenzUtilsTest.java @@ -0,0 +1,21 @@ +package com.yahoo.vespa.hosted.controller.api.integration.athenz; + +import com.yahoo.vespa.hosted.controller.api.identifiers.AthenzDomain; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author bjorncs + */ +public class AthenzUtilsTest { + + @Test + public void athenz_identity_is_parsed_from_dot_separated_string() { + AthenzIdentity expectedIdentity = new AthenzService(new AthenzDomain("my.subdomain"), "myservicename"); + String fullName = expectedIdentity.getFullName(); + AthenzIdentity actualIdentity = AthenzUtils.createAthenzIdentity(fullName); + assertEquals(expectedIdentity, actualIdentity); + } + +}
\ No newline at end of file |