Make admin-token optional (#55)
Diff
config.toml | 2 ++
src/config.rs | 3 ++-
src/providers/gitlab.rs | 19 ++++++++++++-------
3 files changed, 13 insertions(+), 11 deletions(-)
@@ -13,4 +13,6 @@
admin-token = "personal-access-token"
@@ -33,7 +33,8 @@
#[serde(rename_all = "kebab-case")]
pub struct GitlabConfig {
pub uri: Url,
pub admin_token: String,
pub admin_token: Option<String>,
#[serde(default = "GitlabConfig::default_token_expiry")]
pub token_expiry: Duration,
#[serde(default)]
@@ -7,11 +7,10 @@
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use reqwest::{header, Certificate};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, sync::Arc};
use std::{borrow::Cow, str::FromStr, sync::Arc};
use time::{Duration, OffsetDateTime};
use tracing::{info_span, instrument, Instrument};
use url::Url;
use std::str::FromStr;
pub struct Gitlab {
client: reqwest::Client,
@@ -22,13 +21,13 @@
impl Gitlab {
pub fn new(config: &GitlabConfig) -> anyhow::Result<Self> {
let mut headers = header::HeaderMap::new();
headers.insert(
"PRIVATE-TOKEN",
header::HeaderValue::from_str(&config.admin_token)?,
);
let mut client_builder = reqwest::ClientBuilder::new().default_headers(headers);
let mut client_builder = reqwest::ClientBuilder::new();
if let Some(token) = &config.admin_token {
let mut headers = header::HeaderMap::new();
headers.insert("PRIVATE-TOKEN", header::HeaderValue::from_str(token)?);
client_builder = client_builder.default_headers(headers);
}
let ssl_cert = match &config.ssl_cert {
Some(cert_path) => {
@@ -286,7 +285,7 @@
let uri = self.base_url.join(&path.metadata_uri(version))?;
let client = match &do_as.token {
None => self.client.clone(),
Some(token) => self.build_client_with_token("PRIVATE-TOKEN", token)?
Some(token) => self.build_client_with_token("PRIVATE-TOKEN", token)?,
};
Ok(handle_error(client.get(uri).send().await?)