SAM Broker
Smarter API SmarterAuthToken Manifest handler.
- class smarter.lib.drf.manifest.brokers.auth_token.SAMSmarterAuthTokenBroker(*args, **kwargs)[source]
Bases:
AbstractBrokerSmarter API SmarterAuthToken Manifest Broker.
This class is responsible for - loading, validating and parsing the Smarter Api yaml SmarterAuthToken manifests - using the manifest to initialize the corresponding Pydantic model
This Broker class interacts with the collection of Django ORM models that represent the Smarter API SAMSmarterAuthToken manifests. The Broker class is responsible for creating, updating, deleting and querying the Django ORM models, as well as transforming the Django ORM models into Pydantic models for serialization and deserialization.
- property ORMMetaModelClass: Type[SmarterAuthToken]
Return the Django ORM meta model class for the broker.
- Returns:
The Django ORM meta model class definition for the broker.
- Return type:
Type[SmarterAuthToken]
- property ORMModelClass: Type[SmarterAuthToken]
Return the Django ORM model class for the broker.
- Returns:
The Django ORM model class definition for the broker.
- Return type:
- property SerializerClass: Type[ModelSerializer]
Return the Serializer class for the SmarterAuthToken model.
This is used to serialize and deserialize the SmarterAuthToken model for API responses and requests.
- __init__(*args, **kwargs)[source]
Initialize the SAMSmarterAuthTokenBroker with the given arguments.
The constructor initializes the parent class and sets up the manifest and user attributes.
- apply(request, *args, **kwargs)[source]
Apply the manifest.
copy the manifest data to the Django ORM model and save the model to the database. Call super().apply() to ensure that the manifest is loaded and validated before applying the manifest to the Django ORM model. Note that there are fields included in the manifest that are not editable and are therefore removed from the Django ORM model dict prior to attempting the save() command. These fields are defined in the readonly_fields list.
- Return type:
- cache_invalidations()[source]
Invalidate any relevant caches when the manifest or SmarterAuthToken data changes.
- Return type:
- delete(request, *args, **kwargs)[source]
Delete a resource.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the delete operation.
- Return type:
- deploy(request, *args, **kwargs)[source]
Deploy a resource.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the deploy operation.
- Return type:
- describe(request, *args, **kwargs)[source]
Describe a resource.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the description of the resource.
- Return type:
- django_orm_to_manifest_dict()[source]
Transform the Django ORM model into a Pydantic readable.
Smarter API SAMSmarterAuthToken manifest dict.
- Return type:
- example_manifest(request, *args, **kwargs)[source]
Returns an example yaml manifest document for the kind of resource.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the example manifest.
- Return type:
- property formatted_class_name: str
Returns the formatted class name for logging purposes.
This is used to provide a more readable class name in logs.
- get(request, *args, **kwargs)[source]
Get information about specified resources.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the get operation.
- Return type:
- logs(request, *args, **kwargs)[source]
Get logs for a resource.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the logs for the resource.
- Return type:
- property manifest: SAMSmarterAuthToken | None
SAMSmarterAuthToken() is a Pydantic model.
that is used to represent the Smarter API SAMSmarterAuthToken manifest. The Pydantic model is initialized with the data from the manifest loader, which is generally passed to the model constructor as **data. However, this top-level manifest model has to be explicitly initialized, whereas its child models are automatically cascade-initialized by the Pydantic model, implicitly passing **data to each child’s constructor.
- manifest_to_django_orm()[source]
Transform the Smarter API SAMSmarterAuthToken manifest into a Django ORM model.
- property orm_instance: SmarterAuthToken | None
Return the Django ORM model instance for the broker.
- Returns:
The Django ORM model instance for the broker.
- Return type:
Optional[TimestampedModel]
- orm_meta_instance_setter()[source]
Override the base method to initialize the ORM meta model for the broker.
- Return type:
- prompt(request, *args, **kwargs)[source]
Invoke a prompt operation.
This abstract method should be implemented by subclasses to provide prompt-based interactions with the broker resource.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the prompt response.
- Return type:
- property smarter_auth_token: SmarterAuthToken | None
The SmarterAuthToken object is a Django ORM model subclass from knox.AuthToken.
that represents a SmarterAuthToken api key. The SmarterAuthToken object is used to store the authentication hash and Smarter metadata for the Smarter API. The SmarterAuthToken object is retrieved from the database, if it exists, or created from the manifest if it does not.
- property token_key: str | None
The token_key is the actual API key that is used to authenticate with the Smarter API.
The token_key is generated by the SmarterAuthToken object when it is created and it is only available immediately after the object is created.
- undeploy(request, *args, **kwargs)[source]
Undeploy a resource.
- Parameters:
request (
ASGIRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the undeploy operation.
- Return type:
- exception smarter.lib.drf.manifest.brokers.auth_token.SAMSmarterAuthTokenBrokerError(message=None, thing=None, command=None, stack_trace=None)[source]
Bases:
SAMBrokerErrorBase exception for Smarter API SmarterAuthToken Broker handling.
- property get_formatted_err_message