Skip to main content

agent_sdk_store_supabase/
auth.rs

1use core::fmt;
2
3#[derive(Clone, Eq, PartialEq)]
4/// Supabase service auth used by REST-backed store adapters.
5pub struct SupabaseAuth {
6    api_key: String,
7    bearer_token: String,
8}
9
10impl SupabaseAuth {
11    /// Creates Supabase REST auth using the same secret for `apikey` and bearer auth.
12    pub fn service_role(secret: impl Into<String>) -> Self {
13        let secret = secret.into();
14        Self {
15            api_key: secret.clone(),
16            bearer_token: secret,
17        }
18    }
19
20    /// Creates Supabase REST auth from explicit header values.
21    pub fn new(api_key: impl Into<String>, bearer_token: impl Into<String>) -> Self {
22        Self {
23            api_key: api_key.into(),
24            bearer_token: bearer_token.into(),
25        }
26    }
27
28    /// Returns the `apikey` header value.
29    pub fn api_key(&self) -> &str {
30        &self.api_key
31    }
32
33    /// Returns the bearer token header value.
34    pub fn bearer_token(&self) -> &str {
35        &self.bearer_token
36    }
37}
38
39impl fmt::Debug for SupabaseAuth {
40    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
41        formatter
42            .debug_struct("SupabaseAuth")
43            .field("api_key", &"<redacted>")
44            .field("bearer_token", &"<redacted>")
45            .finish()
46    }
47}