reqsign_oracle/provide_credential/
static_.rs1use crate::Credential;
19use reqsign_core::{Context, ProvideCredential, Result};
20
21#[derive(Debug)]
23pub struct StaticCredentialProvider {
24 credential: Credential,
25}
26
27impl StaticCredentialProvider {
28 pub fn new(user: &str, tenancy: &str, key_file: &str, fingerprint: &str) -> Self {
30 Self {
31 credential: Credential {
32 user: user.to_string(),
33 tenancy: tenancy.to_string(),
34 key_file: key_file.to_string(),
35 fingerprint: fingerprint.to_string(),
36 expires_in: None,
37 },
38 }
39 }
40}
41impl ProvideCredential for StaticCredentialProvider {
42 type Credential = Credential;
43
44 async fn provide_credential(&self, _ctx: &Context) -> Result<Option<Self::Credential>> {
45 Ok(Some(self.credential.clone()))
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52 use reqsign_core::OsEnv;
53 use reqsign_file_read_tokio::TokioFileRead;
54 use reqsign_http_send_reqwest::ReqwestHttpSend;
55
56 #[tokio::test]
57 async fn test_static_credential_provider() -> anyhow::Result<()> {
58 let ctx = Context::new()
59 .with_file_read(TokioFileRead)
60 .with_http_send(ReqwestHttpSend::default())
61 .with_env(OsEnv);
62
63 let provider = StaticCredentialProvider::new(
64 "test_user",
65 "test_tenancy",
66 "/path/to/key",
67 "test_fingerprint",
68 );
69 let cred = provider.provide_credential(&ctx).await?;
70 assert!(cred.is_some());
71 let cred = cred.unwrap();
72 assert_eq!(cred.user, "test_user");
73 assert_eq!(cred.tenancy, "test_tenancy");
74 assert_eq!(cred.key_file, "/path/to/key");
75 assert_eq!(cred.fingerprint, "test_fingerprint");
76 assert!(cred.expires_in.is_none());
77
78 Ok(())
79 }
80}