Skip to content

Commit

Permalink
refactor: restructure and cleanup core blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Jan 3, 2024
1 parent 7ba4edf commit 60741af
Show file tree
Hide file tree
Showing 80 changed files with 72 additions and 164 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ FROM base as development
RUN poetry install
COPY /src/.behaverc ./src/.behaverc
COPY src ./src
RUN chown -R 1000:1000 /code/src/home/system/data_sources/system.json
RUN chown -R 1000:1000 /code/src/system_DS.json
USER 1000

FROM base as prod
RUN poetry install --no-dev
COPY src ./src
RUN chown -R 1000:1000 /code/src/home/system/data_sources/system.json
RUN chown -R 1000:1000 /code/src/system_DS.json
USER 1000
1 change: 1 addition & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
volumes:
- ./src:/code/src
environment:
SECRET_KEY: sg9aeUM5i1JO4gNN8fQadokJa3_gXQMLBjSGGYcfscs= # Don't reuse this in production...
ENVIRONMENT: local
LOGGING_LEVEL: debug
# MONGO_URI: ${MONGO_URI}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "dmss://system/SIMOS/RecipeLink",
"_blueprintPath_": "dmss://system/SIMOS/blob_types/PDF",
"_blueprintPath_": "dmss://system/SIMOS/PDF",
"extends": [
"dmss://system/SIMOS/NamedEntity",
"_default_"
Expand Down
6 changes: 2 additions & 4 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,12 @@ def init_application():
}
)
import_package(
f"{config.APPLICATION_HOME}/system/SIMOS",
"/code/src/SIMOS",
user,
data_source_name=config.CORE_DATA_SOURCE,
is_root=True,
)
create_lookup_table_use_case(["system/SIMOS/recipe_links"], "DMSS", user)
logger.debug("DONE")


@cli.command()
Expand Down Expand Up @@ -207,7 +206,6 @@ def nuke_db():
mongo_client[db_name][collection].delete_many({})
blob_handler = gridfs.GridFS(mongo_client[db_name])
for filename in blob_handler.list():
print(filename)
blob_handler.delete(filename)
logger.debug("DONE")

Expand All @@ -217,7 +215,7 @@ def nuke_db():
def reset_app(context):
context.invoke(nuke_db)
logger.info("CREATING SYSTEM DATA SOURCE")
context.invoke(import_data_source, file="/code/src/home/system/data_sources/system.json")
context.invoke(import_data_source, file="/code/src/system_DS.json")
logger.debug("DONE")
context.invoke(init_application)

Expand Down
3 changes: 0 additions & 3 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

from pydantic import BaseSettings, Field

from enums import AuthProviderForRoleCheck
Expand All @@ -15,7 +13,6 @@ class Config(BaseSettings):
MAX_ENTITY_RECURSION_DEPTH: int = Field(50, env="MAX_ENTITY_RECURSION_DEPTH")
CORE_DATA_SOURCE: str = "system"
CACHE_MAX_SIZE: int = 200
APPLICATION_HOME: str = Field(f"{Path(__file__).parent!s}/home", env="APPLICATION_HOME")
# Access Control
DMSS_ADMIN: str = Field("dmss-admin", env="DMSS_ADMIN")
DMSS_ADMIN_ROLE: str = Field("dmss-admin", env="DMSS_ADMIN_ROLE")
Expand Down
2 changes: 1 addition & 1 deletion src/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SIMOS(Enum):
NAMED_ENTITY = "dmss://system/SIMOS/NamedEntity"
PACKAGE = "dmss://system/SIMOS/Package"
BLUEPRINT_ATTRIBUTE = "dmss://system/SIMOS/BlueprintAttribute"
ATTRIBUTE_TYPES = "dmss://system/SIMOS/AttributeTypes"
ATTRIBUTE_TYPES = "dmss://system/SIMOS/enums/AttributeTypes"
BLOB = "dmss://system/SIMOS/Blob"
RECIPE_LINK = "dmss://system/SIMOS/RecipeLink"
DATASOURCE = "datasource"
Expand Down
39 changes: 0 additions & 39 deletions src/home/system/SIMOS/Action.json

This file was deleted.

15 changes: 0 additions & 15 deletions src/home/system/SIMOS/Annotation.json

This file was deleted.

15 changes: 0 additions & 15 deletions src/home/system/data_sources/azure.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ echo -e "########### VERSION ##########\n"

if [ "$1" = 'api' ]; then
if [ "${DATA_SOURCE_FILES:-""}" != "" ]; then
echo "$DATA_SOURCE_FILES" > /code/src/home/system/data_sources/system.json
echo "$DATA_SOURCE_FILES" > /code/src/system_DS.json
fi

if [ "${RESET_DATA_SOURCE:-"on"}" == "on" ]; then
Expand Down
16 changes: 0 additions & 16 deletions src/reset-database.sh

This file was deleted.

6 changes: 3 additions & 3 deletions src/storage/repositories/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class LocalFileRepository(RepositoryInterface):
def __init__(self, location: str | Path | None = None):
if location is None:
location = f"{Path(__file__).parent.parent.parent!s}/home/"
location = f"{Path(__file__).parent.parent.parent}/SIMOS"
self.path = Path(location)

def get(self, absolute_ref: str) -> dict:
try:
protocol, address = absolute_ref.split("://", 1)
with open(f"{self.path}/{address}.json") as f:
path_to_json = absolute_ref.replace("dmss://system/SIMOS/", "")
with open(f"{self.path}/{path_to_json}.json") as f:
return json.load(f)
except FileNotFoundError as ex:
raise FileNotFoundError(
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions src/tests/bdd/document/add_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ Feature: Explorer - Add file
},
{
"name": "a_pdf",
"attributeType": "dmss://system/SIMOS/blob_types/PDF",
"attributeType": "dmss://system/SIMOS/PDF",
"type": "dmss://system/SIMOS/BlueprintAttribute"
},
{
"name": "another_pdf",
"attributeType": "dmss://system/SIMOS/blob_types/PDF",
"attributeType": "dmss://system/SIMOS/PDF",
"type": "dmss://system/SIMOS/BlueprintAttribute"
},
{
Expand Down Expand Up @@ -707,7 +707,7 @@ Feature: Explorer - Add file
"a_pdf": {
"name": "MyPDF1",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file1",
"type": "dmss://system/SIMOS/Blob"
Expand All @@ -717,7 +717,7 @@ Feature: Explorer - Add file
"another_pdf": {
"name": "MyPDF2",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file2",
"type": "dmss://system/SIMOS/Blob"
Expand All @@ -731,7 +731,7 @@ Feature: Explorer - Add file
"a_pdf": {
"name": "MyPDF3",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file3",
"type": "dmss://system/SIMOS/Blob"
Expand All @@ -741,7 +741,7 @@ Feature: Explorer - Add file
"another_pdf": {
"name": "MyPDF4",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file4",
"type": "dmss://system/SIMOS/Blob",
Expand Down
12 changes: 6 additions & 6 deletions src/tests/bdd/document/update_with_blob.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ Feature: Update document that has blob data
"attributes": [
{
"name": "a_pdf",
"attributeType": "dmss://system/SIMOS/blob_types/PDF",
"attributeType": "dmss://system/SIMOS/PDF",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"optional": true
},
{
"name": "another_pdf",
"attributeType": "dmss://system/SIMOS/blob_types/PDF",
"attributeType": "dmss://system/SIMOS/PDF",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"optional": true
},
Expand Down Expand Up @@ -84,7 +84,7 @@ Feature: Update document that has blob data
"a_pdf": {
"name": "MyPDF1",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file1",
"type": "dmss://system/SIMOS/Blob",
Expand All @@ -95,7 +95,7 @@ Feature: Update document that has blob data
"another_pdf": {
"name": "MyPDF2",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file2",
"type": "dmss://system/SIMOS/Blob",
Expand All @@ -110,7 +110,7 @@ Feature: Update document that has blob data
"a_pdf": {
"name": "MyPDF3",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file3",
"type": "dmss://system/SIMOS/Blob",
Expand All @@ -121,7 +121,7 @@ Feature: Update document that has blob data
"another_pdf": {
"name": "MyPDF4",
"description": "",
"type": "dmss://system/SIMOS/blob_types/PDF",
"type": "dmss://system/SIMOS/PDF",
"blob": {
"name": "file4",
"type": "dmss://system/SIMOS/Blob",
Expand Down
2 changes: 1 addition & 1 deletion src/tests/bdd/steps/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def step_impl(context):
logger_level_before = logger.level
logger.setLevel("ERROR")
import_package(
f"{config.APPLICATION_HOME}/system/SIMOS",
"SIMOS",
context.user,
is_root=True,
data_source_name="system",
Expand Down
6 changes: 3 additions & 3 deletions src/tests/unit/authentication/test_pat_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from datetime import datetime
from datetime import UTC, datetime
from uuid import UUID

from authentication.models import AccessLevel, PATData
Expand Down Expand Up @@ -29,7 +29,7 @@ def test_dict(self):
user_id="user1",
roles=["role1", "role2"],
scope=AccessLevel.READ,
expire=datetime.utcnow(),
expire=datetime.now(UTC),
)
as_dict = pat_data.dict()
self.assertEqual(as_dict["_id"], "hash123")
Expand All @@ -38,7 +38,7 @@ def test_dict(self):
self.assertEqual(as_dict["scope"], AccessLevel.READ)

def test_uuid_default(self):
pat_data = PATData(user_id="user1", scope=AccessLevel.WRITE, expire=datetime.utcnow())
pat_data = PATData(user_id="user1", scope=AccessLevel.WRITE, expire=datetime.now(UTC))

self.assertIsInstance(pat_data.uuid, str)
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CarRental",
"type": "system/SIMOS/Blueprint",
"type": "dmss://system/SIMOS/Blueprint",
"extends": [
"dmss://system/SIMOS/NamedEntity"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CarTest",
"type": "system/SIMOS/Blueprint",
"type": "dmss://system/SIMOS/Blueprint",
"extends": [
"dmss://system/SIMOS/NamedEntity"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EngineTest",
"type": "system/SIMOS/Blueprint",
"type": "dmss://system/SIMOS/Blueprint",
"description": "This describes an engine",
"extends": [
"dmss://system/SIMOS/NamedEntity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FuelPumpTest",
"type": "system/SIMOS/Blueprint",
"type": "dmss://system/SIMOS/Blueprint",
"description": "This describes a fuel pump",
"extends": [
"dmss://system/SIMOS/NamedEntity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RentalCar",
"type": "system/SIMOS/Blueprint",
"type": "dmss://system/SIMOS/Blueprint",
"extends": [
"dmss://system/SIMOS/NamedEntity"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WheelTest",
"type": "system/SIMOS/Blueprint",
"type": "dmss://system/SIMOS/Blueprint",
"extends": [
"dmss://system/SIMOS/NamedEntity"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Blueprint4",
"type": "system/SIMOS/Blueprint",
"type": "dmss://system/SIMOS/Blueprint",
"description": "Second blueprint",
"extends": [
"dmss://system/SIMOS/NamedEntity"
Expand Down
Loading

0 comments on commit 60741af

Please sign in to comment.