@@ -49,22 +49,28 @@ def ready() -> None:
4949
5050@cli .command ()
5151@click .argument ("path" , type = click .Path (exists = True ))
52- def diff (path : str ) -> None :
53- """Show differences between plain_secrets.json and cluster secrets.
52+ @click .option (
53+ "--format" ,
54+ type = click .Choice (["json" , "yaml" ], case_sensitive = False ),
55+ default = "json" ,
56+ help = "Output format for secret files (default: json)" ,
57+ )
58+ def diff (path : str , format : str ) -> None :
59+ """Show differences between plain_secrets file and cluster secrets.
5460
5561 PATH: Path to Tanka environment directory or .jsonnet file
5662
57- This shows what would change in the cluster based on plain_secrets.json
63+ This shows what would change in the cluster based on plain_secrets file
5864 """
5965 try :
60- # Create SecretState from path
61- secret_state = SecretState .from_path (path )
66+ # Create SecretState from path with specified format
67+ secret_state = SecretState .from_path (path , format = format )
6268
6369 # Create a Diff instance and run comparison
6470 diff_obj = Diff (secret_state )
6571 result = diff_obj .plain ()
6672
67- # Display results
73+ # Display results - Always in JSON format, it is independent of the sealed_secrets format (YAML/JSON)
6874 if result .has_differences :
6975 click .echo (result .diff_output )
7076 else :
@@ -77,17 +83,23 @@ def diff(path: str) -> None:
7783
7884@cli .command ()
7985@click .argument ("path" , type = click .Path (exists = True ))
80- def pull (path : str ) -> None :
81- """Pull secrets from the cluster to plain_secrets.json.
86+ @click .option (
87+ "--format" ,
88+ type = click .Choice (["json" , "yaml" ], case_sensitive = False ),
89+ default = "json" ,
90+ help = "Output format for secret files (default: json)" ,
91+ )
92+ def pull (path : str , format : str ) -> None :
93+ """Pull secrets from the cluster to plain_secrets file.
8294
8395 PATH: Path to Tanka environment directory or .jsonnet file
8496
8597 This extracts unencrypted secrets from the Kubernetes cluster
86- and saves them to plain_secrets.json in the environment directory.
98+ and saves them to plain_secrets.json or plain_secrets.yaml in the environment directory.
8799 """
88100 try :
89- # Create SecretState from path
90- secret_state = SecretState .from_path (path )
101+ # Create SecretState from path with specified format
102+ secret_state = SecretState .from_path (path , format = format )
91103
92104 # Create Pull instance and show differences
93105 pull_obj = Pull (secret_state )
@@ -104,18 +116,24 @@ def pull(path: str) -> None:
104116 click .secho (f" - { secret .name } (type: { secret .type } )" , fg = "yellow" )
105117
106118 # Show informational message
119+ plain_secrets_file = f"plain_secrets.{ format } "
107120 click .secho (
108- 'This shows how "plain_secrets.json " would change based on what\' s in the Kubernetes cluster' ,
121+ f 'This shows how "{ plain_secrets_file } " would change based on what\' s in the Kubernetes cluster' ,
109122 fg = "yellow" ,
110123 )
124+
125+ # Create Pull instance and show differences
126+ pull_obj = Pull (secret_state )
127+ result = pull_obj .run ()
128+
111129 # Display diff results
112130 if result .has_differences :
113131 click .echo (result .diff_output )
114132
115133 # Confirm before writing
116134 if click .confirm ("Are you sure?" ):
117135 pull_obj .write ()
118- click .echo ("Successfully pulled secrets to plain_secrets.json " )
136+ click .echo (f "Successfully pulled secrets to { plain_secrets_file } " )
119137 else :
120138 click .echo ("No differences" )
121139
@@ -126,21 +144,29 @@ def pull(path: str) -> None:
126144
127145@cli .command ()
128146@click .argument ("path" , type = click .Path (exists = True ))
129- def seal (path : str ) -> None :
130- """Seal plain_secrets.json to sealed_secrets.json.
147+ @click .option (
148+ "--format" ,
149+ type = click .Choice (["json" , "yaml" ], case_sensitive = False ),
150+ default = "json" ,
151+ help = "Output format for secret files (default: json)" ,
152+ )
153+ def seal (path : str , format : str ) -> None :
154+ """Seal plain_secrets file to sealed_secrets file.
131155
132156 PATH: Path to Tanka environment directory or .jsonnet file
133157
134- Takes secrets from plain_secrets.json , encrypts them using kubeseal,
135- and saves the resulting SealedSecret resources to sealed_secrets.json .
158+ Takes secrets from plain_secrets file , encrypts them using kubeseal,
159+ and saves the resulting SealedSecret resources to sealed_secrets file .
136160 """
137161 try :
138- # Create SecretState from path
139- secret_state = SecretState .from_path (path )
162+ # Create SecretState from path with specified format
163+ secret_state = SecretState .from_path (path , format = format )
164+
165+ sealed_secrets_file = f"sealed_secrets.{ format } "
140166
141167 # Show informational message
142168 # click.secho(
143- # 'This shows what would change in the cluster based on "plain_secrets.json "',
169+ # f 'This shows what would change in the cluster based on "plain_secrets.{format} "',
144170 # fg="yellow",
145171 # )
146172
@@ -156,7 +182,7 @@ def seal(path: str) -> None:
156182 if click .confirm ("Are you sure?" ):
157183 seal_obj = Seal (secret_state )
158184 seal_obj .run ()
159- click .echo ("Successfully sealed secrets to sealed_secrets.json " )
185+ click .echo (f "Successfully sealed secrets to { sealed_secrets_file } " )
160186 # else:
161187 # click.echo("No differences")
162188
0 commit comments