Skip to content

Commit

Permalink
add option to provide headers to send as client
Browse files Browse the repository at this point in the history
Signed-off-by: Aviram Hassan <aviramyhassan@gmail.com>
  • Loading branch information
aviramha committed Jun 18, 2024
1 parent 41549bc commit ca2e736
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kube-client/src/client/config_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl ConfigExt for Config {
}

fn extra_headers_layer(&self) -> Result<ExtraHeadersLayer> {
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"),
Expand Down
6 changes: 6 additions & 0 deletions kube-client/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,6 +155,8 @@ pub struct Config {
///
/// If not set, the `cluster_url` is used instead
pub tls_server_name: Option<String>,
/// Headers to pass with every request.
pub headers: Vec<(HeaderName, HeaderValue)>
}

impl Config {
Expand All @@ -174,6 +177,7 @@ impl Config {
auth_info: AuthInfo::default(),
proxy_url: None,
tls_server_name: None,
headers: Vec::new(),

Check warning on line 180 in kube-client/src/config/mod.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/config/mod.rs#L180

Added line #L180 was not covered by tests
}
}

Expand Down Expand Up @@ -255,6 +259,7 @@ impl Config {
},
proxy_url: None,
tls_server_name: None,
headers: Vec::new(),

Check warning on line 262 in kube-client/src/config/mod.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/config/mod.rs#L262

Added line #L262 was not covered by tests
})
}

Expand Down Expand Up @@ -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(),
})
}

Expand Down

0 comments on commit ca2e736

Please sign in to comment.