Skip to content

state

mlte/backend/core/state.py

Globally-accessible application state.

State

Global state object.

Source code in mlte/backend/core/state.py
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
class State:
    """Global state object."""

    def __init__(self):
        self.reset()

    def reset(self):
        """Resets all internal state to defaults."""
        self._artifact_store: Optional[ArtifactStore] = None
        """The artifact store instance maintained by the state object."""

        self._user_store: Optional[UserStore] = None
        """The user store instance maintained by the state object."""

        self._catalog_stores: CatalogStoreGroup = CatalogStoreGroup()
        """The list of catalog store instances maintained by the state object."""

        self._custom_list_store: Optional[CustomListStore] = None
        """The custom list store instance maintained by the state object."""

        self._jwt_secret_key: str = ""
        """Secret key used to sign authentication tokens."""

    def set_artifact_store(self, store: ArtifactStore):
        """Set the globally-configured backend artifact store."""
        self._artifact_store = store

    def set_user_store(self, store: UserStore):
        """Set the globally-configured backend user store."""
        self._user_store = store

    def add_catalog_store(
        self, store: CatalogStore, id: str, overwite: bool = False
    ):
        """Adds to the the globally-configured backend list of catalog stores."""
        self._catalog_stores.add_catalog(id, store, overwite)

    def add_catalog_store_from_uri(
        self, store_uri: str, id: str, overwite: bool = False
    ):
        """Adds to the the globally-configured backend list of catalog stores."""
        self._catalog_stores.add_catalog_from_uri(id, store_uri, overwite)

    def set_custom_list_store(self, store: CustomListStore):
        """Set the globally-configured backend custom list store."""
        self._custom_list_store = store

    def set_token_key(self, token_key: str):
        """Sets the globally used token secret key."""
        self._jwt_secret_key = token_key

    @property
    def artifact_store(self) -> ArtifactStore:
        """Get the globally-configured backend artifact store."""
        if self._artifact_store is None:
            raise RuntimeError("Artifact store is not configured.")
        return self._artifact_store

    @property
    def user_store(self) -> UserStore:
        """Get the globally-configured backend user store."""
        if self._user_store is None:
            raise RuntimeError("User store is not configured.")
        return self._user_store

    @property
    def catalog_stores(self) -> CatalogStoreGroup:
        """Get the globally-configured backend catalog store group."""
        return self._catalog_stores

    @property
    def token_key(self) -> str:
        """Get the globally-configured token secret key."""
        if self._jwt_secret_key == "":
            raise RuntimeError("Token key has not been configured.")
        return self._jwt_secret_key

    @property
    def custom_list_store(self) -> CustomListStore:
        """Get the globablly-configured backend custom list store."""
        if self._custom_list_store is None:
            raise RuntimeError("Custom list store is not configured.")
        return self._custom_list_store

artifact_store property

Get the globally-configured backend artifact store.

catalog_stores property

Get the globally-configured backend catalog store group.

custom_list_store property

Get the globablly-configured backend custom list store.

token_key property

Get the globally-configured token secret key.

user_store property

Get the globally-configured backend user store.

add_catalog_store(store, id, overwite=False)

Adds to the the globally-configured backend list of catalog stores.

Source code in mlte/backend/core/state.py
49
50
51
52
53
def add_catalog_store(
    self, store: CatalogStore, id: str, overwite: bool = False
):
    """Adds to the the globally-configured backend list of catalog stores."""
    self._catalog_stores.add_catalog(id, store, overwite)

add_catalog_store_from_uri(store_uri, id, overwite=False)

Adds to the the globally-configured backend list of catalog stores.

Source code in mlte/backend/core/state.py
55
56
57
58
59
def add_catalog_store_from_uri(
    self, store_uri: str, id: str, overwite: bool = False
):
    """Adds to the the globally-configured backend list of catalog stores."""
    self._catalog_stores.add_catalog_from_uri(id, store_uri, overwite)

reset()

Resets all internal state to defaults.

Source code in mlte/backend/core/state.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def reset(self):
    """Resets all internal state to defaults."""
    self._artifact_store: Optional[ArtifactStore] = None
    """The artifact store instance maintained by the state object."""

    self._user_store: Optional[UserStore] = None
    """The user store instance maintained by the state object."""

    self._catalog_stores: CatalogStoreGroup = CatalogStoreGroup()
    """The list of catalog store instances maintained by the state object."""

    self._custom_list_store: Optional[CustomListStore] = None
    """The custom list store instance maintained by the state object."""

    self._jwt_secret_key: str = ""
    """Secret key used to sign authentication tokens."""

set_artifact_store(store)

Set the globally-configured backend artifact store.

Source code in mlte/backend/core/state.py
41
42
43
def set_artifact_store(self, store: ArtifactStore):
    """Set the globally-configured backend artifact store."""
    self._artifact_store = store

set_custom_list_store(store)

Set the globally-configured backend custom list store.

Source code in mlte/backend/core/state.py
61
62
63
def set_custom_list_store(self, store: CustomListStore):
    """Set the globally-configured backend custom list store."""
    self._custom_list_store = store

set_token_key(token_key)

Sets the globally used token secret key.

Source code in mlte/backend/core/state.py
65
66
67
def set_token_key(self, token_key: str):
    """Sets the globally used token secret key."""
    self._jwt_secret_key = token_key

set_user_store(store)

Set the globally-configured backend user store.

Source code in mlte/backend/core/state.py
45
46
47
def set_user_store(self, store: UserStore):
    """Set the globally-configured backend user store."""
    self._user_store = store