gitlab/api/runners/
reset_authentication_token_by_token.rs

1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7use derive_builder::Builder;
8
9use crate::api::endpoint_prelude::*;
10
11/// Reset a runner's authentication token by its current token.
12#[derive(Debug, Builder, Clone)]
13pub struct ResetRunnerAuthenticationTokenByToken<'a> {
14    /// The authentication token of the runner.
15    #[builder(setter(into))]
16    token: Cow<'a, str>,
17}
18
19impl<'a> ResetRunnerAuthenticationTokenByToken<'a> {
20    /// Create a builder for the endpoint.
21    pub fn builder() -> ResetRunnerAuthenticationTokenByTokenBuilder<'a> {
22        ResetRunnerAuthenticationTokenByTokenBuilder::default()
23    }
24}
25
26impl Endpoint for ResetRunnerAuthenticationTokenByToken<'_> {
27    fn method(&self) -> Method {
28        Method::POST
29    }
30
31    fn endpoint(&self) -> Cow<'static, str> {
32        "runners/reset_authentication_token".into()
33    }
34
35    fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
36        let mut params = FormParams::default();
37
38        params.push("token", self.token.as_ref());
39
40        params.into_body()
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use http::Method;
47
48    use crate::api::runners::{
49        ResetRunnerAuthenticationTokenByToken, ResetRunnerAuthenticationTokenByTokenBuilderError,
50    };
51    use crate::api::{self, Query};
52    use crate::test::client::{ExpectedUrl, SingleTestClient};
53
54    #[test]
55    fn token_is_required() {
56        let err = ResetRunnerAuthenticationTokenByToken::builder()
57            .build()
58            .unwrap_err();
59        crate::test::assert_missing_field!(
60            err,
61            ResetRunnerAuthenticationTokenByTokenBuilderError,
62            "token"
63        );
64    }
65
66    #[test]
67    fn token_is_sufficient() {
68        ResetRunnerAuthenticationTokenByToken::builder()
69            .token("blah")
70            .build()
71            .unwrap();
72    }
73
74    #[test]
75    fn endpoint() {
76        let endpoint = ExpectedUrl::builder()
77            .method(Method::POST)
78            .endpoint("runners/reset_authentication_token")
79            .content_type("application/x-www-form-urlencoded")
80            .body_str("token=blah")
81            .build()
82            .unwrap();
83        let client = SingleTestClient::new_raw(endpoint, "");
84
85        let endpoint = ResetRunnerAuthenticationTokenByToken::builder()
86            .token("blah")
87            .build()
88            .unwrap();
89        api::ignore(endpoint).query(&client).unwrap();
90    }
91}