Refactor GPG key handling to allow using separate GPG keys.

Closes #7
This commit is contained in:
Mark Paluch
2022-11-14 08:48:59 +01:00
parent 9787750d5f
commit 6a9c3c8027
10 changed files with 74 additions and 16 deletions

View File

@@ -40,7 +40,6 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.io.IOUtils;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.data.release.build.CommandLine.Argument;
@@ -49,6 +48,7 @@ import org.springframework.data.release.build.Pom.Artifact;
import org.springframework.data.release.deployment.DefaultDeploymentInformation;
import org.springframework.data.release.deployment.DeploymentInformation;
import org.springframework.data.release.deployment.DeploymentProperties;
import org.springframework.data.release.deployment.DeploymentProperties.MavenCentral;
import org.springframework.data.release.deployment.StagingRepository;
import org.springframework.data.release.io.Workspace;
import org.springframework.data.release.model.ArtifactVersion;
@@ -63,7 +63,6 @@ import org.springframework.data.release.utils.Logger;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.xmlbeam.ProjectionFactory;
import org.xmlbeam.XBProjector;
import org.xmlbeam.dom.DOMAccess;
@@ -418,6 +417,8 @@ class MavenBuildSystem implements BuildSystem {
logger.log(BUILD, "Verifying Maven Build System…");
Gpg gpg = getGpg();
CommandLine arguments = CommandLine.of(Goal.CLEAN, Goal.VERIFY, //
profile("central"), //
SKIP_TESTS, //
@@ -488,6 +489,8 @@ class MavenBuildSystem implements BuildSystem {
logger.log(module, "Deploying artifacts to Sonatype OSS Nexus…");
Gpg gpg = getGpg();
CommandLine arguments = CommandLine.of(Goal.CLEAN, Goal.DEPLOY, //
profile("ci,release,central"), //
SKIP_TESTS, //
@@ -510,6 +513,17 @@ class MavenBuildSystem implements BuildSystem {
doWithProjection(file, Pom.class, callback);
}
private Gpg getGpg() {
MavenCentral mavenCentral = properties.getMavenCentral();
if (mavenCentral.hasGpgConfiguration()) {
return mavenCentral.getGpg();
}
return gpg;
}
/**
* TODO: Move XML file callbacks using the {@link ProjectionFactory} to {@link Workspace}.
*/

View File

@@ -15,17 +15,18 @@
*/
package org.springframework.data.release.deployment;
import lombok.Data;
import java.net.URI;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.release.model.Gpg;
import org.springframework.data.release.model.Password;
import org.springframework.data.release.utils.HttpBasicCredentials;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.util.UriTemplate;
import lombok.Data;
/**
* @author Oliver Gierke
* @author Mark Paluch
@@ -126,6 +127,11 @@ public class DeploymentProperties {
private String stagingProfileId;
private Gpg gpg;
public boolean hasGpgConfiguration() {
return gpg != null && gpg.isGpgAvailable();
}
}
}

View File

@@ -25,7 +25,19 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
@@ -58,7 +70,6 @@ import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.TagOpt;
import org.eclipse.jgit.transport.URIish;
import org.springframework.data.release.io.Workspace;
import org.springframework.data.release.issues.IssueTracker;
import org.springframework.data.release.issues.Ticket;
@@ -697,6 +708,8 @@ public class GitOperations {
String email = gitProperties.getEmail();
boolean allowEmpty = all;
Gpg gpg = getGpg();
logger.log(project, "git commit -m \"%s\" %s --author=\"%s <%s>\"", commit.getSummary(),
gpg.isGpgAvailable() ? "-S" + gpg.getKeyname() : "", author, email);
@@ -1077,6 +1090,15 @@ public class GitOperations {
void doWithGit(Git git) throws Exception;
}
private Gpg getGpg() {
if (gitProperties.hasGpgConfiguration()) {
return gitProperties.getGpg();
}
return gpg;
}
/**
* {@link CredentialsProvider} for GPG Keys used with JGit Commit Signing.
*/
@@ -1127,8 +1149,4 @@ public class GitOperations {
return false;
}
}
private static class VersionedIterations {
}
}

View File

@@ -24,6 +24,7 @@ import javax.annotation.PostConstruct;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.release.model.Gpg;
import org.springframework.data.release.model.Password;
import org.springframework.data.release.utils.HttpBasicCredentials;
import org.springframework.stereotype.Component;
@@ -43,6 +44,8 @@ public class GitProperties {
private @Getter(AccessLevel.PRIVATE) Password password;
private String username, author, email;
private Gpg gpg;
@PostConstruct
public void init() {
@@ -64,4 +67,8 @@ public class GitProperties {
public HttpBasicCredentials getHttpCredentials() {
return new HttpBasicCredentials(username, password);
}
public boolean hasGpgConfiguration() {
return gpg != null && gpg.isGpgAvailable();
}
}

View File

@@ -614,7 +614,7 @@ public class GitHub extends GitHubSupport implements IssueTracker {
throw new IllegalStateException(String.format("Cannot obtain /user. Status: %s", entity.getStatusCode()));
}
logger.log("GitHub", "Authentication verified!");
logger.log("GitHub", "Authentication verified.");
}
private String getDocumentationLinks(ModuleIteration module, DocumentationMetadata documentation) {

View File

@@ -3,7 +3,10 @@ git.author=${GIT_AUTHOR}
git.email=${GIT_EMAIL}
git.password=${GIT_PASSWORD}
github.api.url=${GITHUB_API_URL}
git.gpg.keyname=6743E1BD
git.gpg.passphrase=${GIT_SIGNING_KEY_PASSWORD}
git.gpg.secretKeyring=${GNUPGHOME}/secring.gpg
git.gpg.executable=/usr/bin/gpg
deployment.username=${DEPLOYMENT_API_KEY_USR}
deployment.password=${DEPLOYMENT_API_KEY_PSW}
@@ -22,5 +25,10 @@ maven.home=${MAVEN_HOME}
maven.console-logger=false
maven.repo.local=${RELEASE_TOOLS_CACHE}
maven.maven-central.gpg.keyname=${GPG_KEYNAME}
maven.maven-central.gpg.passphrase=${PASSPHRASE}
maven.maven-central.gpg.secretKeyring=${GNUPGHOME}/secring.gpg
maven.maven-central.gpg.executable=/usr/bin/gpg
io.workDir=dist
io.logs=${LOGS_DIR}