use car_secrets::{SecretRef, SecretStore};
use crate::error::ConnectorError;
fn key(slug: &str, header: &str) -> String {
format!("connector:{slug}:{header}")
}
pub fn put_header_secret(slug: &str, header: &str, value: &str) -> Result<(), ConnectorError> {
SecretStore::new()
.put(&SecretRef::with_default_service(key(slug, header)), value)
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
pub fn get_header_secret(slug: &str, header: &str) -> Result<String, ConnectorError> {
SecretStore::new()
.get(&SecretRef::with_default_service(key(slug, header)))
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
pub fn delete_header_secret(slug: &str, header: &str) -> Result<(), ConnectorError> {
SecretStore::new()
.delete(&SecretRef::with_default_service(key(slug, header)))
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
fn tokens_key(slug: &str) -> String {
format!("connector:{slug}:tokens")
}
fn client_secret_key(slug: &str) -> String {
format!("connector:{slug}:client_secret")
}
pub fn put_tokens(slug: &str, tokens: &crate::oauth::StoredTokens) -> Result<(), ConnectorError> {
SecretStore::new()
.put_json(&SecretRef::with_default_service(tokens_key(slug)), tokens)
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
pub fn get_tokens(slug: &str) -> Result<crate::oauth::StoredTokens, ConnectorError> {
SecretStore::new()
.get_json(&SecretRef::with_default_service(tokens_key(slug)))
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
pub fn delete_tokens(slug: &str) -> Result<(), ConnectorError> {
SecretStore::new()
.delete(&SecretRef::with_default_service(tokens_key(slug)))
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
pub fn put_client_secret(slug: &str, secret: &str) -> Result<(), ConnectorError> {
SecretStore::new()
.put(&SecretRef::with_default_service(client_secret_key(slug)), secret)
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
pub fn get_client_secret(slug: &str) -> Result<String, ConnectorError> {
SecretStore::new()
.get(&SecretRef::with_default_service(client_secret_key(slug)))
.map_err(|e| ConnectorError::Secret(e.to_string()))
}
pub fn delete_client_secret(slug: &str) -> Result<(), ConnectorError> {
SecretStore::new()
.delete(&SecretRef::with_default_service(client_secret_key(slug)))
.map_err(|e| ConnectorError::Secret(e.to_string()))
}