Skip to content

Commit

Permalink
Change client interface to client.store_user.get() to client.store.us…
Browse files Browse the repository at this point in the history
…er.get() and same for similar functions (user/role/rule)

This is done by forwarding the parent client to sub-subclients.

Also client.algorithm_store has been changed to client.store
  • Loading branch information
bartvanb committed Mar 5, 2024
1 parent 57182cc commit 4d00774
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
12 changes: 2 additions & 10 deletions vantage6-client/vantage6/client/__init__.py
Expand Up @@ -9,9 +9,6 @@
import traceback

from pathlib import Path
from vantage6.client.subclients.algorithm import AlgorithmSubClient
from vantage6.client.subclients.store_rule import StoreRuleSubClient
from vantage6.client.subclients.store_user import StoreUserSubClient

from vantage6.common.globals import APPNAME
from vantage6.common.encryption import RSACryptor
Expand All @@ -23,13 +20,11 @@
from vantage6.common.task_status import has_task_finished
from vantage6.common.client.client_base import ClientBase
from vantage6.client.subclients.algorithm_store import AlgorithmStoreSubClient
from vantage6.client.subclients.store_role import StoreRoleSubClient
from vantage6.client.subclients.algorithm import AlgorithmSubClient


module_name = __name__.split(".")[1]

LEGACY = "legacy"


class UserClient(ClientBase):
"""User interface to the vantage6-server"""
Expand Down Expand Up @@ -60,11 +55,8 @@ def __init__(self, *args, log_level="debug", **kwargs) -> None:
self.role = self.Role(self)
self.node = self.Node(self)
self.rule = self.Rule(self)
self.algorithm_store = AlgorithmStoreSubClient(self)
self.store = AlgorithmStoreSubClient(self)
self.algorithm = AlgorithmSubClient(self)
self.store_role = StoreRoleSubClient(self)
self.store_rule = StoreRuleSubClient(self)
self.store_user = StoreUserSubClient(self)

# set collaboration id to None
self.collaboration_id = None
Expand Down
9 changes: 9 additions & 0 deletions vantage6-client/vantage6/client/subclients/algorithm_store.py
@@ -1,4 +1,7 @@
from vantage6.client.filter import post_filtering
from vantage6.client.subclients.store_role import StoreRoleSubClient
from vantage6.client.subclients.store_rule import StoreRuleSubClient
from vantage6.client.subclients.store_user import StoreUserSubClient
from vantage6.common.client.client_base import ClientBase


Expand All @@ -10,6 +13,12 @@ def __init__(self, parent: ClientBase):
self.url = None
self.store_id = None

self.base_client = self.parent

self.role = StoreRoleSubClient(self)
self.rule = StoreRuleSubClient(self)
self.user = StoreUserSubClient(self)

def set(self, id_: int) -> dict:
""" "
Set the algorithm store to use for the client.
Expand Down
10 changes: 8 additions & 2 deletions vantage6-common/vantage6/common/client/client_base.py
Expand Up @@ -159,7 +159,7 @@ def generate_path_to(self, endpoint: str, is_for_algorithm_store: bool) -> str:
base_path = self.base_path
else:
try:
base_path = self.algorithm_store.url
base_path = self.store.url
except AttributeError as exc:
raise AttributeError(
"Algorithm store not set. Please set the algorithm store first with"
Expand Down Expand Up @@ -543,4 +543,10 @@ class SubClient:
"""

def __init__(self, parent) -> None:
self.parent = parent
# If the parent has a parent, use that as the parent - we don't want
# grandparents and so on.
# TODO maybe this should ideally get a name of 'main_client' or something
if hasattr(parent, "parent"):
self.parent = parent.parent
else:
self.parent = parent

0 comments on commit 4d00774

Please sign in to comment.