Read minio instance secret key
This commit is contained in:
20
src/secrets.rs
Normal file
20
src/secrets.rs
Normal 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())?)
|
||||
}
|
||||
Reference in New Issue
Block a user