magpie.api.management.network.network_utils¶
Attributes¶
Functions¶
|
|
|
Return the content of all PEM files |
|
Return the passwords used to encrypt the PEM files. |
|
Create a private key file at the specified filename. Encrypt it using the password if specified. |
|
Return a JSON Web Key Set containing all JSON Web Keys loaded from the PEM files listed |
|
Return a dictionary containing key ids and private keys from the PEM files listed in |
|
Encode claims as a JSON web token. |
|
Decode a JSON Web Token issued by a node in the network. |
Return a |
Module Contents¶
- magpie.api.management.network.network_utils.pem_files(settings_container: magpie.typedefs.AnySettingsContainer | None = None) List[magpie.typedefs.Str][source]¶
- magpie.api.management.network.network_utils._pem_file_content(primary: bool = False, settings_container: magpie.typedefs.AnySettingsContainer | None = None) List[bytes][source]¶
Return the content of all PEM files
- magpie.api.management.network.network_utils._pem_file_passwords(primary: bool = False, settings_container: magpie.typedefs.AnySettingsContainer | None = None) List[bytes | None][source]¶
Return the passwords used to encrypt the PEM files. The passwords will be returned in the same order as the file content from _pem_file_content.
If a file is not encrypted with a password, a
Nonevalue will be returned in place of the password.For example: if there are 4 PEM files and the second and fourth are not encrypted, this will return
["password1", None, "password2"]
- magpie.api.management.network.network_utils.create_private_key(filename: magpie.typedefs.Str, password: bytes | None = None, settings_container: magpie.typedefs.AnySettingsContainer | None = None) None[source]¶
Create a private key file at the specified filename. Encrypt it using the password if specified. If password is None and the filename matches a file in MAGPIE_NETWORK_PEM_FILES, the associated password specified in MAGPIE_NETWORK_PEM_PASSWORDS will be used instead.
Warning
This function should only be used to create a file if MAGPIE_NETWORK_CREATE_MISSING_PEM_FILE is truthy. This is not enforced in this function.
- magpie.api.management.network.network_utils.jwks(primary: bool = False, settings_container: magpie.typedefs.AnySettingsContainer | None = None) jwcrypto.jwk.JWKSet[source]¶
Return a JSON Web Key Set containing all JSON Web Keys loaded from the PEM files listed in
MAGPIE_NETWORK_PEM_FILES.
- magpie.api.management.network.network_utils._private_keys(primary: bool = False) Dict[magpie.typedefs.Str, cryptography.hazmat.primitives.asymmetric.types.PrivateKeyTypes][source]¶
Return a dictionary containing key ids and private keys from the PEM files listed in
MAGPIE_NETWORK_PEM_FILES.If the
primaryargument is True, only the primary key will be included in the returned list.
- magpie.api.management.network.network_utils.encode_jwt(claims: magpie.typedefs.JSON, audience_name: magpie.typedefs.Str, settings_container: magpie.typedefs.AnySettingsContainer | None = None) magpie.typedefs.Str[source]¶
Encode claims as a JSON web token.
Unless overridden by a field in the
claimsargument, the"iss"claim will default to MAGPIE_NETWORK_INSTANCE_NAME, the"exp"claim will default to MAGPIE_NETWORK_INTERNAL_TOKEN_EXPIRY, and the"aud"claim will default toaudience_name. The JWT will be signed with Magpie’s primary private key (see the _private_keys function for details) using the asymmetric RS256 algorithm.
- magpie.api.management.network.network_utils.decode_jwt(token: magpie.typedefs.Str, node: magpie.models.NetworkNode, settings_container: magpie.typedefs.AnySettingsContainer | None = None) magpie.typedefs.JSON[source]¶
Decode a JSON Web Token issued by a node in the network.
The token must include the
"exp","aud", and"iss"claims. If the issuer is not the same asnode.name, or the audience is not this instance (i.e. the same asMAGPIE_NETWORK_INSTANCE_NAME), or the token is expired, an error will be raised. An error will also be raised if the token cannot be verified with the issuer node’s public key.
- magpie.api.management.network.network_utils.get_network_models_from_request_token(request: pyramid.request.Request, create_network_remote_user: bool = False) Tuple[magpie.models.NetworkNode, magpie.models.NetworkRemoteUser | None][source]¶
Return a
NetworkNodeand associatedNetworkRemoteUserdetermined by parsing the claims in the JWT included in therequestargument.If the
NetworkRemoteUserdoes not exist andcreate_network_remote_userisTrue, this creates a newNetworkRemoteUserassociated with the anonymous user for the givenNetworkNodeand adds it to the current database transaction.