Skip to content

Commit 1efc616

Browse files
committed
buildbot-effects: don't print program arguments by default
since we run outside of buildbot, secrets are not hidden if they are provided via commandline
1 parent a701a54 commit 1efc616

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

buildbot_effects/buildbot_effects/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def run(
2222
stdin: int | IO[str] | None = None,
2323
stdout: int | IO[str] | None = None,
2424
stderr: int | IO[str] | None = None,
25-
verbose: bool = True,
25+
debug: bool = True,
2626
) -> subprocess.CompletedProcess[str]:
27-
if verbose:
27+
if debug:
2828
print("$", shlex.join(cmd), file=sys.stderr)
2929
return subprocess.run(
3030
cmd,
@@ -36,9 +36,9 @@ def run(
3636
)
3737

3838

39-
def git_command(args: list[str], path: Path) -> str:
39+
def git_command(args: list[str], path: Path, debug: bool = False) -> str:
4040
cmd = ["git", "-C", str(path), *args]
41-
proc = run(cmd, stdout=subprocess.PIPE)
41+
proc = run(cmd, stdout=subprocess.PIPE, debug=debug)
4242
return proc.stdout.strip()
4343

4444

@@ -121,7 +121,7 @@ def list_effects(opts: EffectsOptions) -> list[str]:
121121
"--expr",
122122
f"builtins.attrNames ({effect_function(opts)})",
123123
)
124-
proc = run(cmd, stdout=subprocess.PIPE)
124+
proc = run(cmd, stdout=subprocess.PIPE, debug=opts.debug)
125125
return json.loads(proc.stdout)
126126

127127

@@ -131,11 +131,11 @@ def instantiate_effects(effect: str, opts: EffectsOptions) -> str:
131131
"--expr",
132132
f"(({effect_function(opts)}).{effect}).run or []",
133133
]
134-
proc = run(cmd, stdout=subprocess.PIPE)
134+
proc = run(cmd, stdout=subprocess.PIPE, debug=opts.debug)
135135
return proc.stdout.rstrip()
136136

137137

138-
def parse_derivation(path: str) -> dict[str, Any]:
138+
def parse_derivation(path: str, debug: bool = False) -> dict[str, Any]:
139139
cmd = [
140140
"nix",
141141
"--extra-experimental-features",
@@ -144,7 +144,7 @@ def parse_derivation(path: str) -> dict[str, Any]:
144144
"show",
145145
f"{path}^*",
146146
]
147-
proc = run(cmd, stdout=subprocess.PIPE)
147+
proc = run(cmd, stdout=subprocess.PIPE, debug=debug)
148148
return json.loads(proc.stdout)
149149

150150

@@ -176,6 +176,7 @@ def run_effects(
176176
drv_path: str,
177177
drv: dict[str, Any],
178178
secrets: dict[str, Any] | None = None,
179+
debug: bool = False,
179180
) -> None:
180181
if secrets is None:
181182
secrets = {}
@@ -257,7 +258,8 @@ def run_effects(
257258
bubblewrap_cmd.append("--")
258259
bubblewrap_cmd.extend(sandboxed_cmd)
259260
with pipe() as (r_file, w_file):
260-
print("$", shlex.join(bubblewrap_cmd), file=sys.stderr)
261+
if debug:
262+
print("$", shlex.join(bubblewrap_cmd), file=sys.stderr)
261263
proc = subprocess.Popen(
262264
bubblewrap_cmd,
263265
text=True,

buildbot_effects/buildbot_effects/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def parse_args() -> tuple[argparse.Namespace, EffectsOptions]:
5656
default=Path(),
5757
help="Path to the repository",
5858
)
59+
parser.add_argument(
60+
"--debug",
61+
default=False,
62+
action="store_true",
63+
help="Enable debug mode (may leak secrets such as GITHUB_TOKEN)",
64+
)
5965
subparser = parser.add_subparsers(
6066
dest="command",
6167
required=True,
@@ -88,6 +94,7 @@ def parse_args() -> tuple[argparse.Namespace, EffectsOptions]:
8894
rev=args.rev,
8995
repo=args.repo,
9096
path=args.path.resolve(),
97+
debug=args.debug,
9198
)
9299
return args, opts
93100

buildbot_effects/buildbot_effects/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ class EffectsOptions:
1111
branch: str | None = None
1212
url: str | None = None
1313
tag: str | None = None
14+
debug: bool = False

0 commit comments

Comments
 (0)