From f033c6889e0071b29e75c551586e8e5da1b556a3 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Fri, 26 Jan 2024 12:34:47 +0100 Subject: Use serde_json::json! instead of manually generating JSON --- git-lfs-authenticate/Cargo.toml | 1 + git-lfs-authenticate/src/main.rs | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'git-lfs-authenticate') 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" anyhow = "1.0" chrono = "0.4" common = { path = "../common" } +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 @@ use anyhow::{anyhow, bail, Result}; use chrono::Utc; +use serde_json::json; use std::{process::ExitCode, time::Duration}; fn main() -> ExitCode { @@ -39,14 +40,17 @@ fn main() -> ExitCode { return ExitCode::FAILURE; }; - println!( - "{{\"header\":{{\"Authorization\":\"Gitolfs3-Hmac-Sha256 {tag} {}\"}},\ - \"expires_at\":\"{}\",\"href\":\"{}{}/info/lfs\"}}", - expires_at.timestamp(), - common::EscJsonFmt(&expires_at.to_rfc3339_opts(chrono::SecondsFormat::Secs, true)), - common::EscJsonFmt(&config.href_base), - common::EscJsonFmt(&repo_name), - ); + let response = json!({ + "header": { + "Authorization": format!( + "Gitolfs3-Hmac-Sha256 {tag} {}", + expires_at.timestamp() + ), + }, + "expires_at": expires_at.to_rfc3339_opts(chrono::SecondsFormat::Secs, true), + "href": format!("{}{}/info/lfs", config.href_base, repo_name), + }); + println!("{}", response.to_string()); ExitCode::SUCCESS } -- cgit v1.2.3