summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-10 17:49:29 -0600
committermo khan <mo@mokhan.ca>2025-07-10 17:49:29 -0600
commitef572ae666732e87a35417710669ce88233a754a (patch)
tree3cc32004dee9600014417d404dbe01ac0e1faca9 /src/bin
parent8417a15087cc6f42c77fe070011ac2207f8d852d (diff)
parent6721aaffa33894624c87a54f4ed10eccd3c080e5 (diff)
Merge branch 'entities' into 'main'
Use a static ACL file(s) to make authorization decisions See merge request gitlab-org/software-supply-chain-security/authorization/authzd!6
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/cli.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/bin/cli.rs b/src/bin/cli.rs
new file mode 100644
index 00000000..fc70ae82
--- /dev/null
+++ b/src/bin/cli.rs
@@ -0,0 +1,69 @@
+use authzd::EntitiesRepository;
+use authzd::gitlab::Api;
+use clap::{Parser, Subcommand};
+
+#[derive(Parser, Debug)]
+#[command(
+ author,
+ version,
+ about = "Authorization CLI for managing Cedar entities and policies"
+)]
+struct Args {
+ #[command(subcommand)]
+ command: Commands,
+}
+
+#[derive(Subcommand, Debug)]
+enum Commands {
+ /// Generate entities from GitLab API
+ Generate {
+ /// Project ID or path (e.g., gitlab-org/gitlab)
+ #[arg(short, long)]
+ project: String,
+
+ /// Output file path
+ #[arg(short, long, default_value = "entities.json")]
+ output: String,
+
+ /// GitLab API token
+ #[arg(short, long, env = "GITLAB_TOKEN")]
+ token: String,
+
+ /// GitLab instance URL
+ #[arg(
+ short = 'H',
+ long,
+ env = "GITLAB_HOST",
+ default_value = "https://gitlab.com"
+ )]
+ host: String,
+ },
+}
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let args = Args::parse();
+
+ match args.command {
+ Commands::Generate {
+ project,
+ output,
+ token,
+ host,
+ } => {
+ let repository = EntitiesRepository::new(Api::new(token, host));
+ let entities = repository.all(project).await?;
+ EntitiesRepository::is_valid(&entities)?;
+ let json = serde_json::to_string_pretty(&entities)?;
+ std::fs::write(&output, json)?;
+
+ println!(
+ "Successfully generated {} entities to {}",
+ entities.len(),
+ output
+ );
+ }
+ }
+
+ Ok(())
+}