Skip to main content

gitlab/api/projects/job_token_scopes/
allowed_projects.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::common::NameOrId;
10use crate::api::endpoint_prelude::*;
11
12/// Fetch the 'CI/CD job token inbound allowlist' (job token scope) of a project.
13#[derive(Debug, Builder, Clone)]
14pub struct AllowedJobTokenProjects<'a> {
15    /// The ID or URL-encoded path of the project.
16    #[builder(setter(into))]
17    project: NameOrId<'a>,
18}
19
20impl<'a> AllowedJobTokenProjects<'a> {
21    /// Create a builder for the endpoint.
22    pub fn builder() -> AllowedJobTokenProjectsBuilder<'a> {
23        AllowedJobTokenProjectsBuilder::default()
24    }
25}
26
27impl Endpoint for AllowedJobTokenProjects<'_> {
28    fn method(&self) -> Method {
29        Method::GET
30    }
31
32    fn endpoint(&self) -> Cow<'static, str> {
33        format!("projects/{}/job_token_scope/allowlist", self.project).into()
34    }
35}
36
37impl Pageable for AllowedJobTokenProjects<'_> {}
38
39#[cfg(test)]
40mod tests {
41    use http::Method;
42
43    use crate::api::projects::job_token_scopes::{
44        AllowedJobTokenProjects, AllowedJobTokenProjectsBuilderError,
45    };
46    use crate::api::{self, Query};
47    use crate::test::client::{ExpectedUrl, SingleTestClient};
48
49    #[test]
50    fn project_is_required() {
51        let err = AllowedJobTokenProjects::builder().build().unwrap_err();
52        crate::test::assert_missing_field!(err, AllowedJobTokenProjectsBuilderError, "project");
53    }
54
55    #[test]
56    fn project_is_sufficient() {
57        AllowedJobTokenProjects::builder()
58            .project("blah")
59            .build()
60            .unwrap();
61    }
62
63    #[test]
64    fn endpoint() {
65        let endpoint = ExpectedUrl::builder()
66            .method(Method::GET)
67            .endpoint("projects/blah/job_token_scope/allowlist")
68            .build()
69            .unwrap();
70        let client = SingleTestClient::new_raw(endpoint, "");
71
72        let endpoint = AllowedJobTokenProjects::builder()
73            .project("blah")
74            .build()
75            .unwrap();
76        api::ignore(endpoint).query(&client).unwrap();
77    }
78}