[pdm-devel] [PATCH proxmox v5 17/21] client: specify cookie names for authentication headers where possible
Shannon Sterz
s.sterz at proxmox.com
Tue Mar 4 15:42:43 CET 2025
if the client knows the auth cookie's name, it now passes it on to the
relevant parts of `proxmox-login` so that the ticket is send the
correct cookie
Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
proxmox-client/src/client.rs | 50 +++++++++++++++++++++++++++++++-----
1 file changed, 44 insertions(+), 6 deletions(-)
diff --git a/proxmox-client/src/client.rs b/proxmox-client/src/client.rs
index 07a53873..a1b4eee2 100644
--- a/proxmox-client/src/client.rs
+++ b/proxmox-client/src/client.rs
@@ -222,8 +222,12 @@ impl Client {
json_body: Option<String>,
// send an `Accept: application/json-seq` header.
streaming: bool,
+ cookie_name: &Option<String>,
) -> Result<(http::response::Parts, hyper::Body), Error> {
- let mut request = auth.set_auth_headers(Request::builder().method(method).uri(uri));
+ let mut request = auth.set_auth_headers_with_cookie_name(
+ Request::builder().method(method).uri(uri),
+ cookie_name,
+ );
if streaming {
request = request.header(http::header::ACCEPT, "application/json-seq");
}
@@ -270,9 +274,18 @@ impl Client {
method: Method,
uri: Uri,
json_body: Option<String>,
+ cookie_name: &Option<String>,
) -> Result<HttpApiResponse, Error> {
- let (response, body) =
- Self::send_authenticated_request(client, auth, method, uri, json_body, false).await?;
+ let (response, body) = Self::send_authenticated_request(
+ client,
+ auth,
+ method,
+ uri,
+ json_body,
+ false,
+ cookie_name,
+ )
+ .await?;
let body = read_body(body).await?;
let content_type = match response.headers.get(http::header::CONTENT_TYPE) {
@@ -475,7 +488,7 @@ impl HttpApiClient for Client {
let auth = self.login_auth()?;
let uri = self.build_uri(path_and_query)?;
let client = Arc::clone(&self.client);
- Self::authenticated_request(client, auth, method, uri, params).await
+ Self::authenticated_request(client, auth, method, uri, params, &self.cookie_name).await
})
}
@@ -500,8 +513,16 @@ impl HttpApiClient for Client {
let auth = self.login_auth()?;
let uri = self.build_uri(path_and_query)?;
let client = Arc::clone(&self.client);
- let (response, body) =
- Self::send_authenticated_request(client, auth, method, uri, params, true).await?;
+ let (response, body) = Self::send_authenticated_request(
+ client,
+ auth,
+ method,
+ uri,
+ params,
+ true,
+ &self.cookie_name,
+ )
+ .await?;
let content_type = match response.headers.get(http::header::CONTENT_TYPE) {
None => None,
@@ -575,6 +596,23 @@ impl AuthenticationKind {
}
}
+ pub fn set_auth_headers_with_cookie_name(
+ &self,
+ request: http::request::Builder,
+ cookie_name: &Option<String>,
+ ) -> http::request::Builder {
+ match self {
+ AuthenticationKind::Ticket(auth) => {
+ if let Some(name) = cookie_name {
+ auth.set_auth_headers_with_cookie_name(request, name)
+ } else {
+ auth.set_auth_headers(request)
+ }
+ }
+ AuthenticationKind::Token(auth) => auth.set_auth_headers(request),
+ }
+ }
+
pub fn userid(&self) -> &str {
match self {
AuthenticationKind::Ticket(auth) => &auth.userid,
--
2.39.5
More information about the pdm-devel
mailing list