@@ -14,6 +14,11 @@
# openpower.toml - example configuration file
#
+[git]
+user = "git"
+public_key = "/home/ruscur/.ssh/id_rsa.pub"
+private_key = "/home/ruscur/.ssh/id_rsa"
+
[patchwork]
url = "https://russell.cc/patchwork"
port = 443 #optional
@@ -14,13 +14,15 @@
// git.rs - snowpatch git functionality
//
-use git2::{Repository, Commit, Remote, Error, PushOptions};
+use git2::{Repository, Commit, Remote, Error, PushOptions, Cred};
use git2::build::CheckoutBuilder;
use std::result::Result;
use std::path::Path;
use std::process::{Command, Output};
+use settings::Git;
+
pub static GIT_REF_BASE: &'static str = "refs/heads";
pub fn get_latest_commit(repo: &Repository) -> Commit {
@@ -89,6 +91,17 @@ pub fn apply_patch(repo: &Repository, path: &Path)
}
}
+pub fn cred_from_settings(settings: &Git) -> Result<Cred, Error> {
+ // We have to convert from Option<String> to Option<&str>
+ let public_key = settings.public_key.as_ref().map(String::as_ref);
+ let passphrase = settings.passphrase.as_ref().map(String::as_ref);
+
+ Cred::ssh_key(&settings.user,
+ public_key,
+ Path::new(&settings.private_key),
+ passphrase)
+}
+
#[cfg(test)]
mod tests {
#[test]
@@ -31,7 +31,7 @@ extern crate url;
extern crate log;
extern crate env_logger;
-use git2::{Cred, BranchType, RemoteCallbacks, PushOptions};
+use git2::{BranchType, RemoteCallbacks, PushOptions};
use hyper::Client;
use hyper::client::ProxyConfig;
@@ -155,7 +155,7 @@ fn test_patch(settings: &Config, client: &Arc<Client>, project: &Project, path:
let mut push_callbacks = RemoteCallbacks::new();
push_callbacks.credentials(|_, _, _| {
- Cred::ssh_key_from_agent("git")
+ git::cred_from_settings(&settings.git)
});
let mut push_opts = PushOptions::new();
@@ -28,6 +28,14 @@ use std::collections::BTreeMap;
// TODO: Give more informative error messages when we fail to parse.
#[derive(RustcDecodable, Clone)]
+pub struct Git {
+ pub user: String,
+ pub public_key: Option<String>,
+ pub private_key: String,
+ pub passphrase: Option<String>
+}
+
+#[derive(RustcDecodable, Clone)]
pub struct Patchwork {
pub url: String,
pub port: Option<u16>,
@@ -65,6 +73,7 @@ impl Project {
#[derive(RustcDecodable, Clone)]
pub struct Config {
+ pub git: Git,
pub patchwork: Patchwork,
pub jenkins: Jenkins,
pub projects: BTreeMap<String, Project>