summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2023-07-02 01:28:21 -0700
committeriximeow <me@iximeow.net>2023-07-02 01:28:21 -0700
commitd156c64d7088b43212b8d2c804e8ae8bf7195724 (patch)
treec1c92d3933dc75691277ed8b7fd9577edb1c83ed
parentd22d4794a1e4c4794d7c300d1ffff3af56385930 (diff)
make client configurable
-rw-r--r--.gitignore1
-rw-r--r--src/ci_runner.rs20
2 files changed, 15 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index f53e36c..ab132b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ state.db
auth_secret
driver_config.json
webserver_config.json
+runner_config.json
diff --git a/src/ci_runner.rs b/src/ci_runner.rs
index 193c471..3ecacdb 100644
--- a/src/ci_runner.rs
+++ b/src/ci_runner.rs
@@ -428,29 +428,37 @@ impl RunnerClient {
}
}
+#[derive(Deserialize, Serialize)]
+struct RunnerConfig {
+ server_address: String,
+ auth_secret: String,
+ allowed_pushers: Option<Vec<String>>,
+}
+
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
- let secret = std::fs::read_to_string("./auth_secret").unwrap();
+ let mut args = std::env::args();
+ args.next().expect("first arg exists");
+ let config_path = args.next().unwrap_or("./runner_config.json".to_string());
+ let runner_config: RunnerConfig = serde_json::from_reader(std::fs::File::open(config_path).expect("file exists and is accessible")).expect("valid json for RunnerConfig");
let client = reqwest::ClientBuilder::new()
.connect_timeout(Duration::from_millis(1000))
.timeout(Duration::from_millis(600000))
.build()
.expect("can build client");
- let allowed_pushers: Option<Vec<String>> = None;
-
loop {
let (mut sender, body) = hyper::Body::channel();
sender.send_data(serde_json::to_string(&json!({
"kind": "new_job_please",
- "accepted_pushers": &["git@iximeow.net", "me@iximeow.net"],
+ "accepted_pushers": &runner_config.allowed_pushers,
})).unwrap().into()).await.expect("req");
let poll = client.post("https://ci.butactuallyin.space:9876/api/next_job")
.header("user-agent", "ci-butactuallyin-space-runner")
- .header("authorization", secret.trim())
+ .header("authorization", runner_config.auth_secret.trim())
.body(body)
.send()
.await;
@@ -465,7 +473,7 @@ async fn main() {
continue;
}
};
- let job = match client.wait_for_work(allowed_pushers.as_ref().map(|x| x.as_ref())).await {
+ let job = match client.wait_for_work(runner_config.allowed_pushers.as_ref().map(|x| x.as_ref())).await {
Ok(Some(request)) => request,
Ok(None) => {
eprintln!("no work to do (yet)");