Skip to content

Commit

Permalink
[MRELEASE-1139] Improve logging of sources for used credentials
Browse files Browse the repository at this point in the history
Clarify precedence of credentials resolved via settings and those
explicitly given.
  • Loading branch information
kwin committed Feb 2, 2024
1 parent 0f5e7a1 commit 0b3dd73
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
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}.
* 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,56 @@ 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 Down

0 comments on commit 0b3dd73

Please sign in to comment.