Skip to content

Commit

Permalink
add expiration date to token
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszspiewak committed Jul 2, 2024
1 parent f95c3c8 commit cae5438
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gitlab.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{Duration, Utc};
use reqwest::Client;
use serde_json::json;

Expand Down Expand Up @@ -174,20 +175,24 @@ impl Gitlab {
&self.gitlab_addr, group_id
);

let date = Utc::now() + Duration::days(365);

let res = self
.client
.post(&url)
.header("PRIVATE-TOKEN", &self.token)
.json(&json!({
"name": name,
"scopes": ["read_registry"],
"expires_at": date.format("%Y-%m-%d").to_string(),
}))
.send()
.await;

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);
Expand Down

0 comments on commit cae5438

Please sign in to comment.