CRUD
The CRUD methods are used to create, read, update and delete triggers. The syntax is the same for all CRUD methods.
Example:
import digitalhub as dh
# Use CRUD method from SDK
trigger = dh.new_trigger(project="my-project",
name="my-trigger",
kind="scheduler",
task="my-task",
function="my-function")
A trigger entity can be managed with the following methods.
Create:
Read:
Update:
Delete:
Create
You can create a trigger with the new_trigger().
The kwargs parameters are determined by the kind of the object, and are described in the kinds section.
New
This function creates a new entity and saves it into the backend.
new_trigger
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project name. |
required |
name
|
str
|
Object name. |
required |
kind
|
str
|
Kind the object. |
required |
task
|
str
|
Task string. |
required |
function
|
str
|
Function string. |
None
|
workflow
|
str
|
Workflow string. |
None
|
uuid
|
str
|
ID of the object. |
None
|
description
|
str
|
Description of the object (human readable). |
None
|
labels
|
list[str]
|
List of labels. |
None
|
embedded
|
bool
|
Flag to determine if object spec must be embedded in project spec. |
False
|
**kwargs
|
dict
|
Spec keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Trigger
|
Object instance. |
Examples:
Read
To read triggers you can use the get_trigger(), get_trigger_versions(), list_triggers() or import_trigger() functions.
Get
This function searches for a single trigger into the backend.
If you want to collect a trigger from the backend using get_trigger(), you have two options:
- The first one is to use the
keyparameter which has the patternstore://<project-name>/<entity-type>/<entity-kind>/<entity-name>:<entity-id>. - The second one is to use the entity name as
identifier, the project name asprojectand the entity id asentity_idparameters. If you do not specify the entity id, you will get the latest version.
get_trigger
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
Entity key (store://...) or entity name. |
required |
project
|
str
|
Project name. |
None
|
entity_id
|
str
|
Entity ID. |
None
|
Returns:
| Type | Description |
|---|---|
Trigger
|
Object instance. |
Examples:
Using entity key:
Using entity name:
Get versions
This function returns all the versions of a trigger from the backend.
get_trigger_versions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
Entity key (store://...) or entity name. |
required |
project
|
str
|
Project name. |
None
|
Returns:
| Type | Description |
|---|---|
list[Trigger]
|
List of object instances. |
Examples:
Using entity key:
Using entity name:
List
This function returns all the latest triggers from the backend related to a project.
list_triggers
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project name. |
required |
q
|
str
|
Query string to filter objects. |
None
|
name
|
str
|
Object name. |
None
|
kind
|
str
|
Kind of the object. |
None
|
user
|
str
|
User that created the object. |
None
|
state
|
str
|
Object state. |
None
|
created
|
str
|
Creation date filter. |
None
|
updated
|
str
|
Update date filter. |
None
|
versions
|
str
|
Object version, default is latest. |
None
|
task
|
str
|
Task string filter. |
None
|
Returns:
| Type | Description |
|---|---|
list[Trigger]
|
List of object instances. |
Examples:
Import
This function loads the trigger from a local yaml file descriptor.
import_trigger
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Path to the YAML file. |
None
|
key
|
str
|
Entity key (store://...). |
None
|
reset_id
|
bool
|
Flag to determine if the ID of executable entities should be reset. |
False
|
context
|
str
|
Project name to use for context resolution. |
None
|
Returns:
| Type | Description |
|---|---|
Trigger
|
Object instance. |
Examples:
Update
To update a trigger you can use the update_trigger() method.
Delete
To delete a trigger you can use the delete_trigger() method.
delete_trigger
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
Entity key (store://...) or entity name. |
required |
project
|
str
|
Project name. |
None
|
entity_id
|
str
|
Entity ID. |
None
|
delete_all_versions
|
bool
|
Delete all versions of the named entity. If True, use entity name instead of entity key as identifier. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Response from backend. |
Examples:
If delete_all_versions is False:
Otherwise: