@@ -128,17 +128,33 @@ class SubjectMapping(BaseModelIgnoreExtra):
128
128
actions : list [Action ]
129
129
metadata : Metadata | None = None
130
130
131
+ class NamespaceKey (BaseModelIgnoreExtra ):
132
+ namespace_id : str
133
+ key_access_server_id : str | None = None
134
+
131
135
136
+
137
+ # Deprecated
132
138
class KasGrantNamespace (BaseModelIgnoreExtra ):
133
139
namespace_id : str
134
- key_access_server_id : str | None = None
140
+ key_id : str
135
141
136
142
143
+ class AttributeKey (BaseModelIgnoreExtra ):
144
+ attribute_id : str
145
+ key_id : str
146
+
147
+ # Deprecated
137
148
class KasGrantAttribute (BaseModelIgnoreExtra ):
138
149
attribute_id : str
139
150
key_access_server_id : str | None = None
140
151
141
152
153
+ class ValueKey (BaseModelIgnoreExtra ):
154
+ value_id : str
155
+ key_id : str
156
+
157
+ # Deprecated
142
158
class KasGrantValue (BaseModelIgnoreExtra ):
143
159
value_id : str
144
160
key_access_server_id : str | None = None
@@ -153,6 +169,12 @@ class KasPublicKey(BaseModelIgnoreExtra):
153
169
kid : str
154
170
alg : int
155
171
172
+ class KasKey (BaseModelIgnoreExtra ):
173
+ id : str
174
+ public_key_ctx : str
175
+ private_key_ctx : str
176
+ alg : str
177
+ mode : str
156
178
157
179
class KasPublicKeySet (BaseModelIgnoreExtra ):
158
180
keys : list [KasPublicKey ]
@@ -225,7 +247,42 @@ def kas_registry_create_if_not_present(self, uri: str, key: PublicKey) -> KasEnt
225
247
if e .uri == uri :
226
248
return e
227
249
return self .kas_registry_create (uri , key )
250
+
251
+ def kas_registry_create_public_key_only (self , publicKey : KasPublicKey ) -> KasKey :
252
+ cmd = self .otdfctl + "policy kas-registry key create --mode public_key" .split ()
253
+ cmd += [
254
+ f"--public-key-pem={ publicKey .pem } " ,
255
+ f"--key-id={ publicKey .kid } " ,
256
+ f"--algorithm={ publicKey .alg } " ,
257
+ ]
258
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE )
259
+ code = process .wait ()
260
+ out , err = process .communicate ()
261
+ if err :
262
+ print (err , file = sys .stderr )
263
+ if out :
264
+ print (out )
265
+ assert code == 0
266
+ return KasKey .model_validate_json (out )
228
267
268
+ def key_assign_ns (self , keyID : KasKey , ns : Namespace ) -> NamespaceKey :
269
+ cmd = self .otdfctl + "policy attributes namespace key assign" .split ()
270
+ cmd += [
271
+ f"--key-id={ keyID .id } " ,
272
+ f"--namespace={ ns .id } " ,
273
+ ]
274
+ logger .info (f"key-assign [{ ' ' .join (cmd )} ]" )
275
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE )
276
+ code = process .wait ()
277
+ out , err = process .communicate ()
278
+ if err :
279
+ print (err , file = sys .stderr )
280
+ if out :
281
+ print (out )
282
+ assert code == 0
283
+ return NamespaceKey .model_validate_json (out )
284
+
285
+ # Deprecated
229
286
def grant_assign_ns (self , kas : KasEntry , ns : Namespace ) -> KasGrantNamespace :
230
287
cmd = self .otdfctl + "policy kas-grants assign" .split ()
231
288
cmd += [
@@ -242,7 +299,25 @@ def grant_assign_ns(self, kas: KasEntry, ns: Namespace) -> KasGrantNamespace:
242
299
print (out )
243
300
assert code == 0
244
301
return KasGrantNamespace .model_validate_json (out )
302
+
303
+ def key_assign_attr (self , keyID : KasKey , attr : Attribute ) -> AttributeKey :
304
+ cmd = self .otdfctl + "policy attributes key assign" .split ()
305
+ cmd += [
306
+ f"--key-id={ keyID .id } " ,
307
+ f"--attribute={ attr .id } " ,
308
+ ]
309
+ logger .info (f"key-assign [{ ' ' .join (cmd )} ]" )
310
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE )
311
+ code = process .wait ()
312
+ out , err = process .communicate ()
313
+ if err :
314
+ print (err , file = sys .stderr )
315
+ if out :
316
+ print (out )
317
+ assert code == 0
318
+ return AttributeKey .model_validate_json (out )
245
319
320
+ # Deprecated
246
321
def grant_assign_attr (self , kas : KasEntry , attr : Attribute ) -> KasGrantAttribute :
247
322
cmd = self .otdfctl + "policy kas-grants assign" .split ()
248
323
cmd += [
@@ -260,6 +335,24 @@ def grant_assign_attr(self, kas: KasEntry, attr: Attribute) -> KasGrantAttribute
260
335
assert code == 0
261
336
return KasGrantAttribute .model_validate_json (out )
262
337
338
+ def key_assign_value (self , keyID : KasKey , val : AttributeValue ) -> ValueKey :
339
+ cmd = self .otdfctl + "policy attributes value key assign" .split ()
340
+ cmd += [
341
+ f"--key-id={ keyID .id } " ,
342
+ f"--value-id={ val .id } " ,
343
+ ]
344
+ logger .info (f"key-assign [{ ' ' .join (cmd )} ]" )
345
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE )
346
+ code = process .wait ()
347
+ out , err = process .communicate ()
348
+ if err :
349
+ print (err , file = sys .stderr )
350
+ if out :
351
+ print (out )
352
+ assert code == 0
353
+ return ValueKey .model_validate_json (out )
354
+
355
+ # Deprecated
263
356
def grant_assign_value (self , kas : KasEntry , val : AttributeValue ) -> KasGrantValue :
264
357
cmd = self .otdfctl + "policy kas-grants assign" .split ()
265
358
cmd += [
@@ -276,7 +369,25 @@ def grant_assign_value(self, kas: KasEntry, val: AttributeValue) -> KasGrantValu
276
369
print (out )
277
370
assert code == 0
278
371
return KasGrantValue .model_validate_json (out )
372
+
373
+ def key_unassign_ns (self , keyID : KasKey , ns : Namespace ) -> NamespaceKey :
374
+ cmd = self .otdfctl + "policy attributes namespace key unassign" .split ()
375
+ cmd += [
376
+ f"--key-id={ keyID .id } " ,
377
+ f"--namespace={ ns .id } " ,
378
+ ]
379
+ logger .info (f"key-assign [{ ' ' .join (cmd )} ]" )
380
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE )
381
+ code = process .wait ()
382
+ out , err = process .communicate ()
383
+ if err :
384
+ print (err , file = sys .stderr )
385
+ if out :
386
+ print (out )
387
+ assert code == 0
388
+ return NamespaceKey .model_validate_json (out )
279
389
390
+ # Deprecated
280
391
def grant_unassign_ns (self , kas : KasEntry , ns : Namespace ) -> KasGrantNamespace :
281
392
cmd = self .otdfctl + "policy kas-grants unassign" .split ()
282
393
cmd += [
@@ -293,7 +404,25 @@ def grant_unassign_ns(self, kas: KasEntry, ns: Namespace) -> KasGrantNamespace:
293
404
print (out )
294
405
assert code == 0
295
406
return KasGrantNamespace .model_validate_json (out )
296
-
407
+
408
+ def key_unassign_attr (self , keyID : KasKey , attr : Attribute ) -> AttributeKey :
409
+ cmd = self .otdfctl + "policy attributes key unassign" .split ()
410
+ cmd += [
411
+ f"--key-id={ keyID .id } " ,
412
+ f"--attribute={ attr .id } " ,
413
+ ]
414
+ logger .info (f"key-assign [{ ' ' .join (cmd )} ]" )
415
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE )
416
+ code = process .wait ()
417
+ out , err = process .communicate ()
418
+ if err :
419
+ print (err , file = sys .stderr )
420
+ if out :
421
+ print (out )
422
+ assert code == 0
423
+ return AttributeKey .model_validate_json (out )
424
+
425
+ # Deprecated
297
426
def grant_unassign_attr (self , kas : KasEntry , attr : Attribute ) -> KasGrantAttribute :
298
427
cmd = self .otdfctl + "policy kas-grants unassign" .split ()
299
428
cmd += [
@@ -311,6 +440,24 @@ def grant_unassign_attr(self, kas: KasEntry, attr: Attribute) -> KasGrantAttribu
311
440
assert code == 0
312
441
return KasGrantAttribute .model_validate_json (out )
313
442
443
+ def key_unassign_value (self , keyID : KasKey , val : AttributeValue ) -> ValueKey :
444
+ cmd = self .otdfctl + "policy attributes value key unassign" .split ()
445
+ cmd += [
446
+ f"--key-id={ keyID .id } " ,
447
+ f"--value-id={ val .id } " ,
448
+ ]
449
+ logger .info (f"key-assign [{ ' ' .join (cmd )} ]" )
450
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE )
451
+ code = process .wait ()
452
+ out , err = process .communicate ()
453
+ if err :
454
+ print (err , file = sys .stderr )
455
+ if out :
456
+ print (out )
457
+ assert code == 0
458
+ return ValueKey .model_validate_json (out )
459
+
460
+ # Deprecated
314
461
def grant_unassign_value (self , kas : KasEntry , val : AttributeValue ) -> KasGrantValue :
315
462
cmd = self .otdfctl + "policy kas-grants unassign" .split ()
316
463
cmd += [
0 commit comments