Accept task data, pass to connectors (#8)

* Add task_data param

* Missed passed one param
This commit is contained in:
jbirddog 2022-10-10 13:46:35 -04:00 committed by GitHub
parent c94230ce27
commit 276aa4c34d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 18 deletions

5
app.py
View File

@ -125,8 +125,11 @@ def do_command(plugin_display_name, command_name):
)
params = request.args.to_dict()
raw_task_data = params.pop('spiff__task_data', '{}')
task_data = json.loads(raw_task_data)
try:
result = command(**params).execute(app.config)
result = command(**params).execute(app.config, task_data)
except Exception as e:
return json_error_response(
f"Error encountered when executing {plugin_display_name}:{command_name} {str(e)}",

View File

@ -29,7 +29,7 @@ class AddDynamoItem:
self.table = self.dynamodb.Table(table_name)
self.item_data = json.loads(item_data)
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
result = self.table.put_item(Item=self.item_data)
if "ResponseMetadata" in result:

View File

@ -19,7 +19,7 @@ class QueryDynamoTable:
self.table = self.dynamodb.Table(table_name)
self.key = key
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
result = self.table.get_item(Key={"primaryKeyName": self.key})
if "ResponseMetadata" in result:

View File

@ -17,7 +17,7 @@ class ScanDynamoTable:
self.dynamodb = SimpleAuth("dynamodb", access_key, secret_key).get_resource()
self.table = self.dynamodb.Table(table_name)
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
result = self.table.scan()
if "ResponseMetadata" in result:

View File

@ -28,7 +28,7 @@ class UploadFileData:
self.bucket = bucket
self.object_name = object_name
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
# Upload the file
try:

View File

@ -22,7 +22,7 @@ class GetPayRate:
"""__init__."""
self.employee_id = employee_id
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
api_key = config["BAMBOOHR_API_KEY"]
subdomain = config["BAMBOOHR_SUBDOMAIN"]

View File

@ -15,16 +15,10 @@ class CreatePDF:
"""__init__."""
self.template = template
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
buf = BytesIO()
# TODO this will be provided in an upcoming pr
task_data = {
"name": "Bob",
"amount": "123",
}
html_string = markdown(self.template)
html_template = Environment(loader=BaseLoader, autoescape=True).from_string(
html_string
@ -55,13 +49,13 @@ class CreatePDFAndUploadToS3:
self.template = template
self.aws_object_name = aws_object_name
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
aws_access_key_id = config["AWS_ACCESS_KEY_ID"]
aws_secret_access_key = config["AWS_SECRET_ACCESS_KEY"]
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":
return {
@ -76,7 +70,7 @@ class CreatePDFAndUploadToS3:
pdf_result["response"],
aws_bucket,
self.aws_object_name,
).execute(config)
).execute(config, task_data)
if aws_result["status"] != "200":
return aws_result

View File

@ -14,7 +14,7 @@ class SendMessage:
message_type: str
recipient: str
def execute(self, config):
def execute(self, config, task_data):
"""Execute."""
url = f'{current_app.config["WAKU_PROXY_BASE_URL"]}/sendMessage'
headers = {"Accept": "application/json", "Content-type": "application/json"}

View File

@ -159,7 +159,7 @@ class CreateInvoice:
self.contact_email = contact_email
self.amount = amount
def execute(self, config):
def execute(self, config, task_data):
"""Creates an invoice in xero."""
client_id = config["XERO_CLIENT_ID"]
client_secret = config["XERO_CLIENT_SECRET"]