From f553c4ef19874692cf5f51d5514612e5d049c03a Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Wed, 19 Jun 2024 11:41:57 +0300 Subject: [PATCH] add option to provide headers to send as client (#1523) * add option to provide headers to send as client Signed-off-by: Aviram Hassan * lint Signed-off-by: Aviram Hassan --------- Signed-off-by: Aviram Hassan --- kube-client/src/client/config_ext.rs | 2 +- kube-client/src/config/mod.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kube-client/src/client/config_ext.rs b/kube-client/src/client/config_ext.rs index a15c1b40f..dcace1c70 100644 --- a/kube-client/src/client/config_ext.rs +++ b/kube-client/src/client/config_ext.rs @@ -181,7 +181,7 @@ impl ConfigExt for Config { } fn extra_headers_layer(&self) -> Result { - let mut headers = Vec::new(); + let mut headers = self.headers.clone(); if let Some(impersonate_user) = &self.auth_info.impersonate { headers.push(( HeaderName::from_static("impersonate-user"), diff --git a/kube-client/src/config/mod.rs b/kube-client/src/config/mod.rs index ed1c1b7d2..c51daebd7 100644 --- a/kube-client/src/config/mod.rs +++ b/kube-client/src/config/mod.rs @@ -6,6 +6,7 @@ //! Unless you have issues, prefer using [`Config::infer`], and pass it to a [`Client`][crate::Client]. use std::{path::PathBuf, time::Duration}; +use http::{HeaderName, HeaderValue}; use thiserror::Error; mod file_config; @@ -154,6 +155,8 @@ pub struct Config { /// /// If not set, the `cluster_url` is used instead pub tls_server_name: Option, + /// Headers to pass with every request. + pub headers: Vec<(HeaderName, HeaderValue)>, } impl Config { @@ -174,6 +177,7 @@ impl Config { auth_info: AuthInfo::default(), proxy_url: None, tls_server_name: None, + headers: Vec::new(), } } @@ -255,6 +259,7 @@ impl Config { }, proxy_url: None, tls_server_name: None, + headers: Vec::new(), }) } @@ -312,6 +317,7 @@ impl Config { proxy_url: loader.proxy_url()?, auth_info: loader.user, tls_server_name: loader.cluster.tls_server_name, + headers: Vec::new(), }) }