@@ -63,14 +63,38 @@ class Assignment:
6363 name : str
6464 value : str
6565
66- def gh_command (self ) -> list [str ]:
67- command = ["gh" , "variable" , "set" , self .name , "--repo" , self .repository , "--body" , self .value ]
66+ def gh_command (self , * , redact_body : bool = False , redact_metadata : bool = False ) -> list [str ]:
67+ body = redacted_value () if redact_body else self .value
68+ repository = redacted_value () if redact_metadata else self .repository
69+ command = ["gh" , "variable" , "set" , self .name , "--repo" , repository , "--body" , body ]
6870 if self .variable_scope == "environment" :
69- command .extend (["--env" , self .environment or "" ])
71+ environment = redacted_value () if redact_metadata else (self .environment or "" )
72+ command .extend (["--env" , environment ])
7073 return command
7174
72- def shell_command (self ) -> str :
73- return " " .join (shlex .quote (part ) for part in self .gh_command ())
75+ def shell_command (self , * , redact_body : bool = False , redact_metadata : bool = False ) -> str :
76+ return " " .join (
77+ shlex .quote (part )
78+ for part in self .gh_command (redact_body = redact_body , redact_metadata = redact_metadata )
79+ )
80+
81+
82+ def redacted_value () -> str :
83+ return "<redacted>"
84+
85+
86+ def assignment_payload (assignment : Assignment , * , redact_values : bool = False ) -> dict [str , Any ]:
87+ payload = {
88+ "target_id" : assignment .target_id ,
89+ "repository" : assignment .repository ,
90+ "variable_scope" : assignment .variable_scope ,
91+ "environment" : assignment .environment ,
92+ "name" : assignment .name ,
93+ "value" : redacted_value () if redact_values else assignment .value ,
94+ }
95+ if redact_values :
96+ payload ["value_redacted" ] = True
97+ return payload
7498
7599
76100def compact_json (value : Any ) -> str :
@@ -482,14 +506,7 @@ def command_render(args: argparse.Namespace) -> int:
482506 print (
483507 json .dumps (
484508 [
485- {
486- "target_id" : assignment .target_id ,
487- "repository" : assignment .repository ,
488- "variable_scope" : assignment .variable_scope ,
489- "environment" : assignment .environment ,
490- "name" : assignment .name ,
491- "value" : assignment .value ,
492- }
509+ assignment_payload (assignment , redact_values = args .redact_values )
493510 for assignment in all_assignments
494511 ],
495512 ensure_ascii = False ,
@@ -500,7 +517,7 @@ def command_render(args: argparse.Namespace) -> int:
500517
501518 if args .format == "gh" :
502519 for assignment in all_assignments :
503- print (assignment .shell_command ())
520+ print (assignment .shell_command (redact_body = args . redact_values , redact_metadata = args . redact_values ))
504521 return 0
505522
506523 current_target = None
@@ -511,7 +528,8 @@ def command_render(args: argparse.Namespace) -> int:
511528 if assignment .environment :
512529 suffix += f":{ assignment .environment } "
513530 print (f"# { assignment .target_id } -> { assignment .repository } ({ suffix } )" )
514- print (f"{ assignment .name } ={ shlex .quote (assignment .value )} " )
531+ value = redacted_value () if args .redact_values else assignment .value
532+ print (f"{ assignment .name } ={ shlex .quote (value )} " )
515533 return 0
516534
517535
@@ -521,10 +539,15 @@ def command_apply(args: argparse.Namespace) -> int:
521539 all_assignments .extend (build_assignments (target ))
522540
523541 for assignment in all_assignments :
524- print (assignment .shell_command ())
542+ redact_preview = not args .show_values
543+ print (assignment .shell_command (redact_body = redact_preview , redact_metadata = redact_preview ))
525544
526545 if not args .yes :
527- print ("\n Dry run only. Re-run with --yes to apply these GitHub variables." )
546+ if args .show_values :
547+ print ("\n Dry run only. Re-run with --yes to apply these GitHub variables." )
548+ else :
549+ print ("\n Dry run only. Re-run with --yes to apply these GitHub variables." )
550+ print ("Values are redacted by default; add --show-values only in a private local terminal." )
528551 return 0
529552
530553 for assignment in all_assignments :
@@ -548,11 +571,17 @@ def build_parser() -> argparse.ArgumentParser:
548571 render = subparsers .add_parser ("render" , help = "render generated variables" )
549572 render .add_argument ("targets" , nargs = "*" , help = "target JSON files; defaults to all targets" )
550573 render .add_argument ("--format" , choices = ("env" , "gh" , "json" ), default = "env" )
574+ render .add_argument ("--redact-values" , action = "store_true" , help = "hide assignment values in rendered output" )
551575 render .set_defaults (func = command_render )
552576
553577 apply = subparsers .add_parser ("apply" , help = "preview or apply GitHub variable updates" )
554578 apply .add_argument ("targets" , nargs = "*" , help = "target JSON files; defaults to all targets" )
555579 apply .add_argument ("--yes" , action = "store_true" , help = "apply updates with gh variable set" )
580+ apply .add_argument (
581+ "--show-values" ,
582+ action = "store_true" ,
583+ help = "print exact values in the preview; avoid this in public CI logs" ,
584+ )
556585 apply .set_defaults (func = command_apply )
557586
558587 repository = subparsers .add_parser ("repository" , help = "print the configured platform repository" )
0 commit comments