Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add principal to configuration #18

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

```toml
users = [
{ name = "torvalds", sources = ["github"] },
{ name = "gvanrossum", sources = ["github", "gitlab"] },
{ name = "graydon", sources = ["github"] },
{ name = "cwoods", sources = ["acme-corp"] },
{ name = "rdavis", sources = ["acme-corp"] },
{ name = "pbrock", sources = ["acme-corp"] }
]
organizations = [
{ name = "rust-lang", sources = ["github"] }
{ name = "torvalds", principals = ["torvalds@linux-foundation.org"], sources = ["github"] },
{ name = "gvanrossum", principals = ["guido@python.org"], sources = ["github", "gitlab"] },
{ name = "graydon", principals = ["graydon@pobox.com"], sources = ["github"] },
{ name = "cwoods", principals = ["cwoods@acme.corp"], sources = ["acme-corp"] },
{ name = "rdavis", principals = ["rdavis@acme.corp"], sources = ["acme-corp"] },
{ name = "pbrock", principals = ["pbrock@acme.corp"], sources = ["acme-corp"] }
]
local = [
"jdoe@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJHDGMF+tZQL3dcr1arPst+YP8v33Is0kAJVvyTKrxMw"
Expand Down
15 changes: 6 additions & 9 deletions benches/load_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ use std::{io::Write, path::Path};
pub fn criterion_benchmark(c: &mut Criterion) {
let toml = indoc! {r#"
users = [
{ name = "torvalds", sources = ["github"] },
{ name = "gvanrossum", sources = ["github", "gitlab"] },
{ name = "graydon", sources = ["github"] },
{ name = "cwoods", sources = ["acme-corp"] },
{ name = "rdavis", sources = ["acme-corp"] },
{ name = "pbrock", sources = ["acme-corp"] }
]
organizations = [
{ name = "rust-lang", sources = ["github"] }
{ name = "torvalds", principals = ["torvalds@linux-foundation.org"], sources = ["github"] },
{ name = "gvanrossum", principals = ["guido@python.org"], sources = ["github", "gitlab"] },
{ name = "graydon", principals = ["graydon@pobox.com"], sources = ["github"] },
{ name = "cwoods", principals = ["cwoods@acme.corp"], sources = ["acme-corp"] },
{ name = "rdavis", principals = ["rdavis@acme.corp"], sources = ["acme-corp"] },
{ name = "pbrock", principals = ["pbrock@acme.corp"], sources = ["acme-corp"] }
]
local = [
"jdoe@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJHDGMF+tZQL3dcr1arPst+YP8v33Is0kAJVvyTKrxMw"
Expand Down
36 changes: 13 additions & 23 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::{
pub struct Config {
allowed_signers: Option<PathBuf>,
users: Option<Vec<User>>,
organizations: Option<Vec<Organization>>,
local: Option<Vec<String>>,
sources: Option<Vec<Source>>,
}
Expand All @@ -26,7 +25,6 @@ impl Default for Config {
Config {
allowed_signers: git_allowed_signers(),
users: None,
organizations: None,
local: None,
sources: Some(vec![
Source {
Expand Down Expand Up @@ -95,12 +93,7 @@ pub enum GitProviderType {
#[derive(Debug, Deserialize, Serialize, PartialEq)]
struct User {
name: String,
sources: Vec<String>,
}

#[derive(Debug, Deserialize, Serialize, PartialEq)]
struct Organization {
name: String,
principals: Vec<String>,
sources: Vec<String>,
}

Expand Down Expand Up @@ -130,15 +123,12 @@ mod tests {
fn example_config() {
let toml = indoc! {r#"
users = [
{ name = "torvalds", sources = ["github"] },
{ name = "gvanrossum", sources = ["github", "gitlab"] },
{ name = "graydon", sources = ["github"] },
{ name = "cwoods", sources = ["acme-corp"] },
{ name = "rdavis", sources = ["acme-corp"] },
{ name = "pbrock", sources = ["acme-corp"] }
]
organizations = [
{ name = "rust-lang", sources = ["github"] }
{ name = "torvalds", principals = ["torvalds@linux-foundation.org"], sources = ["github"] },
{ name = "gvanrossum", principals = ["guido@python.org"], sources = ["github", "gitlab"] },
{ name = "graydon", principals = ["graydon@pobox.com"], sources = ["github"] },
{ name = "cwoods", principals = ["cwoods@acme.corp"], sources = ["acme-corp"] },
{ name = "rdavis", principals = ["rdavis@acme.corp"], sources = ["acme-corp"] },
{ name = "pbrock", principals = ["pbrock@acme.corp"], sources = ["acme-corp"] }
]
local = [
"jdoe@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJHDGMF+tZQL3dcr1arPst+YP8v33Is0kAJVvyTKrxMw"
Expand All @@ -154,35 +144,35 @@ mod tests {
users: Some(vec![
User {
name: "torvalds".to_string(),
principals: vec!["torvalds@linux-foundation.org".to_string()],
sources: vec!["github".to_string()],
},
User {
name: "gvanrossum".to_string(),
principals: vec!["guido@python.org".to_string()],
sources: vec!["github".to_string(), "gitlab".to_string()],
},
User {
name: "graydon".to_string(),
principals: vec!["graydon@pobox.com".to_string()],
sources: vec!["github".to_string()],
},
User {
name: "cwoods".to_string(),
principals: vec!["cwoods@acme.corp".to_string()],
sources: vec!["acme-corp".to_string()],
},
User {
name: "rdavis".to_string(),
principals: vec!["rdavis@acme.corp".to_string()],
sources: vec!["acme-corp".to_string()],
},
User {
name: "pbrock".to_string(),
principals: vec!["pbrock@acme.corp".to_string()],
sources: vec!["acme-corp".to_string()],
},
]),
organizations: Some(vec![
Organization {
name: "rust-lang".to_string(),
sources: vec!["github".to_string()],
}
]),
local: Some(vec!["jdoe@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJHDGMF+tZQL3dcr1arPst+YP8v33Is0kAJVvyTKrxMw".parse().unwrap()]),
sources: Some(vec![
Source {
Expand Down