torii_lib/platforms/
runner.rs1use super::github::GitHubRunnerClient;
10use super::gitlab::GitLabRunnerClient;
11use crate::error::{Result, ToriiError};
12use serde::{Deserialize, Serialize};
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Runner {
16 pub id: String,
18 pub description: String,
19 pub status: String,
21 pub paused: bool,
22 pub ip_address: String,
23 pub os: String,
24 pub tags: Vec<String>,
25 pub version: String,
26 pub runner_type: String,
29 pub web_url: String,
30}
31
32#[allow(dead_code)]
33pub trait RunnerClient: Send {
34 fn list(&self, owner: &str, repo: &str) -> Result<Vec<Runner>>;
35 fn show(&self, owner: &str, repo: &str, id: &str) -> Result<Runner>;
36 fn remove(&self, owner: &str, repo: &str, id: &str) -> Result<()>;
37 fn reset_token(&self, owner: &str, repo: &str, id: &str) -> Result<String>;
40 fn pause(&self, owner: &str, repo: &str, id: &str) -> Result<()>;
41 fn resume(&self, owner: &str, repo: &str, id: &str) -> Result<()>;
42 fn registration_token(&self, owner: &str, repo: &str) -> Result<RegistrationToken>;
47}
48
49#[derive(Debug, Clone)]
50pub struct RegistrationToken {
51 pub token: String,
52 pub register_url: String,
55 pub expires_in_seconds: Option<u64>,
58}
59
60pub(crate) fn set_paused(
65 c: &GitLabRunnerClient,
66 _owner: &str,
67 _repo: &str,
68 id: &str,
69 paused: bool,
70) -> Result<()> {
71 let url = format!("{}/runners/{}", c.base_url, id);
72 let req = c
73 .client()
74 .put(&url)
75 .header("Authorization", c.auth())
76 .json(&serde_json::json!({ "paused": paused }));
77 crate::http::send_empty(req, &format!("GitLab set runner.paused={}", paused))
78}
79
80pub fn get_runner_client(platform: &str) -> Result<Box<dyn RunnerClient>> {
81 match platform {
82 "gitlab" => Ok(Box::new(GitLabRunnerClient::new()?)),
83 "github" => Ok(Box::new(GitHubRunnerClient::new()?)),
84 other => Err(ToriiError::Unsupported(format!(
85 "Runners surface not implemented for `{}` yet. \
86 Supported: github, gitlab.",
87 other
88 ))),
89 }
90}