workflows.models ================ .. py:module:: workflows.models .. autoapi-nested-parse:: Workflow models: definitions, scopes, instances, and enrollment requests. Module Contents --------------- .. py:class:: State(*args, **kwds) Bases: :py:obj:`django.db.models.TextChoices` Workflow and enrollment states. .. py:attribute:: RUNNING :value: ('Running', 'Running') .. py:attribute:: AWAITING :value: ('AwaitingApproval', 'AwaitingApproval') .. py:attribute:: APPROVED :value: ('Approved', 'Approved') .. py:attribute:: PASSED :value: ('Passed', 'Passed') .. py:attribute:: FINALIZED :value: ('Finalized', 'Finalized') .. py:attribute:: REJECTED :value: ('Rejected', 'Rejected') .. py:attribute:: FAILED :value: ('Failed', 'Failed') .. py:attribute:: ABORTED :value: ('Aborted', 'Aborted') .. py:data:: StatusBadge Tuple of (label, bootstrap_badge_class). .. py:data:: BADGE_MAP :type: dict[str, StatusBadge] .. py:function:: get_status_badge(raw) Return a badge (label, CSS class) for a workflow/enrollment state. .. py:class:: WorkflowDefinition(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Blueprint of a workflow: event, steps, transitions. .. py:attribute:: id .. py:attribute:: name .. py:attribute:: version .. py:attribute:: published .. py:attribute:: definition .. py:attribute:: created_at .. py:attribute:: updated_at .. py:class:: Meta Database configuration for workflow definitions. .. py:attribute:: db_table :value: 'workflow_definitions' .. py:attribute:: ordering :value: ('-created_at',) .. py:class:: WorkflowScope(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Assign a workflow to CAs, domains, or devices (NULL = any). .. py:attribute:: id .. py:attribute:: workflow .. py:attribute:: ca_id .. py:attribute:: domain_id .. py:attribute:: device_id .. py:class:: Meta Database configuration for Workflow Scope. .. py:attribute:: db_table :value: 'workflow_scopes' .. py:attribute:: unique_together :value: (('workflow', 'ca_id', 'domain_id', 'device_id'),) .. py:class:: DeviceRequest(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` Represents a device lifecycle request (creation, deletion, onboarding). .. attribute:: id UUID primary key. .. attribute:: device Target device. .. attribute:: domain Domain at the time of event (may be null). .. attribute:: ca CA for domain (if applicable). .. attribute:: action Device action type ("created", "onboarded", "deleted"). .. attribute:: payload Raw event payload from the handler. .. attribute:: aggregated_state Aggregate state over all workflow instances. .. attribute:: finalized True if all workflow instances have reached terminal states. .. attribute:: created_at Request creation timestamp. .. attribute:: updated_at Last update timestamp. .. py:attribute:: id .. py:attribute:: device .. py:attribute:: domain .. py:attribute:: ca .. py:attribute:: action .. py:attribute:: payload .. py:attribute:: aggregated_state .. py:attribute:: finalized .. py:attribute:: created_at .. py:attribute:: updated_at .. py:class:: Meta Database configuration for device workflow parent. .. py:attribute:: ordering :value: ('-created_at',) .. py:method:: recompute_and_save() Recompute the aggregate final state from instances. .. py:property:: badge_class :type: str Return the CSS class for the aggregated state badge. .. py:class:: EnrollmentRequest(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` A single logical certificate enrollment attempt (EST simpleenroll fan-out parent). - Aggregates all child WorkflowInstances that must approve/reject this attempt. - Identity tuple groups repeated polls for the same CSR until a terminal outcome. - We keep request-level states distinct from instance-level strings to avoid confusion. .. py:attribute:: id .. py:attribute:: protocol .. py:attribute:: operation .. py:attribute:: device .. py:attribute:: domain .. py:attribute:: ca .. py:attribute:: fingerprint .. py:attribute:: template .. py:attribute:: aggregated_state .. py:attribute:: finalized .. py:attribute:: created_at .. py:attribute:: updated_at .. py:class:: Meta Database configuration for enrollment request. .. py:attribute:: db_table :value: 'enrollment_requests' .. py:attribute:: indexes .. py:property:: badge_label :type: str Return the human-readable badge label for the aggregated state. .. py:property:: badge_class :type: str Return the CSS class for the aggregated state badge. .. py:method:: recompute_status() Compute aggregate status from child instances. :returns: The new aggregated state derived from child instance states. .. py:method:: is_valid() Return True if the enrollment request is in a successful terminal state. .. py:method:: recompute_and_save() Recalculate the aggregated state and persist changes if it changed. :returns: The (possibly unchanged) aggregated state. .. py:method:: finalize(final_status = None) Finalize this request and all non-finalized child workflow instances. :param final_status: Optional final aggregated state to set for the request. .. py:method:: abort() Abort this request and all non-finalized child workflow instances. .. py:class:: WorkflowInstance(*args, **kwargs) Bases: :py:obj:`django.db.models.Model` An initialized workflows. .. py:attribute:: id .. py:attribute:: definition .. py:attribute:: enrollment_request .. py:attribute:: device_request .. py:attribute:: current_step .. py:attribute:: state .. py:attribute:: payload .. py:attribute:: step_contexts .. py:attribute:: finalized .. py:attribute:: created_at .. py:attribute:: updated_at .. py:class:: Meta Database configuration and indexes for workflow instances. .. py:attribute:: db_table :value: 'workflow_instances' .. py:attribute:: indexes .. py:property:: badge_label :type: str Return the human-readable badge label for this instance's state. .. py:property:: badge_class :type: str Return the CSS class for this instance's state badge. .. py:method:: finalize(state = None) Mark this instance as fully done and optionally set a final state. :param state: Optional final state to set before marking as finalized. .. py:method:: get_steps() Return the ordered list of steps from the workflow definition. :returns: List of step dictionaries from the workflow definition JSON. .. py:method:: get_current_step_index() Return the index of ``self.current_step`` in the steps list, or raise. .. py:method:: get_next_step() Return the step-ID of the next step, or None if at the end. :returns: Step ID string of the next step, or None if there is no next step. .. py:method:: is_last_approval_step() Return True if the current step is the last Approval step in the workflow.