pyauthorizer package

Copyright (c) 2023-2024 msclock. All rights reserved.

pyauthorizer: A simple authorizer for python project.

Subpackages

Submodules

pyauthorizer.cli module

pyauthorizer.cli.convert_user_args_to_dict(user_list)[source]

Converts a list of user arguments to a dictionary.

Parameters:

user_list (list) – A list of user arguments.

Returns:

A dictionary containing the converted user arguments. The keys are the names extracted from the user arguments, and the values are the corresponding values.

Return type:

dict

Raises:

PyAuthorizerError – If the user arguments are not in the correct format or if a parameter is repeated.

pyauthorizer.exceptions module

class pyauthorizer.exceptions.ErrorName(internal_error=1, invalid_parameter_value=2, resource_does_not_exist=3)[source]

Bases: object

Definitions for error codes.

Parameters:
  • internal_error (int)

  • invalid_parameter_value (int)

  • resource_does_not_exist (int)

internal_error: int = 1
invalid_parameter_value: int = 2
resource_does_not_exist: int = 3
exception pyauthorizer.exceptions.PyAuthorizerError(message, error_code=1, **kwargs)[source]

Bases: Exception

Generic exception thrown to surface failure information about external-facing operations.

If the error text is sensitive, raise a generic Exception object instead.

Parameters:
  • message (str) – The message or exception describing the error that occurred. This will be included in the exception’s serialized JSON representation.

  • error_code (int) – An appropriate error code for the error that occurred. It will be included in the exception’s serialized JSON representation.

  • kwargs (Any) – Additional key-value pairs to include in the serialized JSON representation of the PyAuthorizerError.

classmethod invalid_parameter_value(message, **kwargs)[source]

Construct an PyAuthorizerError object with the INVALID_PARAMETER_VALUE error code.

Parameters:
  • message (str) – The message describing the error that occurred. This will be included in the exception’s serialized JSON representation.

  • kwargs (Any) – Additional key-value pairs to include in the serialized JSON representation of the PyAuthorizerError.

Returns:

An instance of PyAuthorizerError with the specified error code.

Return type:

PyAuthorizerError

serialize_as_json()[source]

Serialize the PyAuthorizerError object as JSON.

Returns:

The serialized JSON representation of the PyAuthorizerError object.

Return type:

str