Read minio instance secret key

This commit is contained in:
2023-05-06 10:58:18 +02:00
parent 547cc02800
commit 36aaf5fb4d
10 changed files with 65 additions and 8 deletions

20
src/secrets.rs Normal file
View File

@@ -0,0 +1,20 @@
use k8s_openapi::api::core::v1::Secret;
#[derive(thiserror::Error, Debug)]
enum SecretError {
#[error("Secret has no data!")]
MissingData,
#[error("The key '{0}' is not present in the secret!")]
MissingKey(String),
}
/// Attempt to read a value contained in a secret. Returns an error in case
/// of failure
pub fn read_secret_str(s: &Secret, key: &str) -> anyhow::Result<String> {
let data = s.data.as_ref().ok_or(SecretError::MissingData)?;
let value = data.get(key)
.ok_or(SecretError::MissingKey(key.to_string()))?;
Ok(String::from_utf8(value.0.clone())?)
}