lib_client_anthropic/
auth.rs1use crate::error::Result;
4use async_trait::async_trait;
5use reqwest::header::HeaderMap;
6
7#[async_trait]
9pub trait AuthStrategy: Send + Sync {
10 async fn apply(&self, headers: &mut HeaderMap) -> Result<()>;
12}
13
14#[derive(Debug, Clone)]
16pub struct ApiKeyAuth {
17 api_key: String,
18}
19
20impl ApiKeyAuth {
21 pub fn new(api_key: impl Into<String>) -> Self {
23 Self {
24 api_key: api_key.into(),
25 }
26 }
27}
28
29#[async_trait]
30impl AuthStrategy for ApiKeyAuth {
31 async fn apply(&self, headers: &mut HeaderMap) -> Result<()> {
32 headers.insert("x-api-key", self.api_key.parse().unwrap());
33 Ok(())
34 }
35}