|
1 | | -use std::{ |
2 | | - collections::HashMap, |
3 | | - time::{Duration, SystemTime, UNIX_EPOCH}, |
4 | | -}; |
| 1 | +use std::{collections::HashMap, time::Duration}; |
5 | 2 |
|
6 | 3 | use actix_web::{Error, HttpResponse, http::StatusCode}; |
7 | 4 | use base64::{Engine, engine}; |
| 5 | +use chrono::{TimeDelta, Utc}; |
8 | 6 | use serde::Serialize; |
9 | 7 | use serde_json::Value; |
10 | 8 | use tokenserver_auth::{MakeTokenPlaintext, Tokenlib, TokenserverOrigin}; |
@@ -79,10 +77,7 @@ pub async fn get_tokenserver_result( |
79 | 77 | node_type: req.node_type, |
80 | 78 | }; |
81 | 79 |
|
82 | | - let timestamp = { |
83 | | - let start = SystemTime::now(); |
84 | | - start.duration_since(UNIX_EPOCH).unwrap().as_secs() |
85 | | - }; |
| 80 | + let timestamp = Utc::now().timestamp() as u64; |
86 | 81 |
|
87 | 82 | Ok(HttpResponse::build(StatusCode::OK) |
88 | 83 | .insert_header(("X-Timestamp", timestamp.to_string())) |
@@ -116,13 +111,7 @@ fn get_token_plaintext( |
116 | 111 | ) |
117 | 112 | }; |
118 | 113 |
|
119 | | - let expires = { |
120 | | - let start = SystemTime::now(); |
121 | | - let current_time = start.duration_since(UNIX_EPOCH).unwrap(); |
122 | | - let expires = current_time + Duration::from_secs(req.duration); |
123 | | - |
124 | | - expires.as_secs() |
125 | | - }; |
| 114 | + let expires = (Utc::now() + TimeDelta::seconds(req.duration as i64)).timestamp() as u64; |
126 | 115 |
|
127 | 116 | Ok(MakeTokenPlaintext { |
128 | 117 | node: req.user.node.to_owned(), |
@@ -226,10 +215,7 @@ async fn update_user( |
226 | 215 | // If the client state changed, we need to mark the current user as "replaced" and create a |
227 | 216 | // new user record. Otherwise, we can update the user in place. |
228 | 217 | if req.auth_data.client_state != req.user.client_state { |
229 | | - let timestamp = SystemTime::now() |
230 | | - .duration_since(UNIX_EPOCH) |
231 | | - .unwrap() |
232 | | - .as_millis() as i64; |
| 218 | + let timestamp = Utc::now().timestamp_millis(); |
233 | 219 |
|
234 | 220 | // Create new user record with updated generation/keys_changed_at |
235 | 221 | let post_user_params = PostUser { |
|
0 commit comments