mirror of
https://github.com/sartography/spiffworkflow-backend.git
synced 2025-02-23 12:58:13 +00:00
wildcard environment support
This commit is contained in:
parent
7c01d37f50
commit
c8d2b64ce1
@ -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.environment.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)
|
||||
|
@ -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 = (
|
||||
|
@ -0,0 +1,17 @@
|
||||
"""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…
x
Reference in New Issue
Block a user