From 5c53251ef2d984d9dc201e4db4fc65adfe77201a Mon Sep 17 00:00:00 2001 From: toby Date: Thu, 7 Nov 2019 16:35:22 +0100 Subject: Add method and use this in already supported restapi --- .../controller/api/integration/stubs/MockUserManagement.java | 8 ++++++++ .../hosted/controller/api/integration/user/UserManagement.java | 3 +++ 2 files changed, 11 insertions(+) (limited to 'controller-api') diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java index 03eda33233d..145b468688c 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java @@ -6,6 +6,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.user.UserManagement; import com.yahoo.vespa.hosted.controller.api.role.Role; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -41,6 +42,13 @@ public class MockUserManagement implements UserManagement { memberships.get(role).addAll(userObjs); } + @Override + public void addRoles(UserId user, Collection roles) { + for (Role role : roles) { + addUsers(role, Collections.singletonList(user)); + } + } + @Override public void removeUsers(Role role, Collection users) { memberships.get(role).removeIf(user -> users.contains(new UserId(user.email()))); diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java index f56a9f66288..efe31f6f118 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java @@ -21,6 +21,9 @@ public interface UserManagement { /** Ensures the given users exist, and are part of the given role, or throws if the role does not exist. */ void addUsers(Role role, Collection users); + /** Ensures the given user exist, and are part of the given roles, or throws if the roles does not exist. */ + void addRoles(UserId user, Collection roles); + /** Ensures none of the given users are part of the given role, or throws if the role does not exist. */ void removeUsers(Role role, Collection users); -- cgit v1.2.3