Squashed 'spiffworkflow-backend/' changes from 7c01d37f5..e7af92d97
e7af92d97 pyl w/ burnettk a57134009 updated development perm yml to work with mvp process model w/ burnettk 496c13120 Merge pull request #163 from sartography/feature/fewer-sentry-traces 1f5e1638c Merge pull request #162 from sartography/feature/support-wildcard-envs c9c7f9d6f fewer sentry traces 3b3315857 lint c8d2b64ce wildcard environment support git-subtree-dir: spiffworkflow-backend git-subtree-split: e7af92d979fbb7f90ba662f012baa17422146cd1
This commit is contained in:
parent
b1722ee29d
commit
b9d7ded29b
|
@ -157,18 +157,26 @@ def configure_sentry(app: flask.app.Flask) -> None:
|
|||
return None
|
||||
return event
|
||||
|
||||
sentry_sample_rate = app.config.get("SENTRY_SAMPLE_RATE")
|
||||
if sentry_sample_rate is None:
|
||||
return
|
||||
sentry_errors_sample_rate = app.config.get("SENTRY_ERRORS_SAMPLE_RATE")
|
||||
if sentry_errors_sample_rate is None:
|
||||
raise Exception("SENTRY_ERRORS_SAMPLE_RATE is not set somehow")
|
||||
|
||||
sentry_traces_sample_rate = app.config.get("SENTRY_TRACES_SAMPLE_RATE")
|
||||
if sentry_traces_sample_rate is None:
|
||||
raise Exception("SENTRY_TRACES_SAMPLE_RATE is not set somehow")
|
||||
|
||||
sentry_sdk.init(
|
||||
dsn=app.config.get("SENTRY_DSN"),
|
||||
integrations=[
|
||||
FlaskIntegration(),
|
||||
],
|
||||
environment=app.config["ENV_IDENTIFIER"],
|
||||
# Set traces_sample_rate to 1.0 to capture 100%
|
||||
# sample_rate is the errors sample rate. we usually set it to 1 (100%)
|
||||
# so we get all errors in sentry.
|
||||
sample_rate=float(sentry_errors_sample_rate),
|
||||
# Set traces_sample_rate to capture a certain percentage
|
||||
# of transactions for performance monitoring.
|
||||
# We recommend adjusting this value in production.
|
||||
traces_sample_rate=float(sentry_sample_rate),
|
||||
# We recommend adjusting this value to less than 1(00%) in production.
|
||||
traces_sample_rate=float(sentry_traces_sample_rate),
|
||||
before_send=before_send,
|
||||
)
|
||||
|
|
|
@ -54,13 +54,20 @@ def setup_config(app: Flask) -> None:
|
|||
else:
|
||||
app.config.from_pyfile(f"{app.instance_path}/config.py", silent=True)
|
||||
|
||||
env_config_module = "spiffworkflow_backend.config." + app.config["ENV_IDENTIFIER"]
|
||||
env_config_prefix = "spiffworkflow_backend.config."
|
||||
env_config_module = env_config_prefix + app.config["ENV_IDENTIFIER"]
|
||||
try:
|
||||
app.config.from_object(env_config_module)
|
||||
except ImportStringError as exception:
|
||||
raise ModuleNotFoundError(
|
||||
f"Cannot find config module: {env_config_module}"
|
||||
) from exception
|
||||
if (
|
||||
os.environ.get("TERRAFORM_DEPLOYED_ENVIRONMENT") == "true"
|
||||
and os.environ.get("SPIFFWORKFLOW_BACKEND_ENV") is not None
|
||||
):
|
||||
app.config.from_object("{env_config_prefix}terraform_deployed_environment")
|
||||
else:
|
||||
raise ModuleNotFoundError(
|
||||
f"Cannot find config module: {env_config_module}"
|
||||
) from exception
|
||||
|
||||
setup_database_uri(app)
|
||||
setup_logger(app)
|
||||
|
|
|
@ -47,7 +47,12 @@ SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME = environ.get(
|
|||
|
||||
# Sentry Configuration
|
||||
SENTRY_DSN = environ.get("SENTRY_DSN", default="")
|
||||
SENTRY_SAMPLE_RATE = environ.get("SENTRY_SAMPLE_RATE", default="1.0")
|
||||
SENTRY_ERRORS_SAMPLE_RATE = environ.get(
|
||||
"SENTRY_ERRORS_SAMPLE_RATE", default="1"
|
||||
) # send all errors
|
||||
SENTRY_TRACES_SAMPLE_RATE = environ.get(
|
||||
"SENTRY_TRACES_SAMPLE_RATE", default="0.01"
|
||||
) # send 1% of traces
|
||||
|
||||
SPIFFWORKFLOW_BACKEND_LOG_LEVEL = environ.get(
|
||||
"SPIFFWORKFLOW_BACKEND_LOG_LEVEL", default="info"
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
"""Staging."""
|
||||
"""Demo environment."""
|
||||
from os import environ
|
||||
|
||||
GIT_COMMIT_ON_SAVE = True
|
||||
GIT_COMMIT_USERNAME = "demo"
|
||||
GIT_COMMIT_EMAIL = "demo@example.com"
|
||||
SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME = environ.get(
|
||||
"SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME", default="demo.yml"
|
||||
"SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME",
|
||||
default="terraform_deployed_environment.yml",
|
||||
)
|
||||
|
||||
RUN_BACKGROUND_SCHEDULER = (
|
||||
|
|
|
@ -23,6 +23,21 @@ groups:
|
|||
Finance Team:
|
||||
users: [finance_user1]
|
||||
|
||||
Project Lead:
|
||||
users:
|
||||
[
|
||||
jakub,
|
||||
alex,
|
||||
dan,
|
||||
mike,
|
||||
jason,
|
||||
jarrad,
|
||||
elizabeth,
|
||||
jon,
|
||||
natalia,
|
||||
manuchehr,
|
||||
]
|
||||
|
||||
permissions:
|
||||
admin:
|
||||
groups: [admin]
|
||||
|
@ -50,7 +65,7 @@ permissions:
|
|||
uri: /v1.0/process-models/finance/*
|
||||
|
||||
read-all:
|
||||
groups: [finance, admin]
|
||||
groups: [finance, admin, "Project Lead"]
|
||||
users: []
|
||||
allowed_permissions: [read]
|
||||
uri: /*
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
"""Terraform-deployed environment."""
|
||||
from os import environ
|
||||
|
||||
# default.py already ensured that this key existed as was not None
|
||||
environment_identifier_for_this_config_file_only = environ["SPIFFWORKFLOW_BACKEND_ENV"]
|
||||
|
||||
GIT_COMMIT_ON_SAVE = True
|
||||
GIT_COMMIT_USERNAME = environment_identifier_for_this_config_file_only
|
||||
GIT_COMMIT_EMAIL = f"{environment_identifier_for_this_config_file_only}@example.com"
|
||||
SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME = environ.get(
|
||||
"SPIFFWORKFLOW_BACKEND_PERMISSIONS_FILE_NAME", default="terraform_deployed_environment.yml"
|
||||
)
|
||||
|
||||
RUN_BACKGROUND_SCHEDULER = (
|
||||
environ.get("RUN_BACKGROUND_SCHEDULER", default="false") == "true"
|
||||
)
|
|
@ -1,21 +1,22 @@
|
|||
from flask_bpmn.api.api_error import ApiError
|
||||
|
||||
from spiffworkflow_backend.scripts.script import Script
|
||||
|
||||
"""Get_localtime."""
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
|
||||
import pytz
|
||||
from flask_bpmn.api.api_error import ApiError
|
||||
from SpiffWorkflow.task import Task as SpiffTask # type: ignore
|
||||
|
||||
from spiffworkflow_backend.scripts.script import Script
|
||||
|
||||
|
||||
class GetLocaltime(Script):
|
||||
"""GetLocaltime."""
|
||||
|
||||
def get_description(self) -> str:
|
||||
"""Get_description."""
|
||||
return """Converts a Datetime object into a Datetime object for a specific timezone.
|
||||
Defaults to US/Eastern"""
|
||||
Defaults to US/Eastern."""
|
||||
|
||||
def run(
|
||||
self,
|
||||
|
@ -24,20 +25,23 @@ class GetLocaltime(Script):
|
|||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> datetime:
|
||||
if len(args) > 0 or 'datetime' in kwargs:
|
||||
if 'datetime' in kwargs:
|
||||
date_time = kwargs['datetime']
|
||||
"""Run."""
|
||||
if len(args) > 0 or "datetime" in kwargs:
|
||||
if "datetime" in kwargs:
|
||||
date_time = kwargs["datetime"]
|
||||
else:
|
||||
date_time = args[0]
|
||||
if 'timezone' in kwargs:
|
||||
timezone = kwargs['timezone']
|
||||
if "timezone" in kwargs:
|
||||
timezone = kwargs["timezone"]
|
||||
elif len(args) > 1:
|
||||
timezone = args[1]
|
||||
else:
|
||||
timezone = 'US/Eastern'
|
||||
timezone = "US/Eastern"
|
||||
localtime: datetime = date_time.astimezone(pytz.timezone(timezone))
|
||||
return localtime
|
||||
|
||||
else:
|
||||
raise ApiError(error_code='missing_datetime',
|
||||
message='You must include a datetime to convert.')
|
||||
raise ApiError(
|
||||
error_code="missing_datetime",
|
||||
message="You must include a datetime to convert.",
|
||||
)
|
||||
|
|
|
@ -2,19 +2,12 @@
|
|||
"title": "Get Timezone",
|
||||
"description": "Form to select a timezone.",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"timezone"
|
||||
],
|
||||
"required": ["timezone"],
|
||||
"properties": {
|
||||
"timezone": {
|
||||
"type": "string",
|
||||
"title": "Timezone",
|
||||
"enum": [
|
||||
"US/Eastern",
|
||||
"US/Pacific",
|
||||
"Europe/Berlin",
|
||||
"Australia/ACT"
|
||||
]
|
||||
"enum": ["US/Eastern", "US/Pacific", "Europe/Berlin", "Australia/ACT"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,34 @@
|
|||
"""Test_get_localtime."""
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
import pytz
|
||||
from flask.app import Flask
|
||||
from flask.testing import FlaskClient
|
||||
|
||||
from spiffworkflow_backend.scripts.get_localtime import GetLocaltime
|
||||
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
|
||||
from spiffworkflow_backend.services.process_instance_service import ProcessInstanceService
|
||||
|
||||
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
|
||||
|
||||
from spiffworkflow_backend.scripts.get_localtime import GetLocaltime
|
||||
from spiffworkflow_backend.services.process_instance_processor import (
|
||||
ProcessInstanceProcessor,
|
||||
)
|
||||
from spiffworkflow_backend.services.process_instance_service import (
|
||||
ProcessInstanceService,
|
||||
)
|
||||
|
||||
|
||||
class TestGetLocaltime(BaseTest):
|
||||
"""TestProcessAPi."""
|
||||
|
||||
def test_get_localtime_script_directly(self) -> None:
|
||||
"""Test_get_localtime_script_directly."""
|
||||
current_time = datetime.datetime.now()
|
||||
timezone = "US/Pacific"
|
||||
result = GetLocaltime().run(task=None, environment_identifier='testing', datetime=current_time, timezone=timezone)
|
||||
result = GetLocaltime().run(
|
||||
task=None,
|
||||
environment_identifier="testing",
|
||||
datetime=current_time,
|
||||
timezone=timezone,
|
||||
)
|
||||
assert result == current_time.astimezone(pytz.timezone(timezone))
|
||||
|
||||
def test_get_localtime_script_through_bpmn(
|
||||
|
@ -54,8 +64,8 @@ class TestGetLocaltime(BaseTest):
|
|||
|
||||
assert spiff_task
|
||||
data = spiff_task.data
|
||||
some_time = data['some_time']
|
||||
localtime = data['localtime']
|
||||
timezone = data['timezone']
|
||||
some_time = data["some_time"]
|
||||
localtime = data["localtime"]
|
||||
timezone = data["timezone"]
|
||||
|
||||
assert localtime == some_time.astimezone(pytz.timezone(timezone))
|
||||
|
|
Loading…
Reference in New Issue