From cae543835748a26a3d2fb34ed0a1c6b3f06d7c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadius=20=C5=9Apiewak?= Date: Tue, 2 Jul 2024 13:14:18 +0200 Subject: [PATCH] add expiration date to token --- src/gitlab.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gitlab.rs b/src/gitlab.rs index 5c9f157..5784d62 100644 --- a/src/gitlab.rs +++ b/src/gitlab.rs @@ -1,3 +1,4 @@ +use chrono::{Duration, Utc}; use reqwest::Client; use serde_json::json; @@ -174,6 +175,8 @@ impl Gitlab { &self.gitlab_addr, group_id ); + let date = Utc::now() + Duration::days(365); + let res = self .client .post(&url) @@ -181,6 +184,7 @@ impl Gitlab { .json(&json!({ "name": name, "scopes": ["read_registry"], + "expires_at": date.format("%Y-%m-%d").to_string(), })) .send() .await; @@ -188,6 +192,7 @@ impl Gitlab { match res { Ok(r) => { let body = r.text().await.unwrap(); + log::info!("Response: {}", body); let json: serde_json::Value = serde_json::from_str(&body).unwrap(); let token = json["token"].as_str().unwrap(); log::info!("Created group access token: {}", name);