Secret
Smarter API User Manifest handler
- class smarter.apps.account.manifest.brokers.secret.SAMSecretBroker(*args, **kwargs)[source]
Bases:
AbstractBrokerSmarter API Secret Manifest Broker
This class manages the lifecycle of Smarter API Secret manifests, including loading, validating, parsing, and transforming them between Django ORM models and Pydantic models for serialization and deserialization.
Responsibilities:
Load, validate, and parse Smarter API YAML Secret manifests.
Initialize the corresponding Pydantic model from manifest data.
Interact with Django ORM models representing Secret manifests.
Create, update, delete, and query Secret ORM models.
Transform ORM models into Pydantic models for API serialization.
Parameters:
manifest (Optional[Union[SAMSecret, str, dict]]): The manifest data, which can be a SAMSecret instance, a YAML/JSON string, or a dictionary.
Example Usage:
broker = SAMSecretBroker(manifest=manifest_data) manifest_model = broker.manifest if manifest_model: print(manifest_model.spec.config)
Note
The manifest can be provided as a string, dictionary, or SAMSecret instance. If not a SAMSecret, it will be loaded and validated automatically.
See also
SAMSecretSAMSecretMetadataSAMSecretSpecSAMLoader()
- property ORMMetaModelClass: Type[Secret]
Return the Django ORM meta model class for the broker.
- Returns:
The Django ORM meta model class definition for the broker.
- Return type:
Type[Secret]
- property ORMModelClass: Type[Secret]
Return the Django ORM model class for Smarter API Secret.
- Returns:
Type[Secret] The Django ORM model class.
Example usage:
broker = SAMSecretBroker(manifest=manifest_data) model_cls = broker.ORMModelClass secret_instance = model_cls.objects.get(name="my_secret")
- property SAMModelClass: Type[SAMSecret]
Return the Pydantic model class for the broker.
- Returns:
The Pydantic model class definition for the broker.
- Return type:
Type[SAMSecret]
- property SerializerClass: Type[SecretSerializer]
Return the Django REST Framework serializer class for Smarter API Secret.
- Returns:
Type[SecretSerializer] The serializer class.
Example usage:
broker = SAMSecretBroker(manifest=manifest_data) serializer_cls = broker.SerializerClass serializer = serializer_cls(instance=secret_instance)
- __init__(*args, **kwargs)[source]
Initialize the SAMSecretBroker instance.
This constructor initializes the broker by calling the parent class’s constructor, which will attempt to bootstrap the class instance with any combination of raw manifest data (in JSON or YAML format), a manifest loader, or existing Django ORM models. If a manifest loader is provided and its kind matches the expected kind for this broker, the manifest is initialized using the loader’s data.
This class can bootstrap itself in any of the following ways:
request.body (yaml or json string)
name + account (determined via authentication of the request object)
SAMLoader instance
manifest instance
filepath to a manifest file
If raw manifest data is provided, whether as a string or a dictionary, or a SAMLoader instance, the base class constructor will only goes as far as initializing the loader. The actual manifest model initialization is deferred to this constructor, which checks the loader’s kind.
- Parameters:
args – Positional arguments passed to the parent constructor.
kwargs – Keyword arguments passed to the parent constructor.
Example:
broker = SAMSecretBroker(loader=loader, plugin_meta=plugin_meta)
- apply(request, *args, **kwargs)[source]
Apply the manifest by copying its data to the Django ORM model and saving it to the database.
This method ensures the manifest is loaded and validated before persisting it. Non-editable fields defined in readonly_fields are excluded from the ORM model prior to saving.
Note
tags are handled separately because they are of type TaggableManager and require a different method to set them.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Return type:
- Returns:
SmarterJournaledJsonResponse A JSON response indicating success or error.
Caution
Fields marked as read-only in the manifest will be removed before saving to prevent accidental overwrites.
Example usage:
response = broker.apply(request) if response.success: print("Secret applied successfully.")
- chat(request, *args, **kwargs)[source]
Attention
this is not implemented for Smarter API Secret manifests.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Raises:
SAMBrokerErrorNotImplemented – Always raised to indicate that chat functionality is not available for this manifest type.
- Return type:
- Returns:
SmarterJournaledJsonResponse This method does not return a response; it always raises an error.
- delete(request, *args, **kwargs)[source]
Delete the Smarter API Secret manifest from the database.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Raises:
SAMSecretBrokerError – If there is an error during manifest deletion.
- Return type:
- Returns:
SmarterJournaledJsonResponse A JSON response indicating success or error.
- deploy(request, *args, **kwargs)[source]
Attention
this is not implemented for Smarter API Secret manifests.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Raises:
SAMBrokerErrorNotImplemented – Always raised to indicate that deploy functionality is not available for this manifest type.
- Return type:
- describe(request, *args, **kwargs)[source]
Describe the Smarter API Secret manifest by retrieving its details from the database.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Raises:
SAMSecretBrokerError – If there is an error during manifest retrieval or serialization.
- Return type:
- Returns:
SmarterJournaledJsonResponse A JSON response containing the manifest details.
- django_orm_to_manifest_dict()[source]
Convert a Django ORM Secret model instance into a Pydantic-compatible manifest dictionary.
This method serializes the ORM model, transforms its keys to camelCase, and structures the output for use as a Smarter API Secret manifest.
- Return type:
- Returns:
Optional[dict] A dictionary formatted for Pydantic model consumption, or None if the secret is unavailable.
Important
The returned dictionary is suitable for API responses, configuration export, or further Pydantic validation.
Warning
If the underlying secret does not exist, this method returns None and logs a warning.
Example usage:
manifest_dict = broker.django_orm_to_manifest_dict() if manifest_dict: print(manifest_dict["spec"]["config"]["value"])
See also
Secretmanifest_to_django_orm()SAMSecretSAMSecretMetadataKeysSAMSecretSpecKeysSAMSecretStatusKeysSAMKeys
- example_manifest(request, *args, **kwargs)[source]
Return an example Smarter API Secret manifest.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Return type:
- Returns:
SmarterJournaledJsonResponse A JSON response containing the example manifest.
Example usage:
response = broker.example_manifest(request) print(response.data)
- property formatted_class_name: str
Get a human-readable class name for logging and diagnostics.
This property returns a formatted string representing the class name, which is useful for log messages and debugging output.
- Returns:
str The formatted class name.
Example usage:
logger.debug(broker.formatted_class_name)
- get(request, *args, **kwargs)[source]
Retrieve Smarter API Secret manifests based on query parameters.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Raises:
SAMSecretBrokerError – If there is an error during manifest retrieval or serialization.
- Return type:
- Returns:
SmarterJournaledJsonResponse A JSON response containing the retrieved manifests.
See also:
:class:`Secret` :class:`smarter.apps.account.serializers.SecretSerializer` :class:`SAMKeys` :class:`SCLIResponseGet` :class:`SCLIResponseGetData`
- property kind: str
Return the manifest kind for Smarter API Secret.
- Returns:
str The manifest kind string.
Example usage:
broker = SAMSecretBroker(manifest=manifest_data) print(broker.kind) # Output "Secret"
- logs(request, *args, **kwargs)[source]
Attention
this is not implemented for Smarter API Secret manifests.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Raises:
SAMBrokerErrorNotImplemented – Always raised to indicate that logs functionality is not available for this manifest type.
- Return type:
- property manifest: SAMSecret | None
Return the Pydantic model representing the Smarter API Secret manifest.
The SAMSecret Pydantic model is initialized with manifest data, typically loaded via the manifest loader and passed as keyword arguments. While the top-level manifest model must be explicitly initialized, its child models are automatically cascade-initialized by Pydantic, with their respective data passed implicitly.
- Returns:
Optional[SAMSecret] The initialized manifest model, or None if not available.
Tip
Use this property to access the validated manifest as a Pydantic object for further processing or serialization.
Example usage:
broker = SAMSecretBroker(manifest=manifest_data) manifest_model = broker.manifest if manifest_model: print(manifest_model.spec.config)
See also
SAMSecretSAMSecretMetadataSAMSecretSpecSAMLoader()
- manifest_to_django_orm()[source]
Convert the Smarter API Secret manifest into a Django ORM model dictionary.
This method serializes the manifest’s configuration data, converting camelCase keys to snake_case for compatibility with Django ORM conventions.
- Return type:
- Returns:
Optional[dict] A dictionary suitable for creating or updating a Django ORM Secret model, or None if the manifest is unavailable.
Important
The returned dictionary is intended for direct use with Django ORM operations. Ensure that required fields are present before saving.
Example usage:
orm_data = broker.manifest_to_django_orm() if orm_data: secret_obj = Secret.objects.create(**orm_data)
See also
- property name: str | None
Get the name of the Smarter API Account.
- Returns:
The name of the Smarter API Account, or None if not set.
- Return type:
Optional[str]
- property ready: bool
Check if the broker is ready for operations.
This property determines whether the broker has been properly initialized and is ready to perform its functions. A broker is considered ready if it has a valid manifest loaded, either from raw data, a loader, or existing Django ORM models.
- Returns:
Trueif the broker is ready,Falseotherwise.- Return type:
- property secret: Secret | None
Retrieve the Django ORM Secret model instance associated with this manifest.
This property provides direct access to the underlying Secret object, allowing you to interact with its fields and methods.
- Returns:
Optional[Secret] The corresponding Django ORM model instance, or None if unavailable.
Important
The returned object reflects the current state of the manifest in the database. If the manifest has not been applied or the secret does not exist, this property will return None.
Example usage:
secret_obj = broker.secret if secret_obj: print(secret_obj.get_secret()) print(secret_obj.expires_at)
See also
Secretsecret_transformer()
- property secret_transformer: SecretTransformer | None
Get the SecretTransformer instance associated with this manifest.
The SecretTransformer provides methods for creating, saving, and accessing the Django ORM Secret model based on the manifest data.
- Returns:
SecretTransformer The transformer for this manifest.
Important
The user_profile must be set before accessing this property, or an error will be raised.
Example usage:
transformer = broker.secret_transformer if transformer.ready: transformer.save()
See also
SecretTransformer
- undeploy(request, *args, **kwargs)[source]
Attention
this is not implemented for Smarter API Secret manifests.
- Parameters:
request (
HttpRequest) – “HttpRequest” The incoming HTTP request.args – tuple Additional positional arguments.
kwargs – dict Additional keyword arguments.
- Raises:
SAMBrokerErrorNotImplemented – Always raised to indicate that undeploy functionality is not available for this manifest type.
- Return type:
- exception smarter.apps.account.manifest.brokers.secret.SAMSecretBrokerError(message=None, thing=None, command=None, stack_trace=None)[source]
Bases:
SAMBrokerErrorBase exception for Smarter API Secret Broker handling.
- property get_formatted_err_message