@Test void destroyToken() { final MetadataService mds = newMetadataService(manager); mds.addRepo(author, project1, repo1, ownerOnly).join(); mds.createToken(author, app1).join(); mds.createToken(author, app2).join(); mds.addToken(author, project1, app1, ProjectRole.MEMBER).join(); mds.addToken(author, project1, app2, ProjectRole.MEMBER).join(); mds.addPerTokenPermission(author, project1, repo1, app1, READ_ONLY).join(); mds.addPerTokenPermission(author, project1, repo1, app2, READ_ONLY).join(); assertThat(mds.findPermissions(project1, repo1, app1).join()) .containsExactly(Permission.READ); mds.destroyToken(author, app1).join(); assertThat(mds.findPermissions(project1, repo1, app1).join()) .containsExactlyElementsOf(NO_PERMISSION); assertThat(mds.findPermissions(project1, repo1, app2).join()) .containsExactly(Permission.READ); }
public CompletableFuture<Revision> destroyToken(Author author, String appId) { requireNonNull(author, "author"); requireNonNull(appId, "appId"); final Collection<Project> projects = new SafeProjectManager(projectManager).list().values(); final CompletableFuture<?>[] futures = new CompletableFuture<?>[projects.size()]; int i = 0; for (final Project p : projects) { futures[i++] = removeToken(p.name(), author, appId, true).toCompletableFuture(); } return CompletableFuture.allOf(futures).thenCompose(unused -> tokenRepo.push( INTERNAL_PROJ, Project.REPO_DOGMA, author, "Remove the token: " + appId, () -> tokenRepo.fetch(INTERNAL_PROJ, Project.REPO_DOGMA, TOKEN_JSON) .thenApply(tokens -> { final Token token = tokens.object().get(appId); final JsonPointer appIdPath = JsonPointer.compile("/appIds" + encodeSegment(appId)); final String secret = token.secret(); assert secret != null; final JsonPointer secretPath = JsonPointer.compile("/secrets" + encodeSegment(secret)); final Change<?> change = Change.ofJsonPatch( TOKEN_JSON, asJsonArray(new RemoveOperation(appIdPath), new RemoveIfExistsOperation(secretPath))); return HolderWithRevision.of(change, tokens.revision()); })) ); }
MetadataService { public CompletableFuture<Revision> destroyToken(Author author, String appId) { requireNonNull(author, "author"); requireNonNull(appId, "appId"); final Collection<Project> projects = new SafeProjectManager(projectManager).list().values(); final CompletableFuture<?>[] futures = new CompletableFuture<?>[projects.size()]; int i = 0; for (final Project p : projects) { futures[i++] = removeToken(p.name(), author, appId, true).toCompletableFuture(); } return CompletableFuture.allOf(futures).thenCompose(unused -> tokenRepo.push( INTERNAL_PROJ, Project.REPO_DOGMA, author, "Remove the token: " + appId, () -> tokenRepo.fetch(INTERNAL_PROJ, Project.REPO_DOGMA, TOKEN_JSON) .thenApply(tokens -> { final Token token = tokens.object().get(appId); final JsonPointer appIdPath = JsonPointer.compile("/appIds" + encodeSegment(appId)); final String secret = token.secret(); assert secret != null; final JsonPointer secretPath = JsonPointer.compile("/secrets" + encodeSegment(secret)); final Change<?> change = Change.ofJsonPatch( TOKEN_JSON, asJsonArray(new RemoveOperation(appIdPath), new RemoveIfExistsOperation(secretPath))); return HolderWithRevision.of(change, tokens.revision()); })) ); } }
MetadataService { public CompletableFuture<Revision> destroyToken(Author author, String appId) { requireNonNull(author, "author"); requireNonNull(appId, "appId"); final Collection<Project> projects = new SafeProjectManager(projectManager).list().values(); final CompletableFuture<?>[] futures = new CompletableFuture<?>[projects.size()]; int i = 0; for (final Project p : projects) { futures[i++] = removeToken(p.name(), author, appId, true).toCompletableFuture(); } return CompletableFuture.allOf(futures).thenCompose(unused -> tokenRepo.push( INTERNAL_PROJ, Project.REPO_DOGMA, author, "Remove the token: " + appId, () -> tokenRepo.fetch(INTERNAL_PROJ, Project.REPO_DOGMA, TOKEN_JSON) .thenApply(tokens -> { final Token token = tokens.object().get(appId); final JsonPointer appIdPath = JsonPointer.compile("/appIds" + encodeSegment(appId)); final String secret = token.secret(); assert secret != null; final JsonPointer secretPath = JsonPointer.compile("/secrets" + encodeSegment(secret)); final Change<?> change = Change.ofJsonPatch( TOKEN_JSON, asJsonArray(new RemoveOperation(appIdPath), new RemoveIfExistsOperation(secretPath))); return HolderWithRevision.of(change, tokens.revision()); })) ); } MetadataService(ProjectManager projectManager, CommandExecutor executor); }
MetadataService { public CompletableFuture<Revision> destroyToken(Author author, String appId) { requireNonNull(author, "author"); requireNonNull(appId, "appId"); final Collection<Project> projects = new SafeProjectManager(projectManager).list().values(); final CompletableFuture<?>[] futures = new CompletableFuture<?>[projects.size()]; int i = 0; for (final Project p : projects) { futures[i++] = removeToken(p.name(), author, appId, true).toCompletableFuture(); } return CompletableFuture.allOf(futures).thenCompose(unused -> tokenRepo.push( INTERNAL_PROJ, Project.REPO_DOGMA, author, "Remove the token: " + appId, () -> tokenRepo.fetch(INTERNAL_PROJ, Project.REPO_DOGMA, TOKEN_JSON) .thenApply(tokens -> { final Token token = tokens.object().get(appId); final JsonPointer appIdPath = JsonPointer.compile("/appIds" + encodeSegment(appId)); final String secret = token.secret(); assert secret != null; final JsonPointer secretPath = JsonPointer.compile("/secrets" + encodeSegment(secret)); final Change<?> change = Change.ofJsonPatch( TOKEN_JSON, asJsonArray(new RemoveOperation(appIdPath), new RemoveIfExistsOperation(secretPath))); return HolderWithRevision.of(change, tokens.revision()); })) ); } MetadataService(ProjectManager projectManager, CommandExecutor executor); CompletableFuture<ProjectMetadata> getProject(String projectName); CompletableFuture<Revision> removeProject(Author author, String projectName); CompletableFuture<Revision> restoreProject(Author author, String projectName); CompletableFuture<Member> getMember(String projectName, User user); CompletableFuture<Revision> addMember(Author author, String projectName,
                                                 User member, ProjectRole projectRole); CompletableFuture<Revision> removeMember(Author author, String projectName, User member); CompletableFuture<Revision> updateMemberRole(Author author, String projectName,
                                                        User member, ProjectRole projectRole); CompletableFuture<RepositoryMetadata> getRepo(String projectName, String repoName); CompletableFuture<Revision> addRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> addRepo(Author author, String projectName, String repoName,
                                               PerRolePermissions permission); CompletableFuture<Revision> removeRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> purgeRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> restoreRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> updatePerRolePermissions(Author author,
                                                                String projectName, String repoName,
                                                                PerRolePermissions perRolePermissions); CompletableFuture<Revision> addToken(Author author, String projectName,
                                                Token token, ProjectRole role); CompletableFuture<Revision> addToken(Author author, String projectName,
                                                String appId, ProjectRole role); CompletableFuture<Revision> removeToken(Author author, String projectName, Token token); CompletableFuture<Revision> removeToken(Author author, String projectName, String appId); CompletableFuture<Revision> updateTokenRole(Author author, String projectName,
                                                       Token token, ProjectRole role); CompletableFuture<Revision> addPerUserPermission(Author author, String projectName,
                                                            String repoName, User member,
                                                            Collection<Permission> permission); CompletableFuture<Revision> removePerUserPermission(Author author, String projectName,
                                                               String repoName, User member); CompletableFuture<Revision> updatePerUserPermission(Author author, String projectName,
                                                               String repoName, User member,
                                                               Collection<Permission> permission); CompletableFuture<Revision> addPerTokenPermission(Author author, String projectName,
                                                             String repoName, String appId,
                                                             Collection<Permission> permission); CompletableFuture<Revision> removePerTokenPermission(Author author, String projectName,
                                                                String repoName, String appId); CompletableFuture<Revision> updatePerTokenPermission(Author author, String projectName,
                                                                String repoName, String appId,
                                                                Collection<Permission> permission); CompletableFuture<Collection<Permission>> findPermissions(String projectName, String repoName,
                                                                     User user); CompletableFuture<Collection<Permission>> findPermissions(String projectName, String repoName,
                                                                     String appId); CompletableFuture<ProjectRole> findRole(String projectName, User user); CompletableFuture<Tokens> getTokens(); CompletableFuture<Revision> createToken(Author author, String appId); CompletableFuture<Revision> createToken(Author author, String appId, boolean isAdmin); CompletableFuture<Revision> createToken(Author author, String appId, String secret); CompletableFuture<Revision> createToken(Author author, String appId, String secret,
                                                   boolean isAdmin); CompletableFuture<Revision> destroyToken(Author author, String appId); CompletableFuture<Revision> activateToken(Author author, String appId); CompletableFuture<Revision> deactivateToken(Author author, String appId); CompletableFuture<Token> findTokenByAppId(String appId); CompletableFuture<Token> findTokenBySecret(String secret); }
MetadataService { public CompletableFuture<Revision> destroyToken(Author author, String appId) { requireNonNull(author, "author"); requireNonNull(appId, "appId"); final Collection<Project> projects = new SafeProjectManager(projectManager).list().values(); final CompletableFuture<?>[] futures = new CompletableFuture<?>[projects.size()]; int i = 0; for (final Project p : projects) { futures[i++] = removeToken(p.name(), author, appId, true).toCompletableFuture(); } return CompletableFuture.allOf(futures).thenCompose(unused -> tokenRepo.push( INTERNAL_PROJ, Project.REPO_DOGMA, author, "Remove the token: " + appId, () -> tokenRepo.fetch(INTERNAL_PROJ, Project.REPO_DOGMA, TOKEN_JSON) .thenApply(tokens -> { final Token token = tokens.object().get(appId); final JsonPointer appIdPath = JsonPointer.compile("/appIds" + encodeSegment(appId)); final String secret = token.secret(); assert secret != null; final JsonPointer secretPath = JsonPointer.compile("/secrets" + encodeSegment(secret)); final Change<?> change = Change.ofJsonPatch( TOKEN_JSON, asJsonArray(new RemoveOperation(appIdPath), new RemoveIfExistsOperation(secretPath))); return HolderWithRevision.of(change, tokens.revision()); })) ); } MetadataService(ProjectManager projectManager, CommandExecutor executor); CompletableFuture<ProjectMetadata> getProject(String projectName); CompletableFuture<Revision> removeProject(Author author, String projectName); CompletableFuture<Revision> restoreProject(Author author, String projectName); CompletableFuture<Member> getMember(String projectName, User user); CompletableFuture<Revision> addMember(Author author, String projectName,
                                                 User member, ProjectRole projectRole); CompletableFuture<Revision> removeMember(Author author, String projectName, User member); CompletableFuture<Revision> updateMemberRole(Author author, String projectName,
                                                        User member, ProjectRole projectRole); CompletableFuture<RepositoryMetadata> getRepo(String projectName, String repoName); CompletableFuture<Revision> addRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> addRepo(Author author, String projectName, String repoName,
                                               PerRolePermissions permission); CompletableFuture<Revision> removeRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> purgeRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> restoreRepo(Author author, String projectName, String repoName); CompletableFuture<Revision> updatePerRolePermissions(Author author,
                                                                String projectName, String repoName,
                                                                PerRolePermissions perRolePermissions); CompletableFuture<Revision> addToken(Author author, String projectName,
                                                Token token, ProjectRole role); CompletableFuture<Revision> addToken(Author author, String projectName,
                                                String appId, ProjectRole role); CompletableFuture<Revision> removeToken(Author author, String projectName, Token token); CompletableFuture<Revision> removeToken(Author author, String projectName, String appId); CompletableFuture<Revision> updateTokenRole(Author author, String projectName,
                                                       Token token, ProjectRole role); CompletableFuture<Revision> addPerUserPermission(Author author, String projectName,
                                                            String repoName, User member,
                                                            Collection<Permission> permission); CompletableFuture<Revision> removePerUserPermission(Author author, String projectName,
                                                               String repoName, User member); CompletableFuture<Revision> updatePerUserPermission(Author author, String projectName,
                                                               String repoName, User member,
                                                               Collection<Permission> permission); CompletableFuture<Revision> addPerTokenPermission(Author author, String projectName,
                                                             String repoName, String appId,
                                                             Collection<Permission> permission); CompletableFuture<Revision> removePerTokenPermission(Author author, String projectName,
                                                                String repoName, String appId); CompletableFuture<Revision> updatePerTokenPermission(Author author, String projectName,
                                                                String repoName, String appId,
                                                                Collection<Permission> permission); CompletableFuture<Collection<Permission>> findPermissions(String projectName, String repoName,
                                                                     User user); CompletableFuture<Collection<Permission>> findPermissions(String projectName, String repoName,
                                                                     String appId); CompletableFuture<ProjectRole> findRole(String projectName, User user); CompletableFuture<Tokens> getTokens(); CompletableFuture<Revision> createToken(Author author, String appId); CompletableFuture<Revision> createToken(Author author, String appId, boolean isAdmin); CompletableFuture<Revision> createToken(Author author, String appId, String secret); CompletableFuture<Revision> createToken(Author author, String appId, String secret,
                                                   boolean isAdmin); CompletableFuture<Revision> destroyToken(Author author, String appId); CompletableFuture<Revision> activateToken(Author author, String appId); CompletableFuture<Revision> deactivateToken(Author author, String appId); CompletableFuture<Token> findTokenByAppId(String appId); CompletableFuture<Token> findTokenBySecret(String secret); static final String METADATA_JSON; }