From 32ea5a4c771ce90a4a9b0f6fdb9653352af0d56c Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Mon, 12 Aug 2024 09:26:19 +0200 Subject: [PATCH] add storage scp_prefix properties --- bfabric/entities/storage.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/bfabric/entities/storage.py b/bfabric/entities/storage.py index a885984..3a4b17d 100644 --- a/bfabric/entities/storage.py +++ b/bfabric/entities/storage.py @@ -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 @@ -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']}"