scion_sdk_reqwest_connect_rpc/token_source/
static_token.rs1use async_trait::async_trait;
20use tokio::sync::watch;
21
22use crate::token_source::{TokenSource, TokenSourceError};
23
24pub struct StaticTokenSource {
27 token: String,
28 watch_tx: watch::Sender<Option<Result<String, TokenSourceError>>>,
29}
30
31impl From<String> for StaticTokenSource {
32 fn from(token: String) -> Self {
33 let (watch_tx, _watch_rx) = watch::channel(Some(Ok(token.clone())));
34 StaticTokenSource { token, watch_tx }
35 }
36}
37
38impl From<&'static str> for StaticTokenSource {
39 fn from(token: &'static str) -> Self {
40 let (watch_tx, _watch_rx) = watch::channel(Some(Ok(token.to_string())));
41 StaticTokenSource {
42 token: token.to_string(),
43 watch_tx,
44 }
45 }
46}
47
48#[async_trait]
49impl TokenSource for StaticTokenSource {
50 async fn get_token(&self) -> Result<String, TokenSourceError> {
51 Ok(self.token.clone())
52 }
53
54 fn watch(&self) -> watch::Receiver<Option<Result<String, TokenSourceError>>> {
55 self.watch_tx.subscribe()
56 }
57}