glrcfg/runner/
mod.rs

1// Copyright 2024 bmc::labs GmbH. All rights reserved.
2
3mod date_time;
4mod executors;
5mod runner_token;
6mod url;
7
8pub use date_time::DateTime;
9pub use executors::{Docker, Executor, PullPolicy, SecurityOpt, Service, Sysctls};
10pub use runner_token::{RunnerToken, RunnerTokenParseError};
11use serde::Serialize;
12pub use url::Url;
13
14/// Defines one runner.
15///
16/// See the [`Default` implementation](Self::default) for the default values.
17///
18/// Further documentation found in [the GitLab
19/// docs](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section).
20#[derive(Debug, Serialize)]
21pub struct Runner {
22    pub id: u32,
23    pub name: String,
24    pub url: Url,
25    pub token: RunnerToken,
26    /// Timestamp of when the token was "obtained". This field is undocumented in [the GitLab docs
27    /// for the GitLab Runners configuration
28    /// file](https://docs.gitlab.com/runner/configuration/advanced-configuration.html) and it is
29    /// nowhere to be found in [the GitLab API docs](https://docs.gitlab.com/ee/api/runners.html),
30    /// but it is present in the configuration files generated by the `gitlab-runner` binary. It's
31    /// the timestamp of when the token was first handed to the service processing it (and using
32    /// this library).
33    pub token_obtained_at: DateTime,
34    /// Timestamp of when the token will "expire". While being undocumented in the GitLab Runner
35    /// docs for the configuration file, it can be obtained through [the GitLab
36    /// API](https://docs.gitlab.com/ee/api/runners.html#verify-authentication-for-a-registered-runner)
37    /// and can be set here.
38    pub token_expires_at: DateTime,
39    pub limit: u32,
40    #[serde(flatten)]
41    pub executor: Executor,
42    pub builds_dir: String,
43    pub cache_dir: String,
44    /// Used to set environment variables for a runner or job. Example: `["FOO=bar", "BAZ=qux"]`
45    pub environment: Vec<String>,
46    pub request_concurrency: u32,
47    pub output_limit: u32,
48}
49
50impl Default for Runner {
51    fn default() -> Self {
52        Self {
53            id: 1,
54            name: "default".to_string(),
55            url: Url::parse("https://gitlab.com/").expect("given string is a URL"),
56            token: RunnerToken::parse("glrt-0123456789_abcdefXYZ")
57                .expect("given string is a valid token"),
58            token_obtained_at: DateTime::now(),
59            token_expires_at: DateTime::parse("0001-01-01T00:00:00Z")
60                .expect("given string is a valid ISO8601 timestamp"),
61            limit: 0,
62            executor: Executor::Docker {
63                docker: Default::default(),
64            },
65            builds_dir: "".to_string(),
66            cache_dir: "".to_string(),
67            environment: vec![],
68            request_concurrency: 1,
69            output_limit: 4096,
70        }
71    }
72}