Skip to content

Commit

Permalink
add storage scp_prefix properties
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Aug 12, 2024
1 parent 97b49c9 commit 32ea5a4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bfabric/entities/storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any
from functools import cached_property
from typing import Any, TYPE_CHECKING

from bfabric import Bfabric
from bfabric.entities.core.entity import Entity
Expand All @@ -11,3 +12,16 @@ class Storage(Entity):

def __init__(self, data_dict: dict[str, Any], client: Bfabric | None) -> None:
super().__init__(data_dict=data_dict, client=client)

@cached_property
def scp_prefix_no_path(self) -> str:
"""SCP prefix without storage base path included."""
result = self._client.read("access", {"storageid": self.id, "type": "scp"})
if len(result) != 1:
raise ValueError(f"Expected exactly 1 SCP access for storage {self.id}, actual: {len(result)}")
return f"{result[0]['host']}:"

@cached_property
def scp_prefix_full(self) -> str:
"""SCP prefix with storage base path included."""
return f"{self.scp_prefix_no_path}{self.data_dict['basepath']}"

0 comments on commit 32ea5a4

Please sign in to comment.