Search in sources :

Example 1 with ConsistencyCheckInfo

use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo in project gerrit by GerritCodeReview.

the class CheckConsistency method apply.

@Override
public ConsistencyCheckInfo apply(ConfigResource resource, ConsistencyCheckInput input) throws RestApiException, IOException {
    IdentifiedUser user = userProvider.get();
    if (!user.isIdentifiedUser()) {
        throw new AuthException("Authentication required");
    }
    if (!user.getCapabilities().canAccessDatabase()) {
        throw new AuthException("not allowed to run consistency checks");
    }
    if (input == null || input.checkAccountExternalIds == null) {
        throw new BadRequestException("input required");
    }
    ConsistencyCheckInfo consistencyCheckInfo = new ConsistencyCheckInfo();
    if (input.checkAccountExternalIds != null) {
        consistencyCheckInfo.checkAccountExternalIdsResult = new CheckAccountExternalIdsResultInfo(externalIdsConsistencyChecker.check());
    }
    return consistencyCheckInfo;
}
Also used : ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) AuthException(com.google.gerrit.extensions.restapi.AuthException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) CheckAccountExternalIdsResultInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckAccountExternalIdsResultInfo)

Example 2 with ConsistencyCheckInfo

use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo in project gerrit by GerritCodeReview.

the class CheckConsistency method apply.

@Override
public Response<ConsistencyCheckInfo> apply(ConfigResource resource, ConsistencyCheckInput input) throws RestApiException, IOException, PermissionBackendException, ConfigInvalidException {
    permissionBackend.currentUser().check(GlobalPermission.ACCESS_DATABASE);
    if (input == null || (input.checkAccounts == null && input.checkAccountExternalIds == null && input.checkGroups == null)) {
        throw new BadRequestException("input required");
    }
    ConsistencyCheckInfo consistencyCheckInfo = new ConsistencyCheckInfo();
    if (input.checkAccounts != null) {
        consistencyCheckInfo.checkAccountsResult = new CheckAccountsResultInfo(accountsConsistencyChecker.check());
    }
    if (input.checkAccountExternalIds != null) {
        consistencyCheckInfo.checkAccountExternalIdsResult = new CheckAccountExternalIdsResultInfo(externalIdsConsistencyChecker.check());
    }
    if (input.checkGroups != null) {
        consistencyCheckInfo.checkGroupsResult = new CheckGroupsResultInfo(groupsConsistencyChecker.check());
    }
    return Response.ok(consistencyCheckInfo);
}
Also used : CheckAccountsResultInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckAccountsResultInfo) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) CheckGroupsResultInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckGroupsResultInfo) CheckAccountExternalIdsResultInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckAccountExternalIdsResultInfo)

Example 3 with ConsistencyCheckInfo

use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo in project gerrit by GerritCodeReview.

the class GroupsConsistencyIT method check.

private List<ConsistencyProblemInfo> check() throws Exception {
    ConsistencyCheckInput in = new ConsistencyCheckInput();
    in.checkGroups = new ConsistencyCheckInput.CheckGroupsInput();
    ConsistencyCheckInfo info = gApi.config().server().checkConsistency(in);
    return info.checkGroupsResult.problems;
}
Also used : ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo)

Example 4 with ConsistencyCheckInfo

use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo in project gerrit by GerritCodeReview.

the class AccountIT method checkConsistency.

@Test
public void checkConsistency() throws Exception {
    projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
    requestScopeOperations.resetCurrentApiUser();
    // Create an account with a preferred email.
    String username = name("foo");
    String email = username + "@example.com";
    TestAccount account = accountCreator.create(username, email, "Foo Bar", null);
    ConsistencyCheckInput input = new ConsistencyCheckInput();
    input.checkAccounts = new CheckAccountsInput();
    ConsistencyCheckInfo checkInfo = gApi.config().server().checkConsistency(input);
    assertThat(checkInfo.checkAccountsResult.problems).isEmpty();
    Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
    // Delete the external ID for the preferred email. This makes the account inconsistent since it
    // now doesn't have an external ID for its preferred email.
    accountsUpdateProvider.get().update("Delete External ID", account.id(), u -> u.deleteExternalId(externalIdFactory.createEmail(account.id(), email)));
    expectedProblems.add(new ConsistencyProblemInfo(ConsistencyProblemInfo.Status.ERROR, "Account '" + account.id().get() + "' has no external ID for its preferred email '" + email + "'"));
    checkInfo = gApi.config().server().checkConsistency(input);
    assertThat(checkInfo.checkAccountsResult.problems).hasSize(expectedProblems.size());
    assertThat(checkInfo.checkAccountsResult.problems).containsExactlyElementsIn(expectedProblems);
}
Also used : ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) CheckAccountsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) HashSet(java.util.HashSet) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with ConsistencyCheckInfo

use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo in project gerrit by GerritCodeReview.

the class ExternalIdIT method checkConsistency.

@Test
public void checkConsistency() throws Exception {
    projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
    requestScopeOperations.resetCurrentApiUser();
    insertValidExternalIds();
    ConsistencyCheckInput input = new ConsistencyCheckInput();
    input.checkAccountExternalIds = new CheckAccountExternalIdsInput();
    ConsistencyCheckInfo checkInfo = gApi.config().server().checkConsistency(input);
    assertThat(checkInfo.checkAccountExternalIdsResult.problems).isEmpty();
    Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
    expectedProblems.addAll(insertInvalidButParsableExternalIds());
    expectedProblems.addAll(insertNonParsableExternalIds());
    checkInfo = gApi.config().server().checkConsistency(input);
    assertThat(checkInfo.checkAccountExternalIdsResult.problems).hasSize(expectedProblems.size());
    assertThat(checkInfo.checkAccountExternalIdsResult.problems).containsExactlyElementsIn(expectedProblems);
}
Also used : ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) CheckAccountExternalIdsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountExternalIdsInput) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) HashSet(java.util.HashSet) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ConsistencyCheckInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo)5 ConsistencyCheckInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 CheckAccountExternalIdsResultInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckAccountExternalIdsResultInfo)2 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)2 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 TestAccount (com.google.gerrit.acceptance.TestAccount)1 CheckAccountsResultInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckAccountsResultInfo)1 CheckGroupsResultInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.CheckGroupsResultInfo)1 CheckAccountExternalIdsInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountExternalIdsInput)1 CheckAccountsInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1