Skip to content

Commit

Permalink
Merge pull request #106 from orf/patch-1
Browse files Browse the repository at this point in the history
Improve logging message levels to reduce verbosity
  • Loading branch information
stormshield-gt authored Nov 19, 2024
2 parents 27b18db + 34291b4 commit 4c48122
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<E: Endpoint> WrappedResponse<E> {
&self,
client: &impl Client,
) -> Result<WrappingLookupResponse, ClientError> {
info!("Looking up wrapped response information");
debug!("Looking up wrapped response information");
wrapping::lookup(client, self.info.token.as_str())
.await
.map_err(|e| match &e {
Expand Down Expand Up @@ -147,7 +147,7 @@ impl MiddleWare for EndpointMiddleware {
req: &mut http::Request<Vec<u8>>,
) -> Result<(), rustify::errors::ClientError> {
// Prepend API version to all requests
debug!(
trace!(
"Middleware: prepending {} version to URL",
self.version.as_str()
);
Expand All @@ -157,7 +157,7 @@ impl MiddleWare for EndpointMiddleware {
segs.insert(0, self.version.as_str());
url_c.set_path(format!("{}{}", self.version, url_c.path()).as_str());
*req.uri_mut() = http::Uri::from_str(url_c.as_str()).unwrap();
debug!("Middleware: final URL is {}", url_c.as_str());
trace!("Middleware: final URL is {}", url_c.as_str());

// Add X-Vault-Request to all requests
req.headers_mut().append(
Expand All @@ -167,7 +167,7 @@ impl MiddleWare for EndpointMiddleware {

// Add Vault token to all requests
if !self.token.is_empty() {
debug!("Middleware: adding token to header");
trace!("Middleware: adding token to header");
req.headers_mut().append(
"X-Vault-Token",
http::HeaderValue::from_str(self.token.as_str()).unwrap(),
Expand All @@ -176,7 +176,7 @@ impl MiddleWare for EndpointMiddleware {

// Optionally wrap response
if let Some(wrap) = &self.wrap {
info!("Middleware: adding wrap header with {} ttl", wrap);
trace!("Middleware: adding wrap header with {} ttl", wrap);
req.headers_mut().append(
"X-Vault-Wrap-TTL",
http::HeaderValue::from_str(wrap.as_str()).unwrap(),
Expand All @@ -185,7 +185,7 @@ impl MiddleWare for EndpointMiddleware {

// Optionally wrap response
if let Some(namespace) = &self.namespace {
info!("Middleware: adding namespace header {}", namespace);
trace!("Middleware: adding namespace header {}", namespace);
req.headers_mut().append(
"X-Vault-Namespace",
http::HeaderValue::from_str(namespace.as_str()).unwrap(),
Expand Down Expand Up @@ -213,7 +213,7 @@ pub async fn exec_with_empty<E>(client: &impl Client, endpoint: E) -> Result<(),
where
E: Endpoint,
{
info!("start request");
trace!("start request");
endpoint
.with_middleware(client.middle())
.exec(client.http())
Expand All @@ -231,7 +231,7 @@ pub async fn exec_with_empty_result<E>(client: &impl Client, endpoint: E) -> Res
where
E: Endpoint,
{
info!("start request");
trace!("start request");
endpoint
.with_middleware(client.middle())
.exec(client.http())
Expand All @@ -255,7 +255,7 @@ pub async fn exec_with_no_result<E>(
where
E: Endpoint,
{
info!("start request");
trace!("start request");
endpoint
.with_middleware(client.middle())
.exec(client.http())
Expand Down Expand Up @@ -289,7 +289,7 @@ pub async fn exec_with_result<E>(
where
E: Endpoint,
{
info!("start request");
trace!("start request");
endpoint
.with_middleware(client.middle())
.exec(client.http())
Expand All @@ -310,7 +310,7 @@ pub async fn wrap<E>(client: &impl Client, endpoint: E) -> Result<WrappedRespons
where
E: Endpoint,
{
info!(
trace!(
"Executing {} and returning a wrapped response",
endpoint.path()
);
Expand All @@ -335,7 +335,7 @@ pub async fn auth<E>(client: &impl Client, endpoint: E) -> Result<AuthInfo, Clie
where
E: Endpoint<Response = ()>,
{
info!(
trace!(
"Executing {} and returning authentication info",
endpoint.path()
);
Expand Down
16 changes: 8 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl VaultClient {
}
})?;

info!("Importing CA certificate from {}", path);
debug!("Importing CA certificate from {}", path);
http_client = http_client.add_root_certificate(cert);
}

Expand Down Expand Up @@ -206,10 +206,10 @@ impl VaultClientSettingsBuilder {

fn default_address(&self) -> Result<Url, String> {
let address = if let Ok(address) = env::var("VAULT_ADDR") {
info!("Using vault address from $VAULT_ADDR: {address}");
debug!("Using vault address from $VAULT_ADDR: {address}");
address
} else {
info!("Using default vault address http://127.0.0.1:8200");
debug!("Using default vault address http://127.0.0.1:8200");
String::from("http://127.0.0.1:8200")
};
let url = Url::parse(&address);
Expand All @@ -223,18 +223,18 @@ impl VaultClientSettingsBuilder {
fn default_token(&self) -> String {
match env::var("VAULT_TOKEN") {
Ok(s) => {
info!("Using vault token from $VAULT_TOKEN");
debug!("Using vault token from $VAULT_TOKEN");
s
}
Err(_) => {
info!("Using default empty vault token");
debug!("Using default empty vault token");
String::from("")
}
}
}

fn default_verify(&self) -> bool {
info!("Checking TLS verification using $VAULT_SKIP_VERIFY");
debug!("Checking TLS verification using $VAULT_SKIP_VERIFY");
match env::var("VAULT_SKIP_VERIFY") {
Ok(value) => !matches!(value.to_lowercase().as_str(), "0" | "f" | "false"),
Err(_) => true,
Expand All @@ -245,12 +245,12 @@ impl VaultClientSettingsBuilder {
let mut paths: Vec<String> = Vec::new();

if let Ok(s) = env::var("VAULT_CACERT") {
info!("Found CA certificate in $VAULT_CACERT");
debug!("Found CA certificate in $VAULT_CACERT");
paths.push(s);
}

if let Ok(s) = env::var("VAULT_CAPATH") {
info!("Found CA certificate path in $VAULT_CAPATH");
debug!("Found CA certificate path in $VAULT_CAPATH");
if let Ok(p) = fs::read_dir(s) {
for path in p {
paths.push(path.unwrap().path().to_str().unwrap().to_string())
Expand Down

0 comments on commit 4c48122

Please sign in to comment.