4
4
from typing import List
5
5
from typing import Optional
6
6
7
- from abstorage .base import LabeledAbstractStorage
8
7
from requests import request
9
8
10
9
from .jwe .jwe import alg2keytype as jwe_alg2keytype
@@ -40,7 +39,7 @@ class KeyJar(object):
40
39
41
40
def __init__ (self , ca_certs = None , verify_ssl = True , keybundle_cls = KeyBundle ,
42
41
remove_after = 3600 , httpc = None , httpc_params = None , storage_conf = None ,
43
- abstract_storage_cls = LabeledAbstractStorage ):
42
+ abstract_storage_cls = None ):
44
43
"""
45
44
KeyJar init function
46
45
@@ -56,6 +55,8 @@ def __init__(self, ca_certs=None, verify_ssl=True, keybundle_cls=KeyBundle,
56
55
if storage_conf is None :
57
56
self ._issuers = {}
58
57
else :
58
+ if not abstract_storage_cls :
59
+ raise ValueError ('Missing storage class specification' )
59
60
self ._issuers = abstract_storage_cls (storage_conf )
60
61
61
62
self .storage_conf = storage_conf
@@ -407,7 +408,7 @@ def export_jwks(self, private=False, issuer_id="", usage=None):
407
408
"""
408
409
_issuer = self ._get_issuer (issuer_id = issuer_id )
409
410
if _issuer is None :
410
- return {}
411
+ return {"keys" : [] }
411
412
412
413
keys = []
413
414
for kb in _issuer :
@@ -437,11 +438,12 @@ def import_jwks(self, jwks, issuer_id):
437
438
_keys = jwks ["keys" ]
438
439
except KeyError :
439
440
raise ValueError ('Not a proper JWKS' )
440
- else :
441
+
442
+ if _keys :
441
443
_issuer = self .return_issuer (issuer_id = issuer_id )
442
444
_issuer .add (self .keybundle_cls (_keys , httpc = self .httpc ,
443
445
httpc_params = self .httpc_params ))
444
- self [issuer_id ] = _issuer
446
+ self [issuer_id ] = _issuer
445
447
446
448
def import_jwks_as_json (self , jwks , issuer_id ):
447
449
"""
@@ -776,7 +778,7 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, issuer_id='', storage_c
776
778
777
779
778
780
def init_key_jar (public_path = '' , private_path = '' , key_defs = '' , issuer_id = '' , read_only = True ,
779
- storage_conf = None ):
781
+ storage_conf = None , abstract_storage_cls = None ):
780
782
"""
781
783
A number of cases here:
782
784
@@ -888,7 +890,10 @@ def init_key_jar(public_path='', private_path='', key_defs='', issuer_id='', rea
888
890
else :
889
891
_issuer = build_keyissuer (key_defs , issuer_id = issuer_id )
890
892
891
- keyjar = KeyJar (storage_conf = storage_conf )
893
+ if _issuer is None :
894
+ raise ValueError ('Could not find any keys' )
895
+
896
+ keyjar = KeyJar (storage_conf = storage_conf , abstract_storage_cls = abstract_storage_cls )
892
897
keyjar [issuer_id ] = _issuer
893
898
return keyjar
894
899
0 commit comments