@@ -25,14 +25,13 @@ 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 = 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 ,
36
35
):
37
36
"""
38
37
KeyJar init function
@@ -43,15 +42,9 @@ def __init__(
43
42
:param remove_after: How long keys marked as inactive will remain in the key Jar.
44
43
:param httpc: A HTTP client to use. Default is Requests request.
45
44
:param httpc_params: HTTP request parameters
46
- :param storage: An instance that can store information. It basically look like dictionary.
47
45
:return: Keyjar instance
48
46
"""
49
-
50
- if storage is None :
51
- self ._issuers = {}
52
- else :
53
- self ._issuers = storage
54
-
47
+ self ._issuers = {}
55
48
self .spec2key = {}
56
49
self .ca_certs = ca_certs
57
50
self .keybundle_cls = keybundle_cls
@@ -386,7 +379,7 @@ def export_jwks(self, private=False, issuer_id="", usage=None):
386
379
k .serialize (private )
387
380
for k in kb .keys ()
388
381
if k .inactive_since == 0
389
- and (usage is None or (hasattr (k , "use" ) and k .use == usage ))
382
+ and (usage is None or (hasattr (k , "use" ) and k .use == usage ))
390
383
]
391
384
)
392
385
return {"keys" : keys }
@@ -472,14 +465,14 @@ def remove_outdated(self, when=0):
472
465
473
466
@deprecated_alias (issuer = "issuer_id" , owner = "issuer_id" )
474
467
def _add_key (
475
- self ,
476
- keys ,
477
- issuer_id ,
478
- use ,
479
- key_type = "" ,
480
- kid = "" ,
481
- no_kid_issuer = None ,
482
- allow_missing_kid = False ,
468
+ self ,
469
+ keys ,
470
+ issuer_id ,
471
+ use ,
472
+ key_type = "" ,
473
+ kid = "" ,
474
+ no_kid_issuer = None ,
475
+ allow_missing_kid = False ,
483
476
):
484
477
485
478
_issuer = self ._get_issuer (issuer_id )
@@ -617,8 +610,6 @@ def copy(self):
617
610
"""
618
611
Make deep copy of the content of this key jar.
619
612
620
- Note that if this key jar uses an external storage module the copy will not.
621
-
622
613
:return: A :py:class:`oidcmsg.key_jar.KeyJar` instance
623
614
"""
624
615
@@ -635,10 +626,12 @@ def copy(self):
635
626
def __len__ (self ):
636
627
return len (self ._issuers )
637
628
638
- def dump (self , exclude = None ) :
629
+ def dump (self , exclude : Optional [ bool ] = None , cutoff : Optional [ list ] = None ) -> dict :
639
630
"""
640
631
Returns the key jar content as dictionary
641
632
633
+ :param cutoff: list of attribute names that should be ignored when dumping.
634
+ :type cutoff: list
642
635
:return: A dictionary
643
636
"""
644
637
@@ -654,11 +647,21 @@ def dump(self, exclude=None):
654
647
for _id , _issuer in self ._issuers .items ():
655
648
if exclude and _issuer .name in exclude :
656
649
continue
657
- _issuers [_id ] = _issuer .dump ()
650
+ _issuers [_id ] = _issuer .dump (cutoff = cutoff )
658
651
info ["issuers" ] = _issuers
659
652
660
653
return info
661
654
655
+ def dumps (self , exclude = None ):
656
+ """
657
+ Returns a JSON representation of the key jar
658
+
659
+ :param exclude: Exclude these issuers
660
+ :return: A string
661
+ """
662
+ _dict = self .dump (exclude = exclude )
663
+ return json .dumps (_dict )
664
+
662
665
def load (self , info ):
663
666
"""
664
667
@@ -675,6 +678,9 @@ def load(self, info):
675
678
self ._issuers [_issuer_id ] = KeyIssuer ().load (_issuer_desc )
676
679
return self
677
680
681
+ def loads (self , string ):
682
+ return self .load (json .loads (string ))
683
+
678
684
@deprecated_alias (issuer = "issuer_id" , owner = "issuer_id" )
679
685
def key_summary (self , issuer_id ):
680
686
_issuer = self ._get_issuer (issuer_id )
@@ -705,7 +711,7 @@ def rotate_keys(self, key_conf, kid_template="", issuer_id=""):
705
711
# =============================================================================
706
712
707
713
708
- def build_keyjar (key_conf , kid_template = "" , keyjar = None , issuer_id = "" , storage = None ):
714
+ def build_keyjar (key_conf , kid_template = "" , keyjar = None , issuer_id = "" ):
709
715
"""
710
716
Builds a :py:class:`oidcmsg.key_jar.KeyJar` instance or adds keys to
711
717
an existing KeyJar based on a key specification.
@@ -744,7 +750,6 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, issuer_id="", storage=N
744
750
kid_template is given then the built-in function add_kid() will be used.
745
751
:param keyjar: If an KeyJar instance the new keys are added to this key jar.
746
752
:param issuer_id: The default owner of the keys in the key jar.
747
- :param storage: A Storage instance.
748
753
:return: A KeyJar instance
749
754
"""
750
755
@@ -753,7 +758,7 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, issuer_id="", storage=N
753
758
return None
754
759
755
760
if keyjar is None :
756
- keyjar = KeyJar (storage = storage )
761
+ keyjar = KeyJar ()
757
762
758
763
keyjar [issuer_id ] = _issuer
759
764
@@ -762,12 +767,11 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, issuer_id="", storage=N
762
767
763
768
@deprecated_alias (issuer = "issuer_id" , owner = "issuer_id" )
764
769
def init_key_jar (
765
- public_path = "" ,
766
- private_path = "" ,
767
- key_defs = "" ,
768
- issuer_id = "" ,
769
- read_only = True ,
770
- storage = None ,
770
+ public_path = "" ,
771
+ private_path = "" ,
772
+ key_defs = "" ,
773
+ issuer_id = "" ,
774
+ read_only = True ,
771
775
):
772
776
"""
773
777
A number of cases here:
@@ -805,7 +809,6 @@ def init_key_jar(
805
809
:param key_defs: A definition of what keys should be created if they are not already available
806
810
:param issuer_id: The owner of the keys
807
811
:param read_only: This function should not attempt to write anything to a file system.
808
- :param storage: A Storage instance.
809
812
:return: An instantiated :py:class;`oidcmsg.key_jar.KeyJar` instance
810
813
"""
811
814
@@ -819,7 +822,7 @@ def init_key_jar(
819
822
if _issuer is None :
820
823
raise ValueError ("Could not find any keys" )
821
824
822
- keyjar = KeyJar (storage = storage )
825
+ keyjar = KeyJar ()
823
826
keyjar [issuer_id ] = _issuer
824
827
return keyjar
825
828
0 commit comments