diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b0f0042777558df0e6e4a883f2059b1f6f17357..835234e91010ddead34651f0d81bd856a44c163c 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 d52e37ba504b18eb14342f1aea5ae15825434808..97c765ce6ca8e4987a2bae7a2cea644220f2266a 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"))]