rustfs_rsc/
credentials.rs1use crate::time::UtcTime;
2
3#[derive(Debug, Clone)]
5pub struct Credentials {
6 access_key: String,
7 secret_key: String,
8 session_token: Option<String>,
9 expiration: Option<i64>,
10}
11
12impl Credentials {
13 pub fn new<T1: Into<String>,T2: Into<String>>(ak: T1, sk: T2, st: Option<String>, exp: Option<i64>) -> Self {
14 Credentials {
15 access_key: ak.into(),
16 secret_key: sk.into(),
17 session_token: st,
18 expiration: exp,
19 }
20 }
21
22 pub fn access_key(&self) -> &str {
24 self.access_key.as_ref()
25 }
26
27 pub fn secret_key(&self) -> &str {
29 self.secret_key.as_ref()
30 }
31
32 pub fn session_token(&self) -> Option<&String> {
34 self.session_token.as_ref()
35 }
36
37 pub fn is_expired(&self) -> bool {
39 if let Some(exp) = self.expiration {
40 let now = UtcTime::now();
41 now.before(exp - 10)
42 } else {
43 false
44 }
45 }
46}