config(server): add token field to Forge

This commit is contained in:
Paul Campbell 2024-04-08 12:08:42 +01:00
parent aaaa975911
commit a1484939ab
2 changed files with 11 additions and 1 deletions

View file

@ -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]

View file

@ -47,6 +47,7 @@ pub struct Forge {
forge_type: ForgeType,
hostname: String,
user: String,
token: String,
// API Token
// Private SSH Key Path
repos: HashMap<String, Repo>,
@ -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<Item = (RepoName, &Repo)> {
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(),