38
38
from zenml .constants import SECRET_VALUES
39
39
from zenml .enums import (
40
40
CliCategories ,
41
- SecretScope ,
42
41
)
43
42
from zenml .exceptions import EntityExistsError , ZenKeyError
44
43
from zenml .logger import get_logger
@@ -59,11 +58,12 @@ def secret() -> None:
59
58
)
60
59
@click .argument ("name" , type = click .STRING )
61
60
@click .option (
62
- "--scope" ,
63
- "-s" ,
64
- "scope" ,
65
- type = click .Choice ([scope .value for scope in list (SecretScope )]),
66
- default = SecretScope .WORKSPACE .value ,
61
+ "--private" ,
62
+ "-p" ,
63
+ "private" ,
64
+ is_flag = True ,
65
+ help = "Whether the secret is private. A private secret is only accessible "
66
+ "to the user who creates it." ,
67
67
)
68
68
@click .option (
69
69
"--interactive" ,
@@ -84,13 +84,13 @@ def secret() -> None:
84
84
)
85
85
@click .argument ("args" , nargs = - 1 , type = click .UNPROCESSED )
86
86
def create_secret (
87
- name : str , scope : str , interactive : bool , values : str , args : List [str ]
87
+ name : str , private : bool , interactive : bool , values : str , args : List [str ]
88
88
) -> None :
89
89
"""Create a secret.
90
90
91
91
Args:
92
92
name: The name of the secret to create.
93
- scope: The scope of the secret to create .
93
+ private: Whether the secret is private .
94
94
interactive: Whether to use interactive mode to enter the secret values.
95
95
values: Secret key-value pairs to be passed as JSON or YAML.
96
96
args: The arguments to pass to the secret.
@@ -152,7 +152,7 @@ def create_secret(
152
152
with console .status (f"Saving secret `{ name } `..." ):
153
153
try :
154
154
client .create_secret (
155
- name = name , values = parsed_args , scope = SecretScope ( scope )
155
+ name = name , values = parsed_args , private = private
156
156
)
157
157
declare (f"Secret '{ name } ' successfully created." )
158
158
except EntityExistsError as e :
@@ -186,7 +186,7 @@ def list_secrets(**kwargs: Any) -> None:
186
186
dict (
187
187
name = secret .name ,
188
188
id = str (secret .id ),
189
- scope = secret .scope . value ,
189
+ private = secret .private ,
190
190
)
191
191
for secret in secrets .items
192
192
]
@@ -200,22 +200,26 @@ def list_secrets(**kwargs: Any) -> None:
200
200
type = click .STRING ,
201
201
)
202
202
@click .option (
203
- "--scope" ,
204
- "-s" ,
205
- type = click .Choice ([scope .value for scope in list (SecretScope )]),
206
- default = None ,
203
+ "--private" ,
204
+ "-p" ,
205
+ "private" ,
206
+ type = click .BOOL ,
207
+ required = False ,
208
+ help = "Use this flag to explicitly fetch a private secret or a public secret." ,
207
209
)
208
- def get_secret (name_id_or_prefix : str , scope : Optional [str ] = None ) -> None :
210
+ def get_secret (name_id_or_prefix : str , private : Optional [bool ] = None ) -> None :
209
211
"""Get a secret and print it to the console.
210
212
211
213
Args:
212
214
name_id_or_prefix: The name of the secret to get.
213
- scope: The scope of the secret to get .
215
+ private: Private status of the secret to filter for .
214
216
"""
215
- secret = _get_secret (name_id_or_prefix , scope )
217
+ secret = _get_secret (name_id_or_prefix , private )
218
+ scope = ""
219
+ if private is not None :
220
+ scope = "private " if private else "public "
216
221
declare (
217
- f"Fetched secret with name `{ secret .name } ` and ID `{ secret .id } ` in "
218
- f"scope `{ secret .scope .value } `:"
222
+ f"Fetched { scope } secret with name `{ secret .name } ` and ID `{ secret .id } `:"
219
223
)
220
224
if not secret .secret_values :
221
225
warning (f"Secret with name `{ name_id_or_prefix } ` is empty." )
@@ -224,25 +228,22 @@ def get_secret(name_id_or_prefix: str, scope: Optional[str] = None) -> None:
224
228
225
229
226
230
def _get_secret (
227
- name_id_or_prefix : str , scope : Optional [str ] = None
231
+ name_id_or_prefix : str , private : Optional [bool ] = None
228
232
) -> SecretResponse :
229
233
"""Get a secret with a given name, prefix or id.
230
234
231
235
Args:
232
236
name_id_or_prefix: The name of the secret to get.
233
- scope: The scope of the secret to get .
237
+ private: Private status of the secret to filter for .
234
238
235
239
Returns:
236
240
The secret response model.
237
241
"""
238
242
client = Client ()
239
243
try :
240
- if scope :
241
- return client .get_secret (
242
- name_id_or_prefix = name_id_or_prefix , scope = SecretScope (scope )
243
- )
244
- else :
245
- return client .get_secret (name_id_or_prefix = name_id_or_prefix )
244
+ return client .get_secret (
245
+ name_id_or_prefix = name_id_or_prefix , private = private
246
+ )
246
247
except ZenKeyError as e :
247
248
error (
248
249
f"Error fetching secret with name id or prefix "
@@ -267,9 +268,12 @@ def _get_secret(
267
268
type = click .STRING ,
268
269
)
269
270
@click .option (
270
- "--new-scope" ,
271
- "-s" ,
272
- type = click .Choice ([scope .value for scope in list (SecretScope )]),
271
+ "--private" ,
272
+ "-p" ,
273
+ "private" ,
274
+ type = click .BOOL ,
275
+ required = False ,
276
+ help = "Update the private status of the secret." ,
273
277
)
274
278
@click .option (
275
279
"--interactive" ,
@@ -293,7 +297,7 @@ def _get_secret(
293
297
def update_secret (
294
298
name_or_id : str ,
295
299
extra_args : List [str ],
296
- new_scope : Optional [str ] = None ,
300
+ private : Optional [bool ] = None ,
297
301
remove_keys : List [str ] = [],
298
302
interactive : bool = False ,
299
303
values : str = "" ,
@@ -302,7 +306,7 @@ def update_secret(
302
306
303
307
Args:
304
308
name_or_id: The name or id of the secret to update.
305
- new_scope: The new scope of the secret.
309
+ private: Private status of the secret to update .
306
310
extra_args: The arguments to pass to the secret.
307
311
interactive: Whether to use interactive mode to update the secret.
308
312
remove_keys: The keys to remove from the secret.
@@ -331,10 +335,7 @@ def update_secret(
331
335
except NotImplementedError as e :
332
336
error (f"Centralized secrets management is disabled: { str (e )} " )
333
337
334
- declare (
335
- f"Updating secret with name '{ secret .name } ' and ID '{ secret .id } ' in "
336
- f"scope '{ secret .scope .value } :"
337
- )
338
+ declare (f"Updating secret with name '{ secret .name } ' and ID '{ secret .id } '" )
338
339
339
340
if "name" in parsed_args :
340
341
error ("The word 'name' cannot be used as a key for a secret." )
@@ -388,7 +389,7 @@ def update_secret(
388
389
389
390
client .update_secret (
390
391
name_id_or_prefix = secret .id ,
391
- new_scope = SecretScope ( new_scope ) if new_scope else None ,
392
+ update_private = private ,
392
393
add_or_update_values = secret_args_add_update ,
393
394
remove_values = remove_keys ,
394
395
)
@@ -492,10 +493,12 @@ def delete_secret(name_or_id: str, yes: bool = False) -> None:
492
493
type = click .STRING ,
493
494
)
494
495
@click .option (
495
- "--scope" ,
496
- "-s" ,
497
- type = click .Choice ([scope .value for scope in list (SecretScope )]),
498
- default = None ,
496
+ "--private" ,
497
+ "-p" ,
498
+ "private" ,
499
+ type = click .BOOL ,
500
+ required = False ,
501
+ help = "Use this flag to explicitly fetch a private secret or a public secret." ,
499
502
)
500
503
@click .option (
501
504
"--filename" ,
@@ -509,7 +512,7 @@ def delete_secret(name_or_id: str, yes: bool = False) -> None:
509
512
)
510
513
def export_secret (
511
514
name_id_or_prefix : str ,
512
- scope : Optional [str ] = None ,
515
+ private : Optional [bool ] = None ,
513
516
filename : Optional [str ] = None ,
514
517
) -> None :
515
518
"""Export a secret as a YAML file.
@@ -519,12 +522,12 @@ def export_secret(
519
522
520
523
Args:
521
524
name_id_or_prefix: The name of the secret to export.
522
- scope: The scope of the secret to export.
525
+ private: Private status of the secret to export.
523
526
filename: The name of the file to export the secret to.
524
527
"""
525
528
from zenml .utils .yaml_utils import write_yaml
526
529
527
- secret = _get_secret (name_id_or_prefix = name_id_or_prefix , scope = scope )
530
+ secret = _get_secret (name_id_or_prefix = name_id_or_prefix , private = private )
528
531
if not secret .secret_values :
529
532
warning (f"Secret with name `{ name_id_or_prefix } ` is empty." )
530
533
return
0 commit comments