Skip to main content

rush_ecs_sdk/auth/ports/
filesystem.rs

1use crate::{auth::Auth, error::AuthError};
2use anyhow::{bail, Result};
3use solana_sdk::signer::keypair::{read_keypair_file, Keypair};
4use std::path::Path;
5
6#[derive(Clone, Debug, Default, Eq, PartialEq)]
7pub struct FilesystemAuth {}
8
9impl FilesystemAuth {
10    pub fn new() -> Self {
11        Self {}
12    }
13}
14
15impl Auth for FilesystemAuth {
16    fn signin(&self, path: &str) -> Result<Keypair> {
17        let key_path = Path::new(path).canonicalize()?;
18        let keypair = read_keypair_file(key_path);
19
20        match keypair {
21            Ok(k) => Ok(k),
22            Err(err) => bail!(AuthError::KeypairNotFound(err.to_string())),
23        }
24    }
25}