-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide diagram cache to sessions
- Loading branch information
1 parent
9176abe
commit f87b175
Showing
5 changed files
with
111 additions
and
20 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
backend/capellacollab/projects/toolmodels/diagrams/core.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import datetime | ||
import logging | ||
|
||
import requests | ||
from sqlalchemy import orm | ||
|
||
from capellacollab.configuration.app import config | ||
from capellacollab.projects.toolmodels.modelsources.git import ( | ||
models as git_models, | ||
) | ||
from capellacollab.projects.toolmodels.modelsources.git.handler import ( | ||
factory as git_handler_factory, | ||
) | ||
from capellacollab.projects.toolmodels.modelsources.git.handler import ( | ||
handler as git_handler, | ||
) | ||
|
||
from . import exceptions | ||
|
||
|
||
async def fetch_diagram_cache_metadata( | ||
logger: logging.LoggerAdapter, handler: git_handler.GitHandler | ||
) -> tuple[str | None, datetime.datetime, bytes]: | ||
try: | ||
return await handler.get_file_or_artifact( | ||
trusted_file_path="diagram_cache/index.json", | ||
logger=logger, | ||
job_name="update_capella_diagram_cache", | ||
file_revision=f"diagram-cache/{handler.revision}", | ||
) | ||
except requests.HTTPError as e: | ||
logger.info( | ||
"Failed fetching diagram metadata file or artifact for %s", | ||
handler.path, | ||
exc_info=True, | ||
) | ||
raise exceptions.DiagramCacheNotConfiguredProperlyError() from e | ||
|
||
|
||
async def build_diagram_cache_api_url( | ||
logger: logging.LoggerAdapter, | ||
git_repository: git_models.DatabaseGitModel, | ||
db: orm.Session, | ||
) -> str: | ||
handler = await git_handler_factory.GitHandlerFactory.create_git_handler( | ||
db, git_repository | ||
) | ||
(job_id, _, _) = await fetch_diagram_cache_metadata(logger, handler) | ||
|
||
if (config.general.scheme == "http" and config.general.port == 80) or ( | ||
config.general.scheme == "https" and config.general.port == 443 | ||
): | ||
base_path = f"{config.general.scheme}://{config.general.host}" | ||
else: | ||
base_path = f"{config.general.scheme}://{config.general.host}:{config.general.port}" | ||
|
||
job_id_query = f"?job_id={job_id}" if job_id else "" | ||
return f"{base_path}/api/v1/projects/{git_repository.model.project.slug}/models/{git_repository.model.slug}/diagrams/%s{job_id_query}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters