From ea40e61cf08900607a58cd2562347ebc0a1463ee Mon Sep 17 00:00:00 2001 From: Peter Smit Date: Tue, 25 Feb 2025 06:35:57 +0200 Subject: [PATCH] Add support for GitLab API authentication with job tokens Introduced a `new_with_job_token` constructor to create a GitLab client using a job token for authentication. Added a `job_token` method to switch existing authentication to use a job token. These changes enhance flexibility in authenticating with GitLab APIs. Fixes: #114 --- CHANGELOG.md | 6 ++++++ src/gitlab.rs | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b0f0042..835234e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.1709.1 (unreleased) + +## Additions + + * Add support for GitLab API authentication with job tokens. + # v0.1709.0 ## Breaking changes diff --git a/src/gitlab.rs b/src/gitlab.rs index d52e37ba..97c765ce 100644 --- a/src/gitlab.rs +++ b/src/gitlab.rs @@ -444,6 +444,21 @@ impl GitlabBuilder { } } + /// Create a new Gitlab API client builder with job token. + pub fn new_with_job_token(host: H, token: T) -> Self + where + H: Into, + T: Into, + { + Self { + protocol: "https", + host: host.into(), + token: Auth::JobToken(token.into()), + cert_validation: CertPolicy::Default, + identity: ClientCert::None, + } + } + /// Switch to an insecure protocol (http instead of https). pub fn insecure(&mut self) -> &mut Self { self.protocol = "http"; @@ -463,6 +478,14 @@ impl GitlabBuilder { self } + /// Switch to using an job token instead of a personal access token + pub fn job_token(&mut self) -> &mut Self { + if let Auth::Token(token) = self.token.clone() { + self.token = Auth::JobToken(token); + } + self + } + /// [Authenticate to Gitlab](reqwest::Identity) with the provided /// DER-formatted PKCS#12 archive. #[cfg(any(doc, feature = "client_der"))] -- GitLab