Skip to content

Commit

Permalink
fix: moved unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalDR committed Feb 18, 2025
1 parent 57c52c4 commit 4920326
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 60 deletions.
57 changes: 57 additions & 0 deletions oldies/tools/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
def get_jwks(
httpc_params: dict, metadata: dict, federation_jwks: list[dict] = []
) -> dict:
"""
Get jwks or jwks_uri or signed_jwks_uri
:param httpc_params: parameters to perform http requests.
:type httpc_params: dict
:param metadata: metadata of the entity
:type metadata: dict
:param federation_jwks: jwks of the federation
:type federation_jwks: list
:returns: A list of responses.
:rtype: list[dict]
"""
jwks_list = []
if metadata.get("jwks"):
jwks_list = metadata["jwks"]["keys"]
elif metadata.get("jwks_uri"):
try:
jwks_uri = metadata["jwks_uri"]
jwks_list = get_http_url([jwks_uri], httpc_params=httpc_params)
jwks_list = jwks_list[0].json()
except Exception as e:
logger.error(f"Failed to download jwks from {jwks_uri}: {e}")
elif metadata.get("signed_jwks_uri"):
try:
signed_jwks_uri = metadata["signed_jwks_uri"]
jwks_list = get_http_url([signed_jwks_uri], httpc_params=httpc_params)[
0
].json()
except Exception as e:
logger.error(f"Failed to download jwks from {signed_jwks_uri}: {e}")
return jwks_list

def satisfy_interface(o: object, interface: type) -> bool:
"""
Returns true if and only if an object satisfy an interface.
:param o: an object (instance of a class)
:type o: object
:param interface: an interface type
:type interface: type
:returns: True if the object satisfy the interface, otherwise False
"""
for cls_attr in dir(interface):
if cls_attr.startswith("_"):
continue
if not hasattr(o, cls_attr):
return False
if callable(getattr(interface, cls_attr)) and not callable(
getattr(o, cls_attr)
):
return False
return True
60 changes: 0 additions & 60 deletions pyeudiw/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,43 +99,6 @@ def get_http_url(
return responses


def get_jwks(
httpc_params: dict, metadata: dict, federation_jwks: list[dict] = []
) -> dict:
"""
Get jwks or jwks_uri or signed_jwks_uri
:param httpc_params: parameters to perform http requests.
:type httpc_params: dict
:param metadata: metadata of the entity
:type metadata: dict
:param federation_jwks: jwks of the federation
:type federation_jwks: list
:returns: A list of responses.
:rtype: list[dict]
"""
jwks_list = []
if metadata.get("jwks"):
jwks_list = metadata["jwks"]["keys"]
elif metadata.get("jwks_uri"):
try:
jwks_uri = metadata["jwks_uri"]
jwks_list = get_http_url([jwks_uri], httpc_params=httpc_params)
jwks_list = jwks_list[0].json()
except Exception as e:
logger.error(f"Failed to download jwks from {jwks_uri}: {e}")
elif metadata.get("signed_jwks_uri"):
try:
signed_jwks_uri = metadata["signed_jwks_uri"]
jwks_list = get_http_url([signed_jwks_uri], httpc_params=httpc_params)[
0
].json()
except Exception as e:
logger.error(f"Failed to download jwks from {signed_jwks_uri}: {e}")
return jwks_list


def random_token(n=254) -> str:
"""
Generate a random token.
Expand Down Expand Up @@ -188,29 +151,6 @@ def dynamic_class_loader(
return storage_instance


def satisfy_interface(o: object, interface: type) -> bool:
"""
Returns true if and only if an object satisfy an interface.
:param o: an object (instance of a class)
:type o: object
:param interface: an interface type
:type interface: type
:returns: True if the object satisfy the interface, otherwise False
"""
for cls_attr in dir(interface):
if cls_attr.startswith("_"):
continue
if not hasattr(o, cls_attr):
return False
if callable(getattr(interface, cls_attr)) and not callable(
getattr(o, cls_attr)
):
return False
return True


_HttpcParams_T = NamedTuple("_HttpcParams_T", [("ssl", bool), ("timeout", int)])


Expand Down

0 comments on commit 4920326

Please sign in to comment.