use of org.eclipse.jgit.util.FS in project opsgenie-configuration-backup by opsgenie.
the class BaseBackup method cloneGit.
void cloneGit(final BackupProperties properties) throws GitAPIException {
properties.setPath(properties.getPath() + "/OpsGenieBackupGitRepository");
String rootPath = properties.getPath();
File backupGitDirectory = new File(rootPath);
if (backupGitDirectory.exists() && (backupGitDirectory.list() != null) && (backupGitDirectory.list().length > 0)) {
logger.warn("Destination path " + rootPath + " already exists and is not an empty directory");
logger.warn("Destination path " + rootPath + " will be deleted inorder to clone remote git repository");
BackupUtils.deleteDirectory(backupGitDirectory);
backupGitDirectory.mkdirs();
} else {
backupGitDirectory.mkdirs();
}
final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host hc, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
CredentialsProvider provider = new CredentialsProvider() {
@Override
public boolean isInteractive() {
return false;
}
@Override
public boolean supports(CredentialItem... items) {
return true;
}
@Override
public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
for (CredentialItem item : items) {
((CredentialItem.StringType) item).setValue(backupProperties.getPassphrase());
}
return true;
}
};
UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
session.setUserInfo(userInfo);
}
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.removeAllIdentity();
defaultJSch.addIdentity(properties.getSshKeyPath());
return defaultJSch;
}
};
callBack = new TransportConfigCallback() {
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
};
logger.info("Cloning remote git operation started!");
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI(properties.getGitSshUri());
cloneCommand.setTransportConfigCallback(callBack);
StatusLogger.getLogger().setLevel(Level.OFF);
cloneCommand.setDirectory(backupGitDirectory);
git = cloneCommand.call();
logger.info("Cloning remote git operation finished!");
}
use of org.eclipse.jgit.util.FS in project egit by eclipse.
the class GitTestCase method setUp.
@Before
public void setUp() throws Exception {
// ensure there are no shared Repository instances left
// when starting a new test
Activator.getDefault().getRepositoryCache().clear();
File configFile = File.createTempFile("gitconfigtest", "config");
MockSystemReader mockSystemReader = new MockSystemReader() {
@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
return new FileBasedConfig(parent, configFile, fs);
}
};
configFile.deleteOnExit();
SystemReader.setInstance(mockSystemReader);
mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY, ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getParentFile().getAbsoluteFile().toString());
FileBasedConfig userConfig = mockSystemReader.openUserConfig(null, FS.DETECTED);
// We have to set autoDetach to false for tests, because tests expect to
// be able to clean up by recursively removing the repository, and
// background GC might be in the middle of writing or deleting files,
// which would disrupt this.
userConfig.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_AUTODETACH, false);
userConfig.save();
project = new TestProject(true);
gitDir = new File(project.getProject().getWorkspace().getRoot().getRawLocation().toFile(), Constants.DOT_GIT);
if (gitDir.exists())
FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
}
use of org.eclipse.jgit.util.FS in project gitblit by gitblit.
the class SshUnitTest method startGitblit.
@BeforeClass
public static void startGitblit() throws Exception {
generator = SecurityUtils.getKeyPairGenerator("RSA");
started.set(GitBlitSuite.startGitblit());
final SystemReader dsr = SystemReader.getInstance();
SystemReader.setInstance(new SystemReader() {
final SystemReader defaultsr = dsr;
@Override
public String getHostname() {
return defaultsr.getHostname();
}
@Override
public String getenv(String variable) {
if ("GIT_SSH".equalsIgnoreCase(variable)) {
return null;
}
return defaultsr.getenv(variable);
}
@Override
public String getProperty(String key) {
return defaultsr.getProperty(key);
}
@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
return defaultsr.openUserConfig(parent, fs);
}
@Override
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
return defaultsr.openSystemConfig(parent, fs);
}
@Override
public long getCurrentTime() {
return defaultsr.getCurrentTime();
}
@Override
public int getTimezone(long when) {
return defaultsr.getTimezone(when);
}
});
}
use of org.eclipse.jgit.util.FS in project gerrit by GerritCodeReview.
the class SshSessionMina method getMinaSession.
private SshdSession getMinaSession() throws Exception {
if (session == null) {
String username = getUsername();
URIish uri = new URIish("ssh://" + username + "@" + addr.getAddress().getHostAddress() + ":" + addr.getPort());
// TODO(davido): Switch to memory only key resolving mode.
File userhome = createTempDirectory("home-").toFile();
FS fs = FS.DETECTED.setUserHome(userhome);
File sshDir = new File(userhome, ".ssh");
sshDir.mkdir();
OpenSSHKeyPairResourceWriter keyPairWriter = new OpenSSHKeyPairResourceWriter();
try (OutputStream out = new FileOutputStream(new File(sshDir, "id_ecdsa"))) {
keyPairWriter.writePrivateKey(sshKeys.getKeyPair(account), null, null, out);
}
// TODO(davido): Disable programmatically host key checking: "StrictHostKeyChecking: no" mode.
CharSink configFile = Files.asCharSink(new File(sshDir, "config"), UTF_8);
configFile.writeLines(Arrays.asList("Host *", "StrictHostKeyChecking no"));
JGitKeyCache keyCache = new JGitKeyCache();
try (SshdSessionFactory factory = new SshdSessionFactory(keyCache, new DefaultProxyDataFactory())) {
factory.setHomeDirectory(userhome);
factory.setSshDirectory(sshDir);
session = factory.getSession(uri, null, fs, TIMEOUT);
session.addCloseListener(future -> {
try {
MoreFiles.deleteRecursively(userhome.toPath(), ALLOW_INSECURE);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Failed to cleanup userhome", e);
}
});
}
}
return session;
}
use of org.eclipse.jgit.util.FS in project gerrit by GerritCodeReview.
the class StandaloneSiteTest method setFakeSystemReader.
private static SystemReader setFakeSystemReader(File tempDir) {
SystemReader oldSystemReader = SystemReader.getInstance();
SystemReader.setInstance(new DelegateSystemReader(oldSystemReader) {
@Override
public FileBasedConfig openJGitConfig(Config parent, FS fs) {
return new FileBasedConfig(parent, new File(tempDir, "jgit.config"), FS.detect());
}
@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
return new FileBasedConfig(parent, new File(tempDir, "user.config"), FS.detect());
}
@Override
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
return new FileBasedConfig(parent, new File(tempDir, "system.config"), FS.detect());
}
});
return oldSystemReader;
}
Aggregations