Skip to content

Commit 6b1b9e4

Browse files
committed
Function made into a class method.
1 parent 508602d commit 6b1b9e4

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/cryptojwt/key_issuer.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class KeyIssuer(object):
25-
""" A issuer contains a number of KeyBundles. """
25+
""" A key issuer instance contains a number of KeyBundles. """
2626

2727
def __init__(self, ca_certs=None, keybundle_cls=KeyBundle,
2828
remove_after=3600, httpc=None, httpc_params=None,
@@ -69,7 +69,6 @@ def add_url(self, url, **kwargs):
6969
url as source specification. If no file format is given it's assumed
7070
that what's on the other side is a JWKS.
7171
72-
:param issuer: Who issued the keys
7372
:param url: Where can the key/-s be found
7473
:param kwargs: extra parameters for instantiating KeyBundle
7574
:return: A :py:class:`oidcmsg.oauth2.keybundle.KeyBundle` instance
@@ -234,19 +233,19 @@ def import_jwks(self, jwks):
234233
self._bundles.append(
235234
self.keybundle_cls(_keys, httpc=self.httpc, httpc_params=self.httpc_params))
236235

237-
def import_jwks_as_json(self, jwks, issuer):
236+
def import_jwks_as_json(self, jwks, issuer_id):
238237
"""
239238
Imports all the keys that are represented in a JWKS expressed as a
240239
JSON object
241240
242241
:param jwks: JSON representation of a JWKS
243-
:param issuer: Who 'owns' the JWKS
242+
:param issuer_id: Who 'owns' the JWKS
244243
"""
245244
return self.import_jwks(json.loads(jwks))
246245

247-
def import_jwks_from_file(self, filename, issuer):
246+
def import_jwks_from_file(self, filename, issuer_id):
248247
with open(filename) as jwks_file:
249-
self.import_jwks_as_json(jwks_file.read(), issuer)
248+
self.import_jwks_as_json(jwks_file.read(), issuer_id)
250249

251250
def remove_outdated(self, when=0):
252251
"""
@@ -352,7 +351,7 @@ def __len__(self):
352351

353352
def dump(self, exclude=None):
354353
"""
355-
Returns the key issuer content as a dictionary.
354+
Returns the content as a dictionary.
356355
357356
:return: A dictionary
358357
"""
@@ -447,6 +446,20 @@ def __eq__(self, other):
447446

448447
return True
449448

449+
def rotate_keys(self, key_conf, kid_template=""):
450+
"""
451+
452+
:param key_conf: The configuration for the new keys
453+
:param issuer: KeyIssuer instance
454+
:param kid_template: A key id template
455+
:return:
456+
"""
457+
new_keys = build_keyissuer(key_conf, kid_template)
458+
self.mark_all_keys_as_inactive()
459+
for kb in new_keys:
460+
self.add_kb(kb)
461+
return self
462+
450463

451464
# =============================================================================
452465

@@ -489,6 +502,7 @@ def build_keyissuer(key_conf, kid_template="", key_issuer=None, issuer_id=''):
489502
:param kid_template: A template by which to build the key IDs. If no
490503
kid_template is given then the built-in function add_kid() will be used.
491504
:param key_issuer: If an keyIssuer instance the new keys are added to this key issuer.
505+
:param issuer_id: The identifier of the issuer
492506
:return: A KeyIssuer instance
493507
"""
494508

@@ -504,16 +518,7 @@ def build_keyissuer(key_conf, kid_template="", key_issuer=None, issuer_id=''):
504518
return key_issuer
505519

506520

507-
def rotate_keys(key_conf, issuer, kid_template=""):
508-
new_keys = build_keyissuer(key_conf, kid_template)
509-
issuer.mark_all_keys_as_inactive()
510-
for kb in new_keys:
511-
issuer.add_kb(kb)
512-
return issuer
513-
514-
515-
def init_key_issuer(public_path='', private_path='', key_defs='', read_only=True,
516-
storage_conf=None, abstract_storage_cls=None):
521+
def init_key_issuer(public_path='', private_path='', key_defs='', read_only=True):
517522
"""
518523
A number of cases here:
519524

0 commit comments

Comments
 (0)