Skip to content

Commit

Permalink
allow optional credentials on git so it works nicely inside the secur…
Browse files Browse the repository at this point in the history
…ed fabric
  • Loading branch information
jstrachan committed May 16, 2013
1 parent b3ddf80 commit e6d3765
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions hawtio-git/src/main/java/io/hawt/git/GitFacade.java
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.gitective.core.BlobUtils;
import org.gitective.core.CommitFinder;
import org.gitective.core.CommitUtils;
Expand All @@ -31,13 +32,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -60,6 +58,7 @@ public class GitFacade extends MBeanSupport implements GitFacadeMXBean {
private String defaultRemoteRepository = "https://github.com/hawtio/hawtio-config.git";
private Boolean cloneRemoteRepoOnStartup;
private boolean pullOnStartup = true;
private CredentialsProvider credentials;


public void init() throws Exception {
Expand All @@ -73,7 +72,6 @@ public void init() throws Exception {
protected String getDefaultObjectName() {
return "io.hawt.git:type=GitFacade";
}

public String getRemoteRepository() {
if (remoteRepository == null) {
remoteRepository = getSystemPropertyOrEnvironmentVariable("hawtio.config.repo", "HAWTIO_CONFIG_REPO");
Expand Down Expand Up @@ -132,6 +130,14 @@ public void setCloneRemoteRepoOnStartup(boolean cloneRemoteRepoOnStartup) {
this.cloneRemoteRepoOnStartup = cloneRemoteRepoOnStartup;
}

public CredentialsProvider getCredentials() {
return credentials;
}

public void setCredentials(CredentialsProvider credentials) {
this.credentials = credentials;
}

/**
* Reads the file contents of the given path
*
Expand Down Expand Up @@ -478,6 +484,9 @@ public void initialiseGitRepo() throws IOException, GitAPIException {
if (Strings.isNotBlank(repo) && isCloneRemoteRepoOnStartup()) {
LOG.info("Cloning git repo " + repo + " into directory " + confDir.getCanonicalPath());
CloneCommand clone = Git.cloneRepository().setURI(repo).setDirectory(confDir).setRemote(remote);
if (credentials != null) {
clone = clone.setCredentialsProvider(credentials);
}
try {
git = clone.call();
return;
Expand Down

0 comments on commit e6d3765

Please sign in to comment.