fix: manage auth bearer key and replace vars in body

This commit is contained in:
əlemi 2023-06-20 14:04:27 +02:00
parent 420ea7a746
commit d3dfbca673
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -37,10 +37,24 @@ impl IntoRequest for v2_1_0::RequestClass {
url_str = fill_from_env(url_str);
let url = reqwest::Url::from_str(&url_str).unwrap();
let url = reqwest::Url::from_str(&url_str).unwrap_or_else(|e| {
eprintln!("error creating url ({}), falling back to localhost", e);
reqwest::Url::from_str("http://localhost/").unwrap()
});
let mut out = reqwest::Client::new().request(method, url);
// TODO handle more auth types than just bearer
if let Some(auth) = &self.auth {
if let Some(bearers) = &auth.bearer {
for bearer in bearers {
if let Some(value) = &bearer.value {
out = out.header("Authorization", format!("Bearer {}", value.as_str().unwrap_or(&value.to_string())))
}
}
}
}
match &self.header {
Some(v2_1_0::HeaderUnion::HeaderArray(x)) => {
for h in x {
@ -52,9 +66,10 @@ impl IntoRequest for v2_1_0::RequestClass {
_ => {},
}
match &self.body {
Some(v2_1_0::Body { raw: Some(x), .. }) => {
out = out.body(x.clone()) // TODO try to avoid cloning?
out = out.body(fill_from_env(x.clone())) // TODO try to avoid cloning?
},
_ => {},
}