-
Notifications
You must be signed in to change notification settings - Fork 18
Add non-interactive CLI support and pre-commit hooks #109
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b522a92
Add non-interactive CLI support, pre-commit hooks, and global flags
natefikru c9a43b4
Fix review issues: remove dead code, move interactive output to stderr
natefikru 49bc876
Improve test coverage and remove dead code from Output module
natefikru a9b61a2
Simplify non-interactive CLI flow
natefikru 100b787
Run tests in pre-commit hook
natefikru d39f724
Simplify login non-interactive flow
natefikru ac226ea
Always show API key setup instructions
natefikru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
| # Pre-commit hook for rust-sdk | ||
| # Runs formatting, clippy, and tests for staged Rust changes. | ||
| # Install with: make install-hooks | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Check if any Rust files are staged | ||
| STAGED_RS=$(git diff --cached --name-only --diff-filter=ACM | grep '\.rs$' || true) | ||
| STAGED_TOML=$(git diff --cached --name-only --diff-filter=ACM | grep 'Cargo\.toml$' || true) | ||
|
|
||
| if [ -z "$STAGED_RS" ] && [ -z "$STAGED_TOML" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Running pre-commit checks..." | ||
|
|
||
| # Check formatting | ||
| echo " Checking formatting..." | ||
| if ! cargo fmt -- --check; then | ||
| echo "" | ||
| echo "Formatting check failed. Run 'cargo fmt' to fix." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Run clippy | ||
| echo " Running clippy..." | ||
| if ! cargo clippy --all-targets --all-features -- -D warnings; then | ||
| echo "" | ||
| echo "Clippy check failed. Fix the warnings above." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Run tests | ||
| echo " Running tests..." | ||
| if ! cargo test; then | ||
| echo "" | ||
| echo "Tests failed. Fix the failing tests above." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Pre-commit checks passed." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,9 +61,9 @@ pub struct Args { | |
| #[arg(long)] | ||
| pub dry_run: bool, | ||
|
|
||
| /// DANGEROUS: skip interactive prompts for approving each aspect of manifest. | ||
| #[arg(long)] | ||
| pub dangerous_skip_interactive: bool, | ||
| /// Skip interactive prompts for approving each aspect of the manifest. | ||
| #[arg(short = 'y', long = "yes", alias = "dangerous-skip-interactive")] | ||
| pub yes: bool, | ||
|
|
||
| /// Write approval to file instead of stdout. | ||
| #[arg(short, long, value_name = "PATH")] | ||
|
|
@@ -75,7 +75,7 @@ pub struct Args { | |
| } | ||
|
|
||
| /// Run the approve deploy command. | ||
| pub async fn run(args: Args) -> anyhow::Result<()> { | ||
| pub async fn run(args: Args, no_input: bool) -> anyhow::Result<()> { | ||
| // Fetch manifest - track manifest_id if fetched from API | ||
| let (manifest, fetched_manifest_id) = match (&args.manifest, &args.deploy_id) { | ||
| (Some(path), _) => (read_manifest_from_path(path).await?, None), | ||
|
|
@@ -86,7 +86,12 @@ pub async fn run(args: Args) -> anyhow::Result<()> { | |
| (None, None) => bail!("a manifest source is required"), | ||
| }; | ||
|
|
||
| if !args.dangerous_skip_interactive { | ||
| if no_input && !args.yes { | ||
| bail!("Approval input is required in non-interactive mode. Re-run with --yes to explicitly approve the manifest."); | ||
| } | ||
|
|
||
| // Skip interactive approval only when --yes/-y is passed | ||
| if !args.yes { | ||
| interactive_approve(&manifest)?; | ||
| } | ||
|
|
||
|
|
@@ -238,27 +243,28 @@ async fn generate_approval( | |
| } | ||
|
|
||
| /// Walk the user through each section of the manifest for approval. | ||
| /// All interactive output goes to stderr to keep stdout clean for data. | ||
| fn interactive_approve(manifest: &Manifest) -> anyhow::Result<()> { | ||
| println!("\n========================================"); | ||
| println!(" MANIFEST APPROVAL"); | ||
| println!("========================================\n"); | ||
| eprintln!("\n========================================"); | ||
| eprintln!(" MANIFEST APPROVAL"); | ||
| eprintln!("========================================\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why stderr? |
||
|
|
||
| review_namespace(&manifest.namespace)?; | ||
| review_enclave(&manifest.enclave)?; | ||
| review_pivot(&manifest.pivot)?; | ||
| review_manifest_set(&manifest.manifest_set)?; | ||
| review_share_set(&manifest.share_set)?; | ||
|
|
||
| println!("\n========================================"); | ||
| println!(" ALL SECTIONS APPROVED"); | ||
| println!("========================================\n"); | ||
| eprintln!("\n========================================"); | ||
| eprintln!(" ALL SECTIONS APPROVED"); | ||
| eprintln!("========================================\n"); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn confirm(prompt: &str) -> anyhow::Result<()> { | ||
| print!("{prompt} [y/N]: "); | ||
| std::io::stdout().flush()?; | ||
| eprint!("{prompt} [y/N]: "); | ||
| std::io::stderr().flush()?; | ||
|
|
||
| let mut input = String::new(); | ||
| std::io::stdin().lock().read_line(&mut input)?; | ||
|
|
@@ -272,56 +278,56 @@ fn confirm(prompt: &str) -> anyhow::Result<()> { | |
| } | ||
|
|
||
| fn review_namespace(namespace: &Namespace) -> anyhow::Result<()> { | ||
| println!("NAMESPACE"); | ||
| println!("─────────────────────────────────────"); | ||
| println!(" Name: {}", namespace.name); | ||
| println!(" Nonce: {}", namespace.nonce); | ||
| println!(" Quorum Key: {}", hex::encode(&namespace.quorum_key)); | ||
| println!(); | ||
| eprintln!("NAMESPACE"); | ||
| eprintln!("─────────────────────────────────────"); | ||
| eprintln!(" Name: {}", namespace.name); | ||
| eprintln!(" Nonce: {}", namespace.nonce); | ||
| eprintln!(" Quorum Key: {}", hex::encode(&namespace.quorum_key)); | ||
| eprintln!(); | ||
|
|
||
| confirm("Approve namespace?") | ||
| } | ||
|
|
||
| fn review_enclave(enclave: &NitroConfig) -> anyhow::Result<()> { | ||
| println!("ENCLAVE (AWS Nitro)"); | ||
| println!("─────────────────────────────────────"); | ||
| println!(" PCR0 (image): {}", hex::encode(&enclave.pcr0)); | ||
| println!(" PCR1 (kernel): {}", hex::encode(&enclave.pcr1)); | ||
| println!(" PCR2 (app): {}", hex::encode(&enclave.pcr2)); | ||
| println!(" PCR3 (IAM role): {}", hex::encode(&enclave.pcr3)); | ||
| eprintln!("ENCLAVE (AWS Nitro)"); | ||
| eprintln!("─────────────────────────────────────"); | ||
| eprintln!(" PCR0 (image): {}", hex::encode(&enclave.pcr0)); | ||
| eprintln!(" PCR1 (kernel): {}", hex::encode(&enclave.pcr1)); | ||
| eprintln!(" PCR2 (app): {}", hex::encode(&enclave.pcr2)); | ||
| eprintln!(" PCR3 (IAM role): {}", hex::encode(&enclave.pcr3)); | ||
| // Skip the QOS commit since its not cryptographically linked | ||
| println!(); | ||
| eprintln!(); | ||
|
|
||
| confirm("Approve enclave configuration?") | ||
| } | ||
|
|
||
| fn review_pivot(pivot: &PivotConfig) -> anyhow::Result<()> { | ||
| println!("PIVOT BINARY"); | ||
| println!("─────────────────────────────────────"); | ||
| println!(" Pivot Binary Hash: {}", hex::encode(pivot.hash)); | ||
| eprintln!("PIVOT BINARY"); | ||
| eprintln!("─────────────────────────────────────"); | ||
| eprintln!(" Pivot Binary Hash: {}", hex::encode(pivot.hash)); | ||
| if pivot.args.is_empty() { | ||
| println!(" CLI Args: (none)"); | ||
| eprintln!(" CLI Args: (none)"); | ||
| } else { | ||
| println!(" CLI Args:\n {}", pivot.args.join("\n ")); | ||
| eprintln!(" CLI Args:\n {}", pivot.args.join("\n ")); | ||
| } | ||
| println!(); | ||
| eprintln!(); | ||
|
|
||
| confirm("Approve pivot binary?") | ||
| } | ||
|
|
||
| fn print_quorum_members(members: &[QuorumMember]) { | ||
| for member in members.iter() { | ||
| println!(" {} ({})", member.alias, hex::encode(&member.pub_key)); | ||
| eprintln!(" {} ({})", member.alias, hex::encode(&member.pub_key)); | ||
| } | ||
| } | ||
|
|
||
| fn review_manifest_set(set: &ManifestSet) -> anyhow::Result<()> { | ||
| println!("MANIFEST SET"); | ||
| println!("─────────────────────────────────────"); | ||
| println!(" Threshold: {} of {}", set.threshold, set.members.len()); | ||
| println!(" Members:"); | ||
| eprintln!("MANIFEST SET"); | ||
| eprintln!("─────────────────────────────────────"); | ||
| eprintln!(" Threshold: {} of {}", set.threshold, set.members.len()); | ||
| eprintln!(" Members:"); | ||
| print_quorum_members(&set.members); | ||
| println!(); | ||
| eprintln!(); | ||
|
|
||
| confirm("Approve manifest set?") | ||
| } | ||
|
|
@@ -352,10 +358,10 @@ fn review_share_set(set: &ShareSet) -> anyhow::Result<()> { | |
| bail!("Share set threshold must be 2, found: {}", set.threshold); | ||
| } | ||
|
|
||
| println!("SHARE SET"); | ||
| println!("─────────────────────────────────────"); | ||
| println!(" ✓ Keys and threshold match dev known share set operators"); | ||
| println!(); | ||
| eprintln!("SHARE SET"); | ||
| eprintln!("─────────────────────────────────────"); | ||
| eprintln!(" Keys and threshold match dev known share set operators"); | ||
| eprintln!(); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion is we should keep this not checked in and add to gitignore if you like using it. Pre-commit hooks are a bit more of personal pref that I don't want to push on people