lib_client_linear/
auth.rs

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