1use rustack_auth::{credentials::CredentialProvider, error::AuthError};
12use tracing::debug;
13
14#[derive(Debug, Clone)]
25pub struct RustackAuth {
26 skip_validation: bool,
27}
28
29impl RustackAuth {
30 #[must_use]
35 pub fn new(skip_validation: bool) -> Self {
36 Self { skip_validation }
37 }
38
39 #[must_use]
41 pub fn skip_validation(&self) -> bool {
42 self.skip_validation
43 }
44}
45
46impl CredentialProvider for RustackAuth {
47 fn get_secret_key(&self, access_key_id: &str) -> Result<String, AuthError> {
48 if self.skip_validation {
49 debug!(access_key_id, "Skipping signature validation");
50 return Ok(String::new());
51 }
52
53 debug!(access_key_id, "Returning default secret key for access key");
54 Ok("test".to_owned())
55 }
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_should_create_auth_with_skip_validation() {
64 let auth = RustackAuth::new(true);
65 assert!(auth.skip_validation());
66 }
67
68 #[test]
69 fn test_should_create_auth_with_validation() {
70 let auth = RustackAuth::new(false);
71 assert!(!auth.skip_validation());
72 }
73
74 #[test]
75 fn test_should_return_empty_key_when_skipping_validation() {
76 let auth = RustackAuth::new(true);
77 let key = auth.get_secret_key("any-key").expect("test get_secret_key");
78 assert_eq!(key, "");
79 }
80
81 #[test]
82 fn test_should_return_test_key_when_validating() {
83 let auth = RustackAuth::new(false);
84 let key = auth
85 .get_secret_key("AKIAIOSFODNN7EXAMPLE")
86 .expect("test get_secret_key");
87 assert_eq!(key, "test");
88 }
89}