Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRELEASE-1139] Improve logging of sources for used credentials #209

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,11 @@ public interface ReleaseDescriptor {
String getScmBranchBase();

/**
* Get the id can be used to get the credentials by the server-id from the settings.xml.
* Get the id which can be used to get the (optionally encrypted) credentials with the given id from the {@code settings.xml}.
michael-o marked this conversation as resolved.
Show resolved Hide resolved
* Explicit credentials in {@link #getScmUsername()}, {@link #getScmPassword()}, {@link #getScmPrivateKey()} or
* {@link #getScmPrivateKeyPassPhrase()} always take precedence, though.
*
* @return String
* @return the server id of a server in {@code settings.xml}
*/
String getScmId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public ScmRepository getConfiguredRepository(String url, ReleaseDescriptor relea

if (releaseDescriptor.getScmId() != null) {
server = settings.getServer(releaseDescriptor.getScmId());
if (server == null) {
logger.warn("No server with id '{}' found in Maven settings", releaseDescriptor.getScmId());
}
}

if (server == null && repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost) {
Expand All @@ -115,39 +118,57 @@ public ScmRepository getConfiguredRepository(String url, ReleaseDescriptor relea
}

if (server != null) {
if (username == null) {
if (username == null && server.getUsername() != null) {
logger.debug(
"Using username from server id '{}' found in Maven settings", releaseDescriptor.getScmId());
username = server.getUsername();
}

if (password == null) {
if (password == null && server.getPassword() != null) {
logger.debug(
"Using password from server id '{}' found in Maven settings", releaseDescriptor.getScmId());
password = decrypt(server.getPassword(), server.getId());
}

if (privateKey == null) {
if (privateKey == null && server.getPrivateKey() != null) {
logger.debug(
"Using private key from server id '{}' found in Maven settings",
releaseDescriptor.getScmId());
privateKey = server.getPrivateKey();
}

if (passphrase == null) {
if (passphrase == null && server.getPassphrase() != null) {
logger.debug(
"Using passphrase from server id '{}' found in Maven settings",
releaseDescriptor.getScmId());
passphrase = decrypt(server.getPassphrase(), server.getId());
}
}
}

if (!(username == null || username.isEmpty())) {
scmRepo.setUser(username);
} else {
logger.debug("No explicit username configured");
}
if (!(password == null || password.isEmpty())) {
scmRepo.setPassword(password);
} else {
logger.debug("No explicit password configured");
}

if (scmRepo instanceof ScmProviderRepositoryWithHost) {
ScmProviderRepositoryWithHost repositoryWithHost = (ScmProviderRepositoryWithHost) scmRepo;
if (!(privateKey == null || privateKey.isEmpty())) {
repositoryWithHost.setPrivateKey(privateKey);
} else {
logger.debug("No explicit private key configured");
}

if (!(passphrase == null || passphrase.isEmpty())) {
repositoryWithHost.setPassphrase(passphrase);
} else {
logger.debug("No explicit passphrase configured");
}
}

Expand All @@ -170,12 +191,12 @@ public ScmRepository getConfiguredRepository(String url, ReleaseDescriptor relea
return repository;
}

private String decrypt(String str, String server) {
private String decrypt(String str, String serverId) {
try {
return mavenCrypto.decrypt(str);
} catch (MavenCryptoException e) {
String msg = "Failed to decrypt password/passphrase for server " + server + ", using auth token as is: "
+ e.getMessage();
String msg = "Failed to decrypt password/passphrase for server with id '" + serverId
+ "', using auth token as is: " + e.getMessage();
if (logger.isDebugEnabled()) {
logger.warn(msg, e);
} else {
Expand Down