Skip to content

Commit

Permalink
Revert "Revert "[#186622738] use workbench-user-service for fetching …
Browse files Browse the repository at this point in the history
…namespace (#3)""

This reverts commit 73cf944.
  • Loading branch information
Diana-DNAstack committed Apr 18, 2024
1 parent 3ae9c72 commit dcce00a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
24 changes: 24 additions & 0 deletions dnastack/cli/workbench/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from dnastack.client.workbench.ewes.client import EWesClient
from dnastack.client.workbench.workflow.client import WorkflowClient
from dnastack.client.workbench.workbench_user_service.client import WorkbenchUserClient
from dnastack.cli.config.context import ContextCommandHandler
from dnastack.cli.helpers.client_factory import ConfigurationBasedClientFactory


DEFAULT_WORKBENCH_DESTINATION = "workbench.omics.ai"


Expand All @@ -15,9 +17,25 @@ def _populate_workbench_endpoint():
handler.use(DEFAULT_WORKBENCH_DESTINATION, context_name="workbench", no_auth=False)


def get_user_client(context_name: Optional[str] = None,
endpoint_id: Optional[str] = None) -> WorkbenchUserClient:
factory: ConfigurationBasedClientFactory = container.get(ConfigurationBasedClientFactory)
try:
return factory.get(WorkbenchUserClient, endpoint_id=endpoint_id, context_name=context_name)
except AssertionError:
_populate_workbench_endpoint()
return factory.get(WorkbenchUserClient, endpoint_id=endpoint_id, context_name=context_name)


def get_ewes_client(context_name: Optional[str] = None,
endpoint_id: Optional[str] = None,
namespace: Optional[str] = None) -> EWesClient:


if not namespace:
user_client = get_user_client(context_name=context_name, endpoint_id=endpoint_id)
namespace = user_client.get_user_config().default_namespace

factory: ConfigurationBasedClientFactory = container.get(ConfigurationBasedClientFactory)
try:
return factory.get(EWesClient, endpoint_id=endpoint_id, context_name=context_name, namespace=namespace)
Expand All @@ -29,6 +47,10 @@ def get_ewes_client(context_name: Optional[str] = None,
def get_workflow_client(context_name: Optional[str] = None,
endpoint_id: Optional[str] = None,
namespace: Optional[str] = None) -> WorkflowClient:
if not namespace:
user_client = get_user_client(context_name=context_name, endpoint_id=endpoint_id)
namespace = user_client.get_user_config().default_namespace

factory: ConfigurationBasedClientFactory = container.get(ConfigurationBasedClientFactory)
try:
return factory.get(WorkflowClient, endpoint_id=endpoint_id, context_name=context_name, namespace=namespace)
Expand All @@ -37,6 +59,8 @@ def get_workflow_client(context_name: Optional[str] = None,
return factory.get(WorkflowClient, endpoint_id=endpoint_id, context_name=context_name, namespace=namespace)




class UnableToMergeJsonError(RuntimeError):
def __init__(self, key):
super().__init__(f'Unable to merge key {key}. The value for {key} must be of type dict, str, int or float')
Expand Down
6 changes: 4 additions & 2 deletions dnastack/client/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import TypeVar

from dnastack.client.workbench.ewes.client import EWesClient
from dnastack.client.workbench.workbench_user_service.client import WorkbenchUserClient
from dnastack.client.workbench.workflow.client import WorkflowClient
from dnastack.client.base_client import BaseServiceClient
from dnastack.client.collections.client import CollectionServiceClient
Expand All @@ -9,16 +10,17 @@
from dnastack.client.service_registry.client import ServiceRegistry

# All known client classes
ALL_SERVICE_CLIENT_CLASSES = (CollectionServiceClient, DataConnectClient, DrsClient, ServiceRegistry, EWesClient, WorkflowClient)
ALL_SERVICE_CLIENT_CLASSES = (CollectionServiceClient, DataConnectClient, DrsClient, ServiceRegistry, EWesClient, WorkflowClient, WorkbenchUserClient)

# All client classes for data access
DATA_SERVICE_CLIENT_CLASSES = (CollectionServiceClient, DataConnectClient, DrsClient, EWesClient, WorkflowClient)
DATA_SERVICE_CLIENT_CLASSES = (CollectionServiceClient, DataConnectClient, DrsClient, EWesClient, WorkflowClient, WorkbenchUserClient)

# Type variable for the service client
SERVICE_CLIENT_CLASS = TypeVar('SERVICE_CLIENT_CLASS',
BaseServiceClient,
EWesClient,
WorkflowClient,
WorkbenchUserClient,
CollectionServiceClient,
DataConnectClient,
DrsClient,
Expand Down
4 changes: 2 additions & 2 deletions dnastack/client/workbench/workbench_user_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dnastack.client.workbench.workbench_user_service.models import WorkbenchUser


class WusClient(BaseServiceClient):
class WorkbenchUserClient(BaseServiceClient):

@staticmethod
def get_adapter_type() -> str:
Expand All @@ -27,7 +27,7 @@ def make(cls, endpoint: ServiceEndpoint):
endpoint.type = cls.get_default_service_type()
return cls(endpoint)

def fetch_current_user(self) -> WorkbenchUser:
def get_user_config(self) -> WorkbenchUser:
with self.create_http_session() as session:
response = session.get(
urljoin(self.endpoint.url, f'users/me')
Expand Down

0 comments on commit dcce00a

Please sign in to comment.