From 34b5ec3042d187f205e080f1424b38352a4373e0 Mon Sep 17 00:00:00 2001 From: ChristianOertlin Date: Fri, 10 Jan 2025 09:15:12 +0100 Subject: [PATCH 1/6] Revert "feat(change token genertion towards tb api) (#4060) (patch)" (#4069) This reverts commit 1ae4b671ff48972140f18fc7a0e0410645a0e8a5. --- cg/apps/tb/api.py | 15 ++++++--------- cg/models/cg_config.py | 1 - cg/server/app_config.py | 1 - cg/server/ext.py | 2 -- tests/conftest.py | 1 - tests/server/conftest.py | 1 - 6 files changed, 6 insertions(+), 15 deletions(-) diff --git a/cg/apps/tb/api.py b/cg/apps/tb/api.py index 7eaa9966e8..4bbcc0719b 100644 --- a/cg/apps/tb/api.py +++ b/cg/apps/tb/api.py @@ -4,8 +4,8 @@ import logging from typing import Any -from google.auth.transport.requests import Request -from google.oauth2 import service_account +from google.auth import jwt +from google.auth.crypt import RSASigner from cg.apps.tb.dto.create_job_request import CreateJobRequest from cg.apps.tb.dto.summary_response import AnalysisSummary, SummariesResponse @@ -46,17 +46,14 @@ class TrailblazerAPI: def __init__(self, config: dict): self.service_account = config["trailblazer"]["service_account"] self.service_account_auth_file = config["trailblazer"]["service_account_auth_file"] - self.google_client_id = config["trailblazer"]["google_client_id"] self.host = config["trailblazer"]["host"] @property def auth_header(self) -> dict: - credentials = service_account.IDTokenCredentials.from_service_account_file( - self.service_account_auth_file, - target_audience=self.google_client_id, - ) - credentials.refresh(Request()) - return {"Authorization": f"Bearer {credentials.token}"} + signer = RSASigner.from_service_account_file(self.service_account_auth_file) + payload = {"email": self.service_account} + jwt_token = jwt.encode(signer=signer, payload=payload).decode("ascii") + return {"Authorization": f"Bearer {jwt_token}"} def query_trailblazer( self, command: str, request_body: dict, method: str = APIMethods.POST diff --git a/cg/models/cg_config.py b/cg/models/cg_config.py index 7ccdbfdf6e..bab7e52a26 100644 --- a/cg/models/cg_config.py +++ b/cg/models/cg_config.py @@ -129,7 +129,6 @@ class ClientConfig(BaseModel): class TrailblazerConfig(BaseModel): service_account: str service_account_auth_file: str - google_client_id: str host: str diff --git a/cg/server/app_config.py b/cg/server/app_config.py index dc3bcfc81d..97f38b3235 100644 --- a/cg/server/app_config.py +++ b/cg/server/app_config.py @@ -21,7 +21,6 @@ class AppConfig(BaseSettings): trailblazer_host: str = "trailblazer_host" trailblazer_service_account: str = "service_account" trailblazer_service_account_auth_file: str = "auth_file.json" - trailblazer_google_client_id: str = "google_client_id" freshdesk_url: str = "https://company.freshdesk.com" freshdesk_api_key: str = "freshdesk_api_key" freshdesk_order_email_id: int = 10 diff --git a/cg/server/ext.py b/cg/server/ext.py index bb77a7467c..a69f9ec573 100644 --- a/cg/server/ext.py +++ b/cg/server/ext.py @@ -68,13 +68,11 @@ def __init__(self, app=None): def init_app(self, app): service_account: str = app.config["trailblazer_service_account"] service_account_auth_file: str = app.config["trailblazer_service_account_auth_file"] - google_client_id: str = app.config["trailblazer_google_client_id"] host: str = app.config["trailblazer_host"] config = { "trailblazer": { "service_account": service_account, "service_account_auth_file": service_account_auth_file, - "google_client_id": google_client_id, "host": host, } } diff --git a/tests/conftest.py b/tests/conftest.py index fc4ea1992e..79b389e3dd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2185,7 +2185,6 @@ def context_config( "host": "https://trailblazer.scilifelab.se/", "service_account": "SERVICE", "service_account_auth_file": "trailblazer-auth.json", - "google_client_id": "client_id", }, "arnold": {"api_url": "https://arnold.scilifelab.se/"}, "janus": {"host": "https://janus.sys.scilifelab.se/"}, diff --git a/tests/server/conftest.py b/tests/server/conftest.py index b723db0163..373bf4dea8 100644 --- a/tests/server/conftest.py +++ b/tests/server/conftest.py @@ -25,7 +25,6 @@ os.environ["GOOGLE_OAUTH_CLIENT_SECRET"] = "dummy_value" os.environ["TRAILBLAZER_SERVICE_ACCOUNT"] = "dummy_value" os.environ["TRAILBLAZER_SERVICE_ACCOUNT_AUTH_FILE"] = "dummy_value" -os.environ["TRAILBLAZER_GOOGLE_CLIENT_ID"] = "dummy_value" os.environ["TRAILBLAZER_HOST"] = "dummy_value" os.environ["CG_SECRET_KEY"] = "dummy_value" os.environ["GUNICORN_BIND"] = "0.0.0.0:8000" From 95d37e833b3a7e103c73c58d0d9edaa2186175cd Mon Sep 17 00:00:00 2001 From: Clinical Genomics Bot Date: Fri, 10 Jan 2025 08:15:39 +0000 Subject: [PATCH 2/6] =?UTF-8?q?Bump=20version:=2065.0.7=20=E2=86=92=2065.0?= =?UTF-8?q?.8=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- cg/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 04129728e6..e6182e2fe8 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 65.0.7 +current_version = 65.0.8 commit = True tag = True tag_name = v{new_version} diff --git a/cg/__init__.py b/cg/__init__.py index 39b15054ab..4017ee6dc5 100644 --- a/cg/__init__.py +++ b/cg/__init__.py @@ -1,2 +1,2 @@ __title__ = "cg" -__version__ = "65.0.7" +__version__ = "65.0.8" diff --git a/pyproject.toml b/pyproject.toml index d0df91e9e0..d991d0b183 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "cg" -version = "65.0.7" +version = "65.0.8" description = "Clinical Genomics command center" authors = ["Clinical Genomics "] readme = "README.md" From d0f311cf129e479c972ef24cb68ed94215f6667c Mon Sep 17 00:00:00 2001 From: ChristianOertlin Date: Mon, 13 Jan 2025 08:52:59 +0100 Subject: [PATCH 3/6] fix(tb auth) (#4072) (patch) # Description TB auth --- cg/apps/tb/api.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cg/apps/tb/api.py b/cg/apps/tb/api.py index 4bbcc0719b..304b10ba33 100644 --- a/cg/apps/tb/api.py +++ b/cg/apps/tb/api.py @@ -4,8 +4,8 @@ import logging from typing import Any -from google.auth import jwt -from google.auth.crypt import RSASigner +from google.auth.transport.requests import Request +from google.oauth2 import service_account from cg.apps.tb.dto.create_job_request import CreateJobRequest from cg.apps.tb.dto.summary_response import AnalysisSummary, SummariesResponse @@ -50,10 +50,12 @@ def __init__(self, config: dict): @property def auth_header(self) -> dict: - signer = RSASigner.from_service_account_file(self.service_account_auth_file) - payload = {"email": self.service_account} - jwt_token = jwt.encode(signer=signer, payload=payload).decode("ascii") - return {"Authorization": f"Bearer {jwt_token}"} + credentials = service_account.IDTokenCredentials.from_service_account_file( + filename=self.service_account_auth_file, + target_audience="trailblazer", + ) + credentials.refresh(Request()) + return {"Authorization": f"Bearer {credentials.token}"} def query_trailblazer( self, command: str, request_body: dict, method: str = APIMethods.POST From e74b9aabf5312ecacf8ca3a1bfda81f27e324785 Mon Sep 17 00:00:00 2001 From: Clinical Genomics Bot Date: Mon, 13 Jan 2025 07:53:26 +0000 Subject: [PATCH 4/6] =?UTF-8?q?Bump=20version:=2065.0.8=20=E2=86=92=2065.0?= =?UTF-8?q?.9=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- cg/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index e6182e2fe8..d489b87122 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 65.0.8 +current_version = 65.0.9 commit = True tag = True tag_name = v{new_version} diff --git a/cg/__init__.py b/cg/__init__.py index 4017ee6dc5..3608eda751 100644 --- a/cg/__init__.py +++ b/cg/__init__.py @@ -1,2 +1,2 @@ __title__ = "cg" -__version__ = "65.0.8" +__version__ = "65.0.9" diff --git a/pyproject.toml b/pyproject.toml index d991d0b183..7514f4950e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "cg" -version = "65.0.8" +version = "65.0.9" description = "Clinical Genomics command center" authors = ["Clinical Genomics "] readme = "README.md" From 1107b45efeeb6f2820d228dc3d64c09b2a8d5ab6 Mon Sep 17 00:00:00 2001 From: ChristianOertlin Date: Mon, 13 Jan 2025 13:05:46 +0100 Subject: [PATCH 5/6] fix(assignment maf cases to special order) (#4053) (patch) # Description Put newly generated MAF cases on fixed cust000 owned order --- cg/services/orders/store_order_services/constants.py | 2 ++ .../store_order_services/store_fastq_order_service.py | 11 +++++++---- cg/store/crud/create.py | 2 ++ tests/conftest.py | 4 ++++ tests/meta/orders/conftest.py | 1 + tests/meta/orders/test_meta_orders_api.py | 2 +- .../order_store_service/test_fastq_order_service.py | 7 ++++++- 7 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 cg/services/orders/store_order_services/constants.py diff --git a/cg/services/orders/store_order_services/constants.py b/cg/services/orders/store_order_services/constants.py new file mode 100644 index 0000000000..7adf027cf1 --- /dev/null +++ b/cg/services/orders/store_order_services/constants.py @@ -0,0 +1,2 @@ +# Hardcoded constant for special order to assign MAF cases to +MAF_ORDER_ID: int = 12377 diff --git a/cg/services/orders/store_order_services/store_fastq_order_service.py b/cg/services/orders/store_order_services/store_fastq_order_service.py index 8699c7a4b4..18ec1d0044 100644 --- a/cg/services/orders/store_order_services/store_fastq_order_service.py +++ b/cg/services/orders/store_order_services/store_fastq_order_service.py @@ -8,6 +8,7 @@ from cg.models.orders.order import OrderIn from cg.models.orders.sample_base import StatusEnum from cg.services.orders.order_lims_service.order_lims_service import OrderLimsService +from cg.services.orders.store_order_services.constants import MAF_ORDER_ID from cg.services.orders.submitters.order_submitter import StoreOrderService from cg.store.models import ApplicationVersion, Case, CaseSample, Customer, Order, Sample from cg.store.store import Store @@ -62,12 +63,14 @@ def order_to_status(order: OrderIn) -> dict: } return status_data - def create_maf_case(self, sample_obj: Sample, order: Order) -> None: + def create_maf_case(self, sample_obj: Sample, order: Order, case: Case) -> None: """Add a MAF case to the Status database.""" + maf_order = self.status_db.get_order_by_id(MAF_ORDER_ID) case: Case = self.status_db.add_case( + comment=f"MAF case for {case.internal_id} original order id {order.id}", data_analysis=Workflow(Workflow.MIP_DNA), data_delivery=DataDelivery(DataDelivery.NO_DELIVERY), - name="_".join([sample_obj.name, "MAF"]), + name="_".join([sample_obj.internal_id, "MAF"]), panels=[GenePanelMasterList.OMIM_AUTO], priority=Priority.research, ticket=sample_obj.original_ticket, @@ -78,7 +81,7 @@ def create_maf_case(self, sample_obj: Sample, order: Order) -> None: relationship: CaseSample = self.status_db.relate_sample( case=case, sample=sample_obj, status=StatusEnum.unknown ) - order.cases.append(case) + maf_order.cases.append(case) self.status_db.session.add_all([case, relationship]) def store_items_in_status( @@ -137,7 +140,7 @@ def store_items_in_status( not new_sample.is_tumour and new_sample.prep_category == SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING ): - self.create_maf_case(sample_obj=new_sample, order=status_db_order) + self.create_maf_case(sample_obj=new_sample, order=status_db_order, case=case) case.customer = customer new_relationship = self.status_db.relate_sample( case=case, sample=new_sample, status=StatusEnum.unknown diff --git a/cg/store/crud/create.py b/cg/store/crud/create.py index 40b0f72c83..e26140f995 100644 --- a/cg/store/crud/create.py +++ b/cg/store/crud/create.py @@ -246,11 +246,13 @@ def add_case( priority: Priority | None = Priority.standard, synopsis: str | None = None, customer_id: int | None = None, + comment: str | None = None, ) -> Case: """Build a new Case record.""" internal_id: str = self.generate_readable_case_id() return Case( + comment=comment, cohorts=cohorts, data_analysis=str(data_analysis), data_delivery=str(data_delivery), diff --git a/tests/conftest.py b/tests/conftest.py index 79b389e3dd..e53ff46ea5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -59,6 +59,7 @@ from cg.services.deliver_files.rsync.service import DeliveryRsyncService from cg.services.illumina.backup.encrypt_service import IlluminaRunEncryptionService from cg.services.illumina.data_transfer.data_transfer_service import IlluminaDataTransferService +from cg.services.orders.store_order_services.constants import MAF_ORDER_ID from cg.store.database import create_all_tables, drop_all_tables, initialize_database from cg.store.models import ( Application, @@ -1649,6 +1650,9 @@ def base_store( store.session.add(organism) store.session.commit() + order: Order = Order(customer_id=1, id=MAF_ORDER_ID, ticket_id="100000000") + store.add_multiple_items_to_store([order]) + yield store diff --git a/tests/meta/orders/conftest.py b/tests/meta/orders/conftest.py index 5857e67a8a..ceb7665020 100644 --- a/tests/meta/orders/conftest.py +++ b/tests/meta/orders/conftest.py @@ -9,6 +9,7 @@ OrderSubmitterRegistry, setup_order_submitter_registry, ) +from cg.store.models import Order from cg.store.store import Store from tests.mocks.limsmock import MockLimsAPI diff --git a/tests/meta/orders/test_meta_orders_api.py b/tests/meta/orders/test_meta_orders_api.py index 04ffe40588..6844697337 100644 --- a/tests/meta/orders/test_meta_orders_api.py +++ b/tests/meta/orders/test_meta_orders_api.py @@ -14,7 +14,7 @@ from cg.services.orders.validate_order_services.validate_case_order import ( ValidateCaseOrderService, ) -from cg.store.models import Case, Customer, Pool, Sample +from cg.store.models import Case, Customer, Pool, Sample, Order from cg.store.store import Store from tests.store_helpers import StoreHelpers diff --git a/tests/services/orders/order_store_service/test_fastq_order_service.py b/tests/services/orders/order_store_service/test_fastq_order_service.py index 7bbc9251bb..c26c217cea 100644 --- a/tests/services/orders/order_store_service/test_fastq_order_service.py +++ b/tests/services/orders/order_store_service/test_fastq_order_service.py @@ -6,8 +6,9 @@ from cg.constants.sequencing import SeqLibraryPrepCategory from cg.exc import OrderError from cg.models.orders.order import OrderIn, OrderType +from cg.services.orders.store_order_services.constants import MAF_ORDER_ID from cg.services.orders.store_order_services.store_fastq_order_service import StoreFastqOrderService -from cg.store.models import Application, Case, Sample +from cg.store.models import Application, Case, Sample, Order from cg.store.store import Store @@ -63,6 +64,10 @@ def test_store_samples( assert family_link.case.data_analysis assert family_link.case.data_delivery in [DataDelivery.FASTQ, DataDelivery.NO_DELIVERY] + # THEN a MAF case should be added to the MAF orders + maf_order: Order = base_store.get_order_by_id(MAF_ORDER_ID) + assert len(maf_order.cases) == 1 + def test_store_samples_sex_stored( base_store: Store, From f67b35ee6cbe1d9ea7205ff52cddcff907e357ef Mon Sep 17 00:00:00 2001 From: Clinical Genomics Bot Date: Mon, 13 Jan 2025 12:06:14 +0000 Subject: [PATCH 6/6] =?UTF-8?q?Bump=20version:=2065.0.9=20=E2=86=92=2065.0?= =?UTF-8?q?.10=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- cg/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d489b87122..e750144371 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 65.0.9 +current_version = 65.0.10 commit = True tag = True tag_name = v{new_version} diff --git a/cg/__init__.py b/cg/__init__.py index 3608eda751..621e107544 100644 --- a/cg/__init__.py +++ b/cg/__init__.py @@ -1,2 +1,2 @@ __title__ = "cg" -__version__ = "65.0.9" +__version__ = "65.0.10" diff --git a/pyproject.toml b/pyproject.toml index 7514f4950e..47f020f2b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "cg" -version = "65.0.9" +version = "65.0.10" description = "Clinical Genomics command center" authors = ["Clinical Genomics "] readme = "README.md"