Skip to content

Commit

Permalink
Merge pull request #802 from DSD-DBS/feat-add-t4c-http-ws-port
Browse files Browse the repository at this point in the history
Feat add t4c http ws port
  • Loading branch information
MoritzWeber0 authored Jul 3, 2023
2 parents 776fd09 + 202447b commit 1607d35
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 179 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ certs/*
/node_modules
.idea
.vscode
/backend/log/*
/helm/charts/*
/logs/*
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ config/*
build
.git_archival.txt
logs
backend.log*

htmlcov
.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
# SPDX-License-Identifier: Apache-2.0

"""Add http port to t4c instance
Revision ID: 3442c1b545e3
Revises: c6d27bd8cf6e
Create Date: 2023-06-26 17:04:34.613373
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "3442c1b545e3"
down_revision = "c6d27bd8cf6e"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"t4c_instances", sa.Column("http_port", sa.Integer(), nullable=True)
)
37 changes: 24 additions & 13 deletions backend/capellacollab/projects/toolmodels/backups/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@


def get_environment(
gitmodel: git_models.DatabaseGitModel,
t4cmodel: t4c_models.DatabaseT4CModel,
git_model: git_models.DatabaseGitModel,
t4c_model: t4c_models.DatabaseT4CModel,
t4c_username: str,
t4c_password: str,
include_commit_history: bool = False,
) -> dict[str, str]:
return {
"GIT_REPO_URL": gitmodel.path,
"GIT_REPO_BRANCH": gitmodel.revision,
"GIT_USERNAME": gitmodel.username,
"GIT_PASSWORD": gitmodel.password,
"T4C_REPO_HOST": t4cmodel.repository.instance.host,
"T4C_REPO_PORT": str(t4cmodel.repository.instance.port),
"T4C_CDO_PORT": str(t4cmodel.repository.instance.cdo_port),
"T4C_REPO_NAME": t4cmodel.repository.name,
"T4C_PROJECT_NAME": t4cmodel.name,
env = {
"GIT_REPO_URL": git_model.path,
"GIT_REPO_BRANCH": git_model.revision,
"GIT_USERNAME": git_model.username,
"GIT_PASSWORD": git_model.password,
"T4C_REPO_HOST": t4c_model.repository.instance.host,
"T4C_REPO_PORT": str(t4c_model.repository.instance.port),
"T4C_REPO_NAME": t4c_model.repository.name,
"T4C_PROJECT_NAME": t4c_model.name,
"T4C_USERNAME": t4c_username,
"T4C_PASSWORD": t4c_password,
"LOG_LEVEL": "INFO",
"INCLUDE_COMMIT_HISTORY": json.dumps(include_commit_history),
"CONNECTION_TYPE": "telnet",
}

if http_port := t4c_model.repository.instance.http_port:
env |= {
"HTTP_LOGIN": t4c_model.repository.instance.username,
"HTTP_PASSWORD": t4c_model.repository.instance.password,
"HTTP_PORT": str(http_port),
}
else:
env |= env | {
"T4C_CDO_PORT": str(t4c_model.repository.instance.cdo_port)
}

return env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from capellacollab.projects.toolmodels.backups import models as backups_models

from . import crud
from . import crud, models


def get_existing_pipeline_run(
Expand All @@ -20,7 +20,7 @@ def get_existing_pipeline_run(
backups_injectables.get_existing_pipeline
),
db: orm.Session = fastapi.Depends(database.get_db),
) -> backups_models.DatabaseBackup:
) -> models.DatabasePipelineRun:
if pipeline_run := crud.get_pipeline_run_by_id(db, pipeline_run_id):
if pipeline_run.pipeline.id != pipeline.id:
raise fastapi.HTTPException(
Expand Down
15 changes: 8 additions & 7 deletions backend/capellacollab/projects/toolmodels/backups/runs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def get_pipeline_runs(
response_model=models.PipelineRun,
)
def get_pipeline_run(
pipeline_run: pipeline_models.DatabaseBackup = fastapi.Depends(
pipeline_run: models.DatabasePipelineRun = fastapi.Depends(
injectables.get_existing_pipeline_run
),
) -> list[models.DatabasePipelineRun]:
) -> models.DatabasePipelineRun:
print(pipeline_run.status)
return pipeline_run


Expand Down Expand Up @@ -126,10 +127,7 @@ def _transform_unix_nanoseconds_to_human_readable_format(
)


@router.get(
"/{pipeline_run_id}/logs",
response_model=str,
)
@router.get("/{pipeline_run_id}/logs", response_model=str)
def get_logs(
pipeline_run: models.DatabasePipelineRun = fastapi.Depends(
injectables.get_existing_pipeline_run
Expand All @@ -155,7 +153,10 @@ def get_logs(
]
)

masked_values = [pipeline_run.pipeline.t4c_password]
masked_values = [
pipeline_run.pipeline.t4c_password,
pipeline_run.pipeline.t4c_model.repository.instance.password,
]
masked_values_generated = []

# Also mask derivated, e.g. base64 encoded credentials
Expand Down
4 changes: 3 additions & 1 deletion backend/capellacollab/sessions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ def start_persistent_guacamole_session(
{
"repository": repository.name,
"protocol": repository.instance.protocol,
"port": repository.instance.port,
"port": repository.instance.http_port
if repository.instance.protocol == "ws"
else repository.instance.port,
"host": repository.instance.host,
"instance": repository.instance.name,
}
Expand Down
13 changes: 13 additions & 0 deletions backend/capellacollab/settings/modelsources/t4c/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class DatabaseT4CInstance(database.Base):
sa.CheckConstraint("cdo_port >= 0 AND cdo_port <= 65535"),
default=12036,
)
http_port: orm.Mapped[int | None] = orm.mapped_column(
sa.CheckConstraint("http_port >= 0 AND http_port <= 65535"),
)
usage_api: orm.Mapped[str]
rest_api: orm.Mapped[str]
username: orm.Mapped[str]
Expand Down Expand Up @@ -89,6 +92,7 @@ class T4CInstanceBase(pydantic.BaseModel):
host: str
port: int
cdo_port: int
http_port: int | None
usage_api: str
rest_api: str
username: str
Expand All @@ -107,6 +111,10 @@ class T4CInstanceBase(pydantic.BaseModel):
port_validator
)

_validate_http_port = pydantic.validator("http_port", allow_reuse=True)(
port_validator
)

class Config:
orm_mode = True

Expand All @@ -117,6 +125,7 @@ class PatchT4CInstance(pydantic.BaseModel):
host: str | None
port: int | None
cdo_port: int | None
http_port: int | None
usage_api: str | None
rest_api: str | None
username: str | None
Expand All @@ -137,6 +146,10 @@ class PatchT4CInstance(pydantic.BaseModel):
port_validator
)

_validate_http_port = pydantic.validator("http_port", allow_reuse=True)(
port_validator
)

class Config:
orm_mode = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import datetime
import time
from unittest import mock

import pytest
from fastapi import testclient
Expand All @@ -13,7 +14,16 @@
import capellacollab.projects.toolmodels.backups.runs.crud as pipeline_runs_crud
import capellacollab.projects.toolmodels.backups.runs.models as pipeline_runs_models
import capellacollab.projects.toolmodels.models as toolmodels_models
from capellacollab.__main__ import app
from capellacollab.core.logging import loki
from capellacollab.projects.toolmodels.backups.runs import (
injectables as runs_injectables,
)
from capellacollab.projects.toolmodels.backups.runs import (
models as runs_models,
)
from capellacollab.users import crud as users_crud
from capellacollab.users import models as users_models


@pytest.fixture(name="unix_time_in_ns")
Expand Down Expand Up @@ -137,3 +147,70 @@ def def_get_logs(

assert response.status_code == 200
assert b"test3" in response.content


@pytest.fixture(name="mock_pipeline_run")
def fixture_mock_pipeline_run():
mock_pipeline_run = mock.MagicMock(spec=runs_models.DatabasePipelineRun)

# Assign the values you want the mock object to return
mock_pipeline_run.id = "mock_id"
mock_pipeline_run.reference_id = "mock_reference_id"
mock_pipeline_run.trigger_time = "mock_time"

# These values will be masked
mock_pipeline_run.pipeline.t4c_password = "secret_pipeline_t4c_password"
mock_pipeline_run.pipeline.t4c_model.repository.instance.password = (
"secret_t4c_instance_password"
)

return mock_pipeline_run


@pytest.fixture(name="override_get_existing_pipeline_run_dependency")
def fixture_override_get_existing_pipeline_run_dependency(
mock_pipeline_run: mock.Mock,
):
def get_mock_existing_pipeline_run() -> runs_models.DatabasePipelineRun:
return mock_pipeline_run

app.dependency_overrides[
runs_injectables.get_existing_pipeline_run
] = get_mock_existing_pipeline_run

yield

app.dependency_overrides.pop(
runs_injectables.get_existing_pipeline_run, None
)


@mock.patch("capellacollab.core.logging.loki.fetch_logs_from_loki")
@pytest.mark.usefixtures("override_get_existing_pipeline_run_dependency")
def test_mask_logs(
mock_fetch_logs: mock.Mock,
client: testclient.TestClient,
db: orm.Session,
executor_name: str,
):
users_crud.create_user(db, executor_name, users_models.Role.ADMIN)

mock_fetch_logs.return_value = [
{
"values": [
(
1618181583458797952,
"This is a log entry containing a secret_pipeline_t4c_password and secret_t4c_instance_password",
)
]
}
]

response = client.get(
"/api/v1/projects/1/models/1/backups/pipelines/1/runs/1/logs"
)

logs = response.json()

assert "secret_pipeline_t4c_password" not in logs
assert "secret_t4c_instance_password" not in logs
1 change: 1 addition & 0 deletions frontend/src/app/services/settings/t4c-instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type BaseT4CInstance = {
host: string;
port: number;
cdo_port: number;
http_port?: number;
usage_api: string;
rest_api: string;
username: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,3 @@
* SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
* SPDX-License-Identifier: Apache-2.0
*/

#submit-button-wrapper {
text-align: right;
}

.space-evenly {
display: flex;
justify-content: space-evenly;
}

#protocol {
width: 6em;
max-width: 85vw;
}

#host {
width: 15em;
max-width: 85vw;
}

#port {
width: 8em;
max-width: 85vw;
}
Loading

0 comments on commit 1607d35

Please sign in to comment.