api module reference
AuthorizedTasks
Stores the function object of functions decorated by the @authorized_task decorator at self.list.
Source code in api/resources/auth.py
register_task(func)
Registers a function in the AuthorizedTasks.list dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
function
|
the function to be registered. |
required |
Source code in api/resources/auth.py
authorized_task(task_func)
Decorator for functions which require authentication by JWT. When the @authorized_task is placed, it will register the decorated function in the AuthorizedTasks function list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_func |
function
|
the decorated function |
required |
Returns:
Name | Type | Description |
---|---|---|
wrapper | a function that returns the original task_func function. |
Source code in api/resources/auth.py
generate_new_jwt(payload)
Generates a new JWT token containing a payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload |
dict
|
A dictionary with the data that will be placed inside the JWT token. |
required |
Returns:
Name | Type | Description |
---|---|---|
jwt_token |
str
|
the generated JWT token |
Source code in api/resources/auth.py
get_user_permissions(user, password)
Gets user allowed task names by credentials passed. It's possible to customize this function for the needs of your project. We discourage to use hardcoded values for credentials or permissions here. It is strongly recommended to hash your credentials with bcrypt and store them in a database. By default, all users have test.main.myProtectedTask as an allowed task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
str
|
user identifier credential |
required |
password |
str
|
password credential |
required |
Returns:
Name | Type | Description |
---|---|---|
payload |
dict
|
dictionary with user's allowed tasks. |
Source code in api/resources/auth.py
verify_credentials(user, password)
A function that verifies if the credentials are correct. It's possible to customize this function for the needs of your project. We discourage to use hardcoded values for credentials here. It is strongly recommended to hash your credentials with bcrypt and store them in a database. By default, the correct credentials are user="testuser" and password="testpass"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
str
|
user identifier credential |
required |
password |
str
|
password credential |
required |
Returns:
Name | Type | Description |
---|---|---|
isVerified |
boolean
|
true if credentials are correct, otherwise, false. |
Source code in api/resources/auth.py
NewTask
Bases: Resource
Registers a new task request through POST method.
Source code in api/resources/web.py
post()
Posts a task
Returns:
Name | Type | Description |
---|---|---|
taskInfo |
dict
|
dictionary with the task id, arguments passed and current status of the task. |