SAMJournal

class smarter.lib.journal.models.SAMJournal(*args, **kwargs)[source]

Bases: Model

Model representing a journal entry for changes made to the SAM database.

This model is used to maintain a comprehensive log of all modifications performed on the SAM database, whether those changes are initiated via the API (api/v1) or through CLI manifests. Each journal entry records the details of the operation, including the user responsible, the type of entity affected, the command executed, the request and response payloads, and the resulting status code.

Examples

Creating a new journal entry:

entry = SAMJournal(
    user=request.user,
    thing=SmarterJournalThings.CHAT.value,
    command=SmarterJournalCliCommands.CREATE.value,
    request={"data": "example"},
    response={"result": "success"},
    status_code=201
)
entry.save()

See also

smarter.common.utils.hash_factory

Utility function used to generate unique keys for journal entries.

smarter.lib.journal.enum.SmarterJournalCliCommands

Enumeration of valid CLI commands for journal entries.

smarter.lib.journal.enum.SmarterJournalThings

Enumeration of valid entity types for journal entries.

param key:

Primary key: Key

type key:

Unknown

param created_at:

Created at

type created_at:

Unknown

param thing:

Thing

type thing:

Unknown

param command:

Command

type command:

Unknown

param request:

Request

type request:

Unknown

param response:

Response

type response:

Unknown

param status_code:

Status code

type status_code:

Unknown

Relationship fields:

param user:

User (related name: samjournal)

type user:

Unknown

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

command

CharField

Command

Choices:

  • apply

  • prompt

  • chat_config

  • delete

  • deploy

  • describe

  • get

  • journal

  • logs

  • example_manifest

  • and 5 more

Type:

Type

created_at

DateTimeField

Created at

Type:

Type

get_command_display(*, field=<django.db.models.CharField: command>)

Shows the label of the command. See get_FOO_display() for more information.

get_thing_display(*, field=<django.db.models.CharField: thing>)

Shows the label of the thing. See get_FOO_display() for more information.

key

CharField

Primary key: Key

Type:

Type

objects = <django.db.models.Manager object>
request

JSONField

Request

Type:

Type

response

JSONField

Response

Type:

Type

save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

status_code

PositiveSmallIntegerField

Status code

Type:

Type

thing

CharField

Thing

Choices:

  • Plugin

  • ApiPlugin

  • SqlPlugin

  • ApiConnection

  • SqlConnection

  • Account

  • SmarterAuthToken

  • User

  • Prompt

  • ChatConfig

  • and 7 more

Type:

Type

user

ForeignKey to User

User (related name: samjournal)

Type:

Type

user_id

Internal field, use user instead.