merged in main and resolved conflicts
This commit is contained in:
commit
508f99000a
|
@ -95,7 +95,7 @@ python-versions = ">=3.5"
|
|||
dev = ["cloudpickle", "coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy (>=0.900,!=0.940)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "sphinx", "sphinx-notfound-page", "zope.interface"]
|
||||
docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"]
|
||||
tests = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "zope.interface"]
|
||||
tests_no_zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins"]
|
||||
tests-no-zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins"]
|
||||
|
||||
[[package]]
|
||||
name = "Babel"
|
||||
|
@ -268,7 +268,7 @@ optional = false
|
|||
python-versions = ">=3.6.0"
|
||||
|
||||
[package.extras]
|
||||
unicode_backport = ["unicodedata2"]
|
||||
unicode-backport = ["unicodedata2"]
|
||||
|
||||
[[package]]
|
||||
name = "classify-imports"
|
||||
|
@ -1512,7 +1512,7 @@ urllib3 = ">=1.21.1,<1.27"
|
|||
|
||||
[package.extras]
|
||||
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
||||
use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"]
|
||||
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
||||
|
||||
[[package]]
|
||||
name = "requests-toolbelt"
|
||||
|
@ -1625,7 +1625,7 @@ falcon = ["falcon (>=1.4)"]
|
|||
fastapi = ["fastapi (>=0.79.0)"]
|
||||
flask = ["blinker (>=1.1)", "flask (>=0.11)"]
|
||||
httpx = ["httpx (>=0.16.0)"]
|
||||
pure_eval = ["asttokens", "executing", "pure-eval"]
|
||||
pure-eval = ["asttokens", "executing", "pure-eval"]
|
||||
pyspark = ["pyspark (>=2.4.4)"]
|
||||
quart = ["blinker (>=1.1)", "quart (>=0.16.1)"]
|
||||
rq = ["rq (>=0.6)"]
|
||||
|
@ -1884,19 +1884,19 @@ aiomysql = ["aiomysql", "greenlet (!=0.4.17)"]
|
|||
aiosqlite = ["aiosqlite", "greenlet (!=0.4.17)", "typing_extensions (!=3.10.0.1)"]
|
||||
asyncio = ["greenlet (!=0.4.17)"]
|
||||
asyncmy = ["asyncmy (>=0.2.3,!=0.2.4)", "greenlet (!=0.4.17)"]
|
||||
mariadb_connector = ["mariadb (>=1.0.1,!=1.1.2)"]
|
||||
mariadb-connector = ["mariadb (>=1.0.1,!=1.1.2)"]
|
||||
mssql = ["pyodbc"]
|
||||
mssql_pymssql = ["pymssql"]
|
||||
mssql_pyodbc = ["pyodbc"]
|
||||
mssql-pymssql = ["pymssql"]
|
||||
mssql-pyodbc = ["pyodbc"]
|
||||
mypy = ["mypy (>=0.910)", "sqlalchemy2-stubs"]
|
||||
mysql = ["mysqlclient (>=1.4.0)", "mysqlclient (>=1.4.0,<2)"]
|
||||
mysql_connector = ["mysql-connector-python"]
|
||||
mysql-connector = ["mysql-connector-python"]
|
||||
oracle = ["cx_oracle (>=7)", "cx_oracle (>=7,<8)"]
|
||||
postgresql = ["psycopg2 (>=2.7)"]
|
||||
postgresql_asyncpg = ["asyncpg", "greenlet (!=0.4.17)"]
|
||||
postgresql_pg8000 = ["pg8000 (>=1.16.6,!=1.29.0)"]
|
||||
postgresql_psycopg2binary = ["psycopg2-binary"]
|
||||
postgresql_psycopg2cffi = ["psycopg2cffi"]
|
||||
postgresql-asyncpg = ["asyncpg", "greenlet (!=0.4.17)"]
|
||||
postgresql-pg8000 = ["pg8000 (>=1.16.6,!=1.29.0)"]
|
||||
postgresql-psycopg2binary = ["psycopg2-binary"]
|
||||
postgresql-psycopg2cffi = ["psycopg2cffi"]
|
||||
pymysql = ["pymysql", "pymysql (<1)"]
|
||||
sqlcipher = ["sqlcipher3_binary"]
|
||||
|
||||
|
|
|
@ -111,4 +111,29 @@ def create_app() -> flask.app.Flask:
|
|||
if app.config["PROCESS_WAITING_MESSAGES"]:
|
||||
start_scheduler(app)
|
||||
|
||||
configure_sentry(app)
|
||||
|
||||
return app # type: ignore
|
||||
|
||||
|
||||
def configure_sentry(app: flask.app.Flask) -> None:
|
||||
"""Configure_sentry."""
|
||||
import sentry_sdk
|
||||
from flask import Flask
|
||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
|
||||
sentry_sample_rate = app.config.get("SENTRY_SAMPLE_RATE")
|
||||
if sentry_sample_rate is None:
|
||||
return
|
||||
sentry_sdk.init(
|
||||
dsn=app.config.get("SENTRY_DSN"),
|
||||
integrations=[
|
||||
FlaskIntegration(),
|
||||
],
|
||||
# Set traces_sample_rate to 1.0 to capture 100%
|
||||
# of transactions for performance monitoring.
|
||||
# We recommend adjusting this value in production.
|
||||
traces_sample_rate=float(sentry_sample_rate),
|
||||
)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
|
|
@ -45,3 +45,7 @@ CONNECTOR_PROXY_URL = environ.get(
|
|||
SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME = environ.get(
|
||||
"SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME"
|
||||
)
|
||||
|
||||
# Sentry Configuration
|
||||
SENTRY_DSN = environ.get("SENTRY_DSN", default="")
|
||||
SENTRY_SAMPLE_RATE = environ.get("SENTRY_SAMPLE_RATE", default="1.0")
|
||||
|
|
|
@ -76,7 +76,7 @@ from spiffworkflow_backend.models.user import UserModelSchema
|
|||
from spiffworkflow_backend.scripts.script import Script
|
||||
from spiffworkflow_backend.services.file_system_service import FileSystemService
|
||||
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
||||
from spiffworkflow_backend.services.service_task_service import ServiceTaskService
|
||||
from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate
|
||||
from spiffworkflow_backend.services.spec_file_service import SpecFileService
|
||||
from spiffworkflow_backend.services.user_service import UserService
|
||||
|
||||
|
@ -169,9 +169,16 @@ class CustomBpmnScriptEngine(PythonScriptEngine): # type: ignore
|
|||
except Exception as e:
|
||||
raise WorkflowTaskExecException(task, f" {script}, {e}", e) from e
|
||||
|
||||
def available_service_task_external_methods(self) -> Dict[str, Any]:
|
||||
"""Returns available service task external methods."""
|
||||
return ServiceTaskService.scripting_additions()
|
||||
def call_service(
|
||||
self,
|
||||
operation_name: str,
|
||||
operation_params: Dict[str, Any],
|
||||
task_data: Dict[str, Any],
|
||||
) -> Any:
|
||||
"""CallService."""
|
||||
return ServiceTaskDelegate.call_connector(
|
||||
operation_name, operation_params, task_data
|
||||
)
|
||||
|
||||
|
||||
class MyCustomParser(BpmnDmnParser): # type: ignore
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"""ServiceTask_service."""
|
||||
import json
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
|
||||
import requests
|
||||
from flask import current_app
|
||||
|
||||
from spiffworkflow_backend.services.file_system_service import FileSystemService
|
||||
from spiffworkflow_backend.services.secret_service import SecretService
|
||||
|
||||
|
||||
|
@ -20,23 +20,34 @@ class ServiceTaskDelegate:
|
|||
@staticmethod
|
||||
def normalize_value(value: Any) -> Any:
|
||||
"""Normalize_value."""
|
||||
secret_prefix = "secret:" # noqa: S105
|
||||
if isinstance(value, dict):
|
||||
value = json.dumps(value)
|
||||
|
||||
secret_prefix = "secret:" # noqa: S105
|
||||
if value.startswith(secret_prefix):
|
||||
key = value.removeprefix(secret_prefix)
|
||||
secret = SecretService().get_secret(key)
|
||||
assert secret # noqa: S101
|
||||
value = secret.value
|
||||
return secret.value
|
||||
|
||||
file_prefix = "file:"
|
||||
if value.startswith(file_prefix):
|
||||
file_name = value.removeprefix(file_prefix)
|
||||
full_path = FileSystemService.full_path_from_relative_path(file_name)
|
||||
with open(full_path) as f:
|
||||
return f.read()
|
||||
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def call_connector(name: str, bpmn_params: Any) -> str:
|
||||
def call_connector(name: str, bpmn_params: Any, task_data: Any) -> str:
|
||||
"""Calls a connector via the configured proxy."""
|
||||
params = {
|
||||
k: ServiceTaskDelegate.normalize_value(v["value"])
|
||||
for k, v in bpmn_params.items()
|
||||
}
|
||||
params["spiff__task_data"] = json.dumps(task_data)
|
||||
|
||||
proxied_response = requests.get(f"{connector_proxy_url()}/v1/do/{name}", params)
|
||||
|
||||
if proxied_response.status_code != 200:
|
||||
|
@ -52,7 +63,6 @@ class ServiceTaskService:
|
|||
def available_connectors() -> Any:
|
||||
"""Returns a list of available connectors."""
|
||||
try:
|
||||
print(connector_proxy_url)
|
||||
response = requests.get(f"{connector_proxy_url()}/v1/commands")
|
||||
|
||||
if response.status_code != 200:
|
||||
|
@ -63,8 +73,3 @@ class ServiceTaskService:
|
|||
except Exception as e:
|
||||
print(e)
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def scripting_additions() -> Dict[str, Any]:
|
||||
"""Allows the ServiceTaskDelegate to be available to script engine instances."""
|
||||
return {"ServiceTaskDelegate": ServiceTaskDelegate}
|
||||
|
|
Loading…
Reference in New Issue