-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: We are increasingly adding new things to the audit command line. E.g. we might want to grab ignore config so we can get that right. If we have `supertd audit` that centralises all of that we can easily change what we do in future. Reviewed By: aniketmathur Differential Revision: D55204654 fbshipit-source-id: 014c20b734f90cab5ca09ef3f718890c546cdb5d
- Loading branch information
1 parent
786a082
commit 5164efe
Showing
8 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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,15 @@ | ||
[package] | ||
name = "audit" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "audit" | ||
path = "bin/main.rs" | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
clap = {version = "4.1.4", features = ["derive"]} | ||
fbinit = { workspace = true } | ||
|
||
td_util = {path = "../td_util"} |
This file contains 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,15 @@ | ||
# Audit | ||
|
||
Run `buck2 audit` with all the special arguments encouraged for use with BTD. | ||
Using this helper ensures that as BTD evolves your scripts will continue to work | ||
correctly. | ||
|
||
As an example: | ||
|
||
```shell | ||
supertd audit cells | ||
supertd audit config | ||
``` | ||
|
||
Within Meta a precompiled version of `supertd` is available at | ||
`~/fbsource/tools/utd/supertd/supertd`. |
This file contains 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,18 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under both the MIT license found in the | ||
* LICENSE-MIT file in the root directory of this source tree and the Apache | ||
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory | ||
* of this source tree. | ||
*/ | ||
|
||
#![forbid(unsafe_code)] | ||
|
||
use td_util::cli::parse_args; | ||
|
||
#[fbinit::main] | ||
pub fn main(fb: fbinit::FacebookInit) -> anyhow::Result<()> { | ||
let _guard = td_util::init(fb); | ||
audit::main(parse_args()?) | ||
} |
This file contains 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,85 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under both the MIT license found in the | ||
* LICENSE-MIT file in the root directory of this source tree and the Apache | ||
* License, Version 2.0 found in the LICENSE-APACHE file in the root directory | ||
* of this source tree. | ||
*/ | ||
|
||
// We use a separate lib since doctests in a binary are ignored, | ||
// and we'd like to use doctests. | ||
|
||
#![forbid(unsafe_code)] | ||
|
||
use std::process; | ||
|
||
use clap::Parser; | ||
use td_util::command::display_command; | ||
|
||
/// Run `buck2 audit` with all the arguments required for BTD/Citadel. | ||
#[derive(Parser, Debug)] | ||
pub struct Args { | ||
#[clap(subcommand)] | ||
mode: AuditMode, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
enum AuditMode { | ||
/// Run `buck2 audit cell` with the right arguments. | ||
Cell(Common), | ||
/// Run `buck2 audit config` with the right arguments. | ||
Config(Common), | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
struct Common { | ||
/// The command for running Buck | ||
#[arg(long, default_value = "buck2")] | ||
buck: String, | ||
|
||
#[arg(long)] | ||
dry_run: bool, | ||
} | ||
|
||
/// It doesn't matter which config we run cells in, they should all be the same, | ||
/// so avoid invaliding the daemon. | ||
const REUSE_CONFIG: &str = "--reuse-current-config"; | ||
|
||
pub fn audit_cell_arguments() -> &'static [&'static str] { | ||
&["audit", "cell", "--json", REUSE_CONFIG] | ||
} | ||
|
||
pub fn audit_config_arguments() -> &'static [&'static str] { | ||
&[ | ||
"audit", | ||
"config", | ||
"--json", | ||
"--all-cells", | ||
"buildfile.name", | ||
"buildfile.name_v2", | ||
REUSE_CONFIG, | ||
] | ||
} | ||
|
||
pub fn main(args: Args) -> anyhow::Result<()> { | ||
let (common, arguments) = match args.mode { | ||
AuditMode::Cell(common) => (common, audit_cell_arguments()), | ||
AuditMode::Config(common) => (common, audit_config_arguments()), | ||
}; | ||
|
||
let mut command = std::process::Command::new(common.buck); | ||
command.args(arguments); | ||
|
||
if common.dry_run { | ||
println!("{}", display_command(&command)); | ||
return Ok(()); | ||
} | ||
|
||
let status = command.status()?; | ||
if status.success() { | ||
Ok(()) | ||
} else { | ||
process::exit(status.code().unwrap_or(1)); | ||
} | ||
} |
This file contains 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 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 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 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