rustfs_policy/auth.rs
1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15mod credentials;
16
17pub use credentials::Credentials;
18pub use credentials::*;
19use serde::{Deserialize, Serialize};
20use time::OffsetDateTime;
21
22#[derive(Serialize, Deserialize, Clone, Debug, Default)]
23pub struct UserIdentity {
24 pub version: i64,
25 pub credentials: Credentials,
26 pub update_at: Option<OffsetDateTime>,
27}
28
29impl UserIdentity {
30 pub fn new(credentials: Credentials) -> Self {
31 UserIdentity {
32 version: 1,
33 credentials,
34 update_at: Some(OffsetDateTime::now_utc()),
35 }
36 }
37}
38
39impl From<Credentials> for UserIdentity {
40 fn from(value: Credentials) -> Self {
41 UserIdentity {
42 version: 1,
43 credentials: value,
44 update_at: Some(OffsetDateTime::now_utc()),
45 }
46 }
47}