client: change Token struct

API tokens between rust & perl code bases are inconsistent... this
needs fixing, but for now this is faster and more compatible.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2024-08-13 15:37:27 +02:00
parent 9923f29622
commit c54d5e06e6

View File

@ -31,13 +31,19 @@ pub struct Token {
/// The api token's value.
pub value: String,
/// The separator for userid & value, due to inconsistencies between perl and rust based
/// products.
/// FIXME: Make one of them work for both types of products and remove this!
pub perl_compat: bool,
}
impl Token {
pub fn set_auth_headers(&self, request: http::request::Builder) -> http::request::Builder {
let delim = if self.perl_compat { '=' } else { ':' };
request.header(
http::header::AUTHORIZATION,
format!("{}={}={}", self.prefix, self.userid, self.value),
format!("{}={}{delim}{}", self.prefix, self.userid, self.value),
)
}
}