mirror of
https://github.com/status-im/spiffworkflow-connector.git
synced 2025-02-23 12:08:13 +00:00
Accept task data, pass to connectors (#8)
* Add task_data param * Missed passed one param
This commit is contained in:
parent
c94230ce27
commit
276aa4c34d
5
app.py
5
app.py
@ -125,8 +125,11 @@ def do_command(plugin_display_name, command_name):
|
|||||||
)
|
)
|
||||||
|
|
||||||
params = request.args.to_dict()
|
params = request.args.to_dict()
|
||||||
|
raw_task_data = params.pop('spiff__task_data', '{}')
|
||||||
|
task_data = json.loads(raw_task_data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = command(**params).execute(app.config)
|
result = command(**params).execute(app.config, task_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return json_error_response(
|
return json_error_response(
|
||||||
f"Error encountered when executing {plugin_display_name}:{command_name} {str(e)}",
|
f"Error encountered when executing {plugin_display_name}:{command_name} {str(e)}",
|
||||||
|
@ -29,7 +29,7 @@ class AddDynamoItem:
|
|||||||
self.table = self.dynamodb.Table(table_name)
|
self.table = self.dynamodb.Table(table_name)
|
||||||
self.item_data = json.loads(item_data)
|
self.item_data = json.loads(item_data)
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
result = self.table.put_item(Item=self.item_data)
|
result = self.table.put_item(Item=self.item_data)
|
||||||
if "ResponseMetadata" in result:
|
if "ResponseMetadata" in result:
|
||||||
|
@ -19,7 +19,7 @@ class QueryDynamoTable:
|
|||||||
self.table = self.dynamodb.Table(table_name)
|
self.table = self.dynamodb.Table(table_name)
|
||||||
self.key = key
|
self.key = key
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
result = self.table.get_item(Key={"primaryKeyName": self.key})
|
result = self.table.get_item(Key={"primaryKeyName": self.key})
|
||||||
if "ResponseMetadata" in result:
|
if "ResponseMetadata" in result:
|
||||||
|
@ -17,7 +17,7 @@ class ScanDynamoTable:
|
|||||||
self.dynamodb = SimpleAuth("dynamodb", access_key, secret_key).get_resource()
|
self.dynamodb = SimpleAuth("dynamodb", access_key, secret_key).get_resource()
|
||||||
self.table = self.dynamodb.Table(table_name)
|
self.table = self.dynamodb.Table(table_name)
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
result = self.table.scan()
|
result = self.table.scan()
|
||||||
if "ResponseMetadata" in result:
|
if "ResponseMetadata" in result:
|
||||||
|
@ -28,7 +28,7 @@ class UploadFileData:
|
|||||||
self.bucket = bucket
|
self.bucket = bucket
|
||||||
self.object_name = object_name
|
self.object_name = object_name
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
# Upload the file
|
# Upload the file
|
||||||
try:
|
try:
|
||||||
|
@ -22,7 +22,7 @@ class GetPayRate:
|
|||||||
"""__init__."""
|
"""__init__."""
|
||||||
self.employee_id = employee_id
|
self.employee_id = employee_id
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
api_key = config["BAMBOOHR_API_KEY"]
|
api_key = config["BAMBOOHR_API_KEY"]
|
||||||
subdomain = config["BAMBOOHR_SUBDOMAIN"]
|
subdomain = config["BAMBOOHR_SUBDOMAIN"]
|
||||||
|
@ -15,16 +15,10 @@ class CreatePDF:
|
|||||||
"""__init__."""
|
"""__init__."""
|
||||||
self.template = template
|
self.template = template
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
|
|
||||||
# TODO this will be provided in an upcoming pr
|
|
||||||
task_data = {
|
|
||||||
"name": "Bob",
|
|
||||||
"amount": "123",
|
|
||||||
}
|
|
||||||
|
|
||||||
html_string = markdown(self.template)
|
html_string = markdown(self.template)
|
||||||
html_template = Environment(loader=BaseLoader, autoescape=True).from_string(
|
html_template = Environment(loader=BaseLoader, autoescape=True).from_string(
|
||||||
html_string
|
html_string
|
||||||
@ -55,13 +49,13 @@ class CreatePDFAndUploadToS3:
|
|||||||
self.template = template
|
self.template = template
|
||||||
self.aws_object_name = aws_object_name
|
self.aws_object_name = aws_object_name
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
aws_access_key_id = config["AWS_ACCESS_KEY_ID"]
|
aws_access_key_id = config["AWS_ACCESS_KEY_ID"]
|
||||||
aws_secret_access_key = config["AWS_SECRET_ACCESS_KEY"]
|
aws_secret_access_key = config["AWS_SECRET_ACCESS_KEY"]
|
||||||
aws_bucket = config["AWS_INVOICE_S3_BUCKET"]
|
aws_bucket = config["AWS_INVOICE_S3_BUCKET"]
|
||||||
|
|
||||||
pdf_result = CreatePDF(self.template).execute(config)
|
pdf_result = CreatePDF(self.template).execute(config, task_data)
|
||||||
|
|
||||||
if pdf_result["status"] != "200":
|
if pdf_result["status"] != "200":
|
||||||
return {
|
return {
|
||||||
@ -76,7 +70,7 @@ class CreatePDFAndUploadToS3:
|
|||||||
pdf_result["response"],
|
pdf_result["response"],
|
||||||
aws_bucket,
|
aws_bucket,
|
||||||
self.aws_object_name,
|
self.aws_object_name,
|
||||||
).execute(config)
|
).execute(config, task_data)
|
||||||
|
|
||||||
if aws_result["status"] != "200":
|
if aws_result["status"] != "200":
|
||||||
return aws_result
|
return aws_result
|
||||||
|
@ -14,7 +14,7 @@ class SendMessage:
|
|||||||
message_type: str
|
message_type: str
|
||||||
recipient: str
|
recipient: str
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Execute."""
|
"""Execute."""
|
||||||
url = f'{current_app.config["WAKU_PROXY_BASE_URL"]}/sendMessage'
|
url = f'{current_app.config["WAKU_PROXY_BASE_URL"]}/sendMessage'
|
||||||
headers = {"Accept": "application/json", "Content-type": "application/json"}
|
headers = {"Accept": "application/json", "Content-type": "application/json"}
|
||||||
|
@ -159,7 +159,7 @@ class CreateInvoice:
|
|||||||
self.contact_email = contact_email
|
self.contact_email = contact_email
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
|
|
||||||
def execute(self, config):
|
def execute(self, config, task_data):
|
||||||
"""Creates an invoice in xero."""
|
"""Creates an invoice in xero."""
|
||||||
client_id = config["XERO_CLIENT_ID"]
|
client_id = config["XERO_CLIENT_ID"]
|
||||||
client_secret = config["XERO_CLIENT_SECRET"]
|
client_secret = config["XERO_CLIENT_SECRET"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user