From a1484939ab9b0c76a5df9a000318ae2ecca94f72 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 8 Apr 2024 12:08:42 +0100 Subject: [PATCH] config(server): add token field to Forge --- server-default.toml | 2 +- src/server/config.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server-default.toml b/server-default.toml index 0c833a2..d6a03ae 100644 --- a/server-default.toml +++ b/server-default.toml @@ -2,7 +2,7 @@ forge_type = "ForgeJo" hostname = "git.example.net" user = "git-next" # the user to perform actions as -# API token for user? +token = "API-Token" # path to private SSH key for user? [forge.default.repos] diff --git a/src/server/config.rs b/src/server/config.rs index 0d825c5..e582524 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -47,6 +47,7 @@ pub struct Forge { forge_type: ForgeType, hostname: String, user: String, + token: String, // API Token // Private SSH Key Path repos: HashMap, @@ -64,6 +65,10 @@ impl Forge { User(self.user.clone()) } + pub fn token(&self) -> ApiToken { + ApiToken(self.token.clone()) + } + pub fn repos(&self) -> impl Iterator { self.repos .iter() @@ -132,6 +137,7 @@ pub struct ForgeDetails { pub forge_type: ForgeType, pub hostname: Hostname, pub user: User, + pub token: ApiToken, // API Token // Private SSH Key Path } @@ -142,6 +148,7 @@ impl From<(&ForgeName, &Forge)> for ForgeDetails { forge_type: forge.1.forge_type.clone(), hostname: forge.1.hostname(), user: forge.1.user(), + token: forge.1.token(), } } } @@ -184,6 +191,7 @@ impl RepoDetails { forge_type: forge.forge_type.clone(), hostname: forge.hostname(), user: forge.user(), + token: forge.token(), }, } } @@ -235,6 +243,7 @@ mod tests { forge_type = "ForgeJo" hostname = "git.example.net" user = "Bob" + token = "API-Token" [forge.default.repos] hello = { repo = "user/hello", branch = "main" } @@ -250,6 +259,7 @@ mod tests { forge_type: ForgeType::ForgeJo, hostname: "git.example.net".to_string(), user: "Bob".to_string(), + token: "API-Token".to_string(), repos: HashMap::from([ ( "hello".to_string(),