diff options
author | Rutger Broekhoff | 2024-01-26 12:34:47 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2024-01-26 12:34:47 +0100 |
commit | f033c6889e0071b29e75c551586e8e5da1b556a3 (patch) | |
tree | 7ab82ed0c11b6d4a1d45d3526015ecd631790be5 /git-lfs-authenticate | |
parent | f146743061ba8170569bf18518202df9a43c09f3 (diff) | |
download | gitolfs3-f033c6889e0071b29e75c551586e8e5da1b556a3.tar.gz gitolfs3-f033c6889e0071b29e75c551586e8e5da1b556a3.zip |
Use serde_json::json! instead of manually generating JSON
Diffstat (limited to 'git-lfs-authenticate')
-rw-r--r-- | git-lfs-authenticate/Cargo.toml | 1 | ||||
-rw-r--r-- | git-lfs-authenticate/src/main.rs | 20 |
2 files changed, 13 insertions, 8 deletions
diff --git a/git-lfs-authenticate/Cargo.toml b/git-lfs-authenticate/Cargo.toml index f4ab4d7..15feba8 100644 --- a/git-lfs-authenticate/Cargo.toml +++ b/git-lfs-authenticate/Cargo.toml | |||
@@ -7,3 +7,4 @@ edition = "2021" | |||
7 | anyhow = "1.0" | 7 | anyhow = "1.0" |
8 | chrono = "0.4" | 8 | chrono = "0.4" |
9 | common = { path = "../common" } | 9 | common = { path = "../common" } |
10 | serde_json = "1" | ||
diff --git a/git-lfs-authenticate/src/main.rs b/git-lfs-authenticate/src/main.rs index accc37f..3101c92 100644 --- a/git-lfs-authenticate/src/main.rs +++ b/git-lfs-authenticate/src/main.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use anyhow::{anyhow, bail, Result}; | 1 | use anyhow::{anyhow, bail, Result}; |
2 | use chrono::Utc; | 2 | use chrono::Utc; |
3 | use serde_json::json; | ||
3 | use std::{process::ExitCode, time::Duration}; | 4 | use std::{process::ExitCode, time::Duration}; |
4 | 5 | ||
5 | fn main() -> ExitCode { | 6 | fn main() -> ExitCode { |
@@ -39,14 +40,17 @@ fn main() -> ExitCode { | |||
39 | return ExitCode::FAILURE; | 40 | return ExitCode::FAILURE; |
40 | }; | 41 | }; |
41 | 42 | ||
42 | println!( | 43 | let response = json!({ |
43 | "{{\"header\":{{\"Authorization\":\"Gitolfs3-Hmac-Sha256 {tag} {}\"}},\ | 44 | "header": { |
44 | \"expires_at\":\"{}\",\"href\":\"{}{}/info/lfs\"}}", | 45 | "Authorization": format!( |
45 | expires_at.timestamp(), | 46 | "Gitolfs3-Hmac-Sha256 {tag} {}", |
46 | common::EscJsonFmt(&expires_at.to_rfc3339_opts(chrono::SecondsFormat::Secs, true)), | 47 | expires_at.timestamp() |
47 | common::EscJsonFmt(&config.href_base), | 48 | ), |
48 | common::EscJsonFmt(&repo_name), | 49 | }, |
49 | ); | 50 | "expires_at": expires_at.to_rfc3339_opts(chrono::SecondsFormat::Secs, true), |
51 | "href": format!("{}{}/info/lfs", config.href_base, repo_name), | ||
52 | }); | ||
53 | println!("{}", response.to_string()); | ||
50 | 54 | ||
51 | ExitCode::SUCCESS | 55 | ExitCode::SUCCESS |
52 | } | 56 | } |