Search in sources :

Example 1 with PushCertificateInfo

use of com.google.gerrit.extensions.common.PushCertificateInfo in project gerrit by GerritCodeReview.

the class ChangeJson method toRevisionInfo.

private RevisionInfo toRevisionInfo(ChangeControl ctl, ChangeData cd, PatchSet in, @Nullable Repository repo, @Nullable RevWalk rw, boolean fillCommit, @Nullable ChangeInfo changeInfo) throws PatchListNotAvailableException, GpgException, OrmException, IOException {
    Change c = ctl.getChange();
    RevisionInfo out = new RevisionInfo();
    out.isCurrent = in.getId().equals(c.currentPatchSetId());
    out._number = in.getId().get();
    out.ref = in.getRefName();
    out.created = in.getCreatedOn();
    out.uploader = accountLoader.get(in.getUploader());
    out.draft = in.isDraft() ? true : null;
    out.fetch = makeFetchMap(ctl, in);
    out.kind = changeKindCache.getChangeKind(rw, repo != null ? repo.getConfig() : null, cd, in);
    out.description = in.getDescription();
    boolean setCommit = has(ALL_COMMITS) || (out.isCurrent && has(CURRENT_COMMIT));
    boolean addFooters = out.isCurrent && has(COMMIT_FOOTERS);
    if (setCommit || addFooters) {
        checkState(rw != null);
        checkState(repo != null);
        Project.NameKey project = c.getProject();
        String rev = in.getRevision().get();
        RevCommit commit = rw.parseCommit(ObjectId.fromString(rev));
        rw.parseBody(commit);
        if (setCommit) {
            out.commit = toCommit(ctl, rw, commit, has(WEB_LINKS), fillCommit);
        }
        if (addFooters) {
            Ref ref = repo.exactRef(ctl.getChange().getDest().get());
            RevCommit mergeTip = null;
            if (ref != null) {
                mergeTip = rw.parseCommit(ref.getObjectId());
                rw.parseBody(mergeTip);
            }
            out.commitWithFooters = mergeUtilFactory.create(projectCache.get(project)).createCommitMessageOnSubmit(commit, mergeTip, ctl, in.getId());
        }
    }
    if (has(ALL_FILES) || (out.isCurrent && has(CURRENT_FILES))) {
        out.files = fileInfoJson.toFileInfoMap(c, in);
        out.files.remove(Patch.COMMIT_MSG);
        out.files.remove(Patch.MERGE_LIST);
    }
    if ((out.isCurrent || (out.draft != null && out.draft)) && has(CURRENT_ACTIONS) && userProvider.get().isIdentifiedUser()) {
        actionJson.addRevisionActions(changeInfo, out, new RevisionResource(changeResourceFactory.create(ctl), in));
    }
    if (gpgApi.isEnabled() && has(PUSH_CERTIFICATES)) {
        if (in.getPushCertificate() != null) {
            out.pushCertificate = gpgApi.checkPushCertificate(in.getPushCertificate(), userFactory.create(in.getUploader()));
        } else {
            out.pushCertificate = new PushCertificateInfo();
        }
    }
    return out;
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Ref(org.eclipse.jgit.lib.Ref) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) Change(com.google.gerrit.reviewdb.client.Change) PushCertificateInfo(com.google.gerrit.extensions.common.PushCertificateInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with PushCertificateInfo

use of com.google.gerrit.extensions.common.PushCertificateInfo in project gerrit by GerritCodeReview.

the class GpgApiAdapterImpl method checkPushCertificate.

@Override
public PushCertificateInfo checkPushCertificate(String certStr, IdentifiedUser expectedUser) throws GpgException {
    try {
        PushCertificate cert = PushCertificateParser.fromString(certStr);
        PushCertificateChecker.Result result = pushCertCheckerFactory.create(expectedUser).setCheckNonce(false).check(cert);
        PushCertificateInfo info = new PushCertificateInfo();
        info.certificate = certStr;
        info.key = GpgKeys.toJson(result.getPublicKey(), result.getCheckResult());
        return info;
    } catch (IOException e) {
        throw new GpgException(e);
    }
}
Also used : GpgException(com.google.gerrit.server.GpgException) PushCertificate(org.eclipse.jgit.transport.PushCertificate) GerritPushCertificateChecker(com.google.gerrit.gpg.GerritPushCertificateChecker) PushCertificateChecker(com.google.gerrit.gpg.PushCertificateChecker) IOException(java.io.IOException) PushCertificateInfo(com.google.gerrit.extensions.common.PushCertificateInfo)

Example 3 with PushCertificateInfo

use of com.google.gerrit.extensions.common.PushCertificateInfo in project gerrit by GerritCodeReview.

the class RevisionJson method toRevisionInfo.

private RevisionInfo toRevisionInfo(AccountLoader accountLoader, ChangeData cd, PatchSet in, @Nullable Repository repo, @Nullable RevWalk rw, boolean fillCommit, @Nullable ChangeInfo changeInfo) throws PatchListNotAvailableException, GpgException, IOException, PermissionBackendException {
    Change c = cd.change();
    RevisionInfo out = new RevisionInfo();
    out.isCurrent = in.id().equals(c.currentPatchSetId());
    out._number = in.id().get();
    out.ref = in.refName();
    out.setCreated(in.createdOn());
    out.uploader = accountLoader.get(in.uploader());
    out.fetch = makeFetchMap(cd, in);
    out.kind = changeKindCache.getChangeKind(rw, repo != null ? repo.getConfig() : null, cd, in);
    out.description = in.description().orElse(null);
    boolean setCommit = has(ALL_COMMITS) || (out.isCurrent && has(CURRENT_COMMIT));
    boolean addFooters = out.isCurrent && has(COMMIT_FOOTERS);
    if (setCommit || addFooters) {
        checkState(rw != null);
        checkState(repo != null);
        Project.NameKey project = c.getProject();
        String rev = in.commitId().name();
        RevCommit commit = rw.parseCommit(ObjectId.fromString(rev));
        rw.parseBody(commit);
        String branchName = cd.change().getDest().branch();
        if (setCommit) {
            out.commit = getCommitInfo(project, rw, commit, has(WEB_LINKS), fillCommit, branchName);
        }
        if (addFooters) {
            Ref ref = repo.exactRef(branchName);
            RevCommit mergeTip = null;
            if (ref != null) {
                mergeTip = rw.parseCommit(ref.getObjectId());
                rw.parseBody(mergeTip);
            }
            out.commitWithFooters = mergeUtilFactory.create(projectCache.get(project).orElseThrow(illegalState(project))).createCommitMessageOnSubmit(commit, mergeTip, cd.notes(), in.id());
        }
    }
    if (has(ALL_FILES) || (out.isCurrent && has(CURRENT_FILES))) {
        try {
            out.files = fileInfoJson.getFileInfoMap(c, in);
            out.files.remove(Patch.COMMIT_MSG);
            out.files.remove(Patch.MERGE_LIST);
        } catch (ResourceConflictException e) {
            logger.atWarning().withCause(e).log("creating file list failed");
        }
    }
    if (out.isCurrent && has(CURRENT_ACTIONS) && userProvider.get().isIdentifiedUser()) {
        actionJson.addRevisionActions(changeInfo, out, new RevisionResource(changeResourceFactory.create(cd, userProvider.get()), in));
    }
    if (gpgApi.isEnabled() && has(PUSH_CERTIFICATES)) {
        if (in.pushCertificate().isPresent()) {
            out.pushCertificate = gpgApi.checkPushCertificate(in.pushCertificate().get(), userFactory.create(in.uploader()));
        } else {
            out.pushCertificate = new PushCertificateInfo();
        }
    }
    return out;
}
Also used : Project(com.google.gerrit.entities.Project) Ref(org.eclipse.jgit.lib.Ref) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) Change(com.google.gerrit.entities.Change) PushCertificateInfo(com.google.gerrit.extensions.common.PushCertificateInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

PushCertificateInfo (com.google.gerrit.extensions.common.PushCertificateInfo)3 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)2 Ref (org.eclipse.jgit.lib.Ref)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 Change (com.google.gerrit.entities.Change)1 Project (com.google.gerrit.entities.Project)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 GerritPushCertificateChecker (com.google.gerrit.gpg.GerritPushCertificateChecker)1 PushCertificateChecker (com.google.gerrit.gpg.PushCertificateChecker)1 Change (com.google.gerrit.reviewdb.client.Change)1 Project (com.google.gerrit.reviewdb.client.Project)1 GpgException (com.google.gerrit.server.GpgException)1 IOException (java.io.IOException)1 PushCertificate (org.eclipse.jgit.transport.PushCertificate)1