@@ -25,15 +25,14 @@ class KeyJar(object):
25
25
""" A keyjar contains a number of KeyBundles sorted by owner/issuer """
26
26
27
27
def __init__ (
28
- self ,
29
- ca_certs = None ,
30
- verify_ssl = True ,
31
- keybundle_cls = KeyBundle ,
32
- remove_after = 3600 ,
33
- httpc = None ,
34
- httpc_params = None ,
35
- storage_conf = None ,
36
- storage_factory = None ,
28
+ self ,
29
+ ca_certs = None ,
30
+ verify_ssl = True ,
31
+ keybundle_cls = KeyBundle ,
32
+ remove_after = 3600 ,
33
+ httpc = None ,
34
+ httpc_params = None ,
35
+ storage = None ,
37
36
):
38
37
"""
39
38
KeyJar init function
@@ -44,20 +43,15 @@ def __init__(
44
43
:param remove_after: How long keys marked as inactive will remain in the key Jar.
45
44
:param httpc: A HTTP client to use. Default is Requests request.
46
45
:param httpc_params: HTTP request parameters
47
- :param storage_conf: Storage configuration
48
- :param storage_factory: A function that given the storage configuration (storage_conf)
49
- will return an instance that can store information.
46
+ :param storage: An instance that can store information. It basically look like dictionary.
50
47
:return: Keyjar instance
51
48
"""
52
49
53
- if storage_conf is None :
50
+ if storage is None :
54
51
self ._issuers = {}
55
52
else :
56
- if not storage_factory :
57
- raise ValueError ("Missing storage factory specification" )
58
- self ._issuers = storage_factory (storage_conf )
53
+ self ._issuers = storage
59
54
60
- self .storage_conf = storage_conf
61
55
self .spec2key = {}
62
56
self .ca_certs = ca_certs
63
57
self .keybundle_cls = keybundle_cls
@@ -392,7 +386,7 @@ def export_jwks(self, private=False, issuer_id="", usage=None):
392
386
k .serialize (private )
393
387
for k in kb .keys ()
394
388
if k .inactive_since == 0
395
- and (usage is None or (hasattr (k , "use" ) and k .use == usage ))
389
+ and (usage is None or (hasattr (k , "use" ) and k .use == usage ))
396
390
]
397
391
)
398
392
return {"keys" : keys }
@@ -478,14 +472,14 @@ def remove_outdated(self, when=0):
478
472
479
473
@deprecated_alias (issuer = "issuer_id" , owner = "issuer_id" )
480
474
def _add_key (
481
- self ,
482
- keys ,
483
- issuer_id ,
484
- use ,
485
- key_type = "" ,
486
- kid = "" ,
487
- no_kid_issuer = None ,
488
- allow_missing_kid = False ,
475
+ self ,
476
+ keys ,
477
+ issuer_id ,
478
+ use ,
479
+ key_type = "" ,
480
+ kid = "" ,
481
+ no_kid_issuer = None ,
482
+ allow_missing_kid = False ,
489
483
):
490
484
491
485
_issuer = self ._get_issuer (issuer_id )
@@ -621,18 +615,14 @@ def get_jwt_verify_keys(self, jwt, **kwargs):
621
615
622
616
def copy (self ):
623
617
"""
624
- Make deep copy of this key jar.
618
+ Make deep copy of the content of this key jar.
619
+
620
+ Note that if this key jar uses an external storage module the copy will not.
625
621
626
622
:return: A :py:class:`oidcmsg.key_jar.KeyJar` instance
627
623
"""
628
- if self .storage_conf :
629
- _conf = self .storage_conf .get ("KeyJar" )
630
- if _conf :
631
- _label = self .storage_conf .get ("label" )
632
- if _label :
633
- self .storage_conf ["KeyJar" ]["label" ] = "{}.copy" .format (_label )
634
624
635
- kj = KeyJar (storage_conf = self . storage_conf )
625
+ kj = KeyJar ()
636
626
for _id , _issuer in self ._issuers .items ():
637
627
_issuer_copy = KeyIssuer ()
638
628
_issuer_copy .set ([kb .copy () for kb in _issuer ])
@@ -653,7 +643,6 @@ def dump(self, exclude=None):
653
643
"""
654
644
655
645
info = {
656
- # 'storage_conf': self.storage_conf,
657
646
"spec2key" : self .spec2key ,
658
647
"ca_certs" : self .ca_certs ,
659
648
"keybundle_cls" : qualified_name (self .keybundle_cls ),
@@ -676,7 +665,6 @@ def load(self, info):
676
665
:param info: A dictionary with the information
677
666
:return:
678
667
"""
679
- # self.storage_conf = info['storage_conf']
680
668
self .spec2key = info ["spec2key" ]
681
669
self .ca_certs = info ["ca_certs" ]
682
670
self .keybundle_cls = importer (info ["keybundle_cls" ])
@@ -718,7 +706,7 @@ def rotate_keys(self, key_conf, kid_template="", issuer_id=""):
718
706
719
707
720
708
def build_keyjar (
721
- key_conf , kid_template = "" , keyjar = None , issuer_id = "" , storage_conf = None , storage_factory = None
709
+ key_conf , kid_template = "" , keyjar = None , issuer_id = "" , storage = None
722
710
):
723
711
"""
724
712
Builds a :py:class:`oidcmsg.key_jar.KeyJar` instance or adds keys to
@@ -758,9 +746,7 @@ def build_keyjar(
758
746
kid_template is given then the built-in function add_kid() will be used.
759
747
:param keyjar: If an KeyJar instance the new keys are added to this key jar.
760
748
:param issuer_id: The default owner of the keys in the key jar.
761
- :param storage_conf: Storage configuration
762
- :param storage_factory: A function that given the configuration can instantiate a Storage
763
- instance.
749
+ :param storage: A Storage instance.
764
750
:return: A KeyJar instance
765
751
"""
766
752
@@ -769,7 +755,7 @@ def build_keyjar(
769
755
return None
770
756
771
757
if keyjar is None :
772
- keyjar = KeyJar (storage_conf = storage_conf , storage_factory = storage_factory )
758
+ keyjar = KeyJar (storage = storage )
773
759
774
760
keyjar [issuer_id ] = _issuer
775
761
@@ -778,13 +764,12 @@ def build_keyjar(
778
764
779
765
@deprecated_alias (issuer = "issuer_id" , owner = "issuer_id" )
780
766
def init_key_jar (
781
- public_path = "" ,
782
- private_path = "" ,
783
- key_defs = "" ,
784
- issuer_id = "" ,
785
- read_only = True ,
786
- storage_conf = None ,
787
- storage_factory = None ,
767
+ public_path = "" ,
768
+ private_path = "" ,
769
+ key_defs = "" ,
770
+ issuer_id = "" ,
771
+ read_only = True ,
772
+ storage = None ,
788
773
):
789
774
"""
790
775
A number of cases here:
@@ -822,9 +807,7 @@ def init_key_jar(
822
807
:param key_defs: A definition of what keys should be created if they are not already available
823
808
:param issuer_id: The owner of the keys
824
809
:param read_only: This function should not attempt to write anything to a file system.
825
- :param storage_conf: Configuration information for the storage
826
- :param storage_factory: A function that given the configuration can instantiate a Storage
827
- instance.
810
+ :param storage: A Storage instance.
828
811
:return: An instantiated :py:class;`oidcmsg.key_jar.KeyJar` instance
829
812
"""
830
813
@@ -835,7 +818,7 @@ def init_key_jar(
835
818
if _issuer is None :
836
819
raise ValueError ("Could not find any keys" )
837
820
838
- keyjar = KeyJar (storage_conf = storage_conf , storage_factory = storage_factory )
821
+ keyjar = KeyJar (storage = storage )
839
822
keyjar [issuer_id ] = _issuer
840
823
return keyjar
841
824
0 commit comments