From 827f3af2f9b7f4f5556f56c4f9a414b6ef2fc897 Mon Sep 17 00:00:00 2001 From: Anshuman Goel Date: Wed, 28 Oct 2020 13:19:15 -0700 Subject: [PATCH 1/4] Adding cache for sas url --- src/cli/onefuzz/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cli/onefuzz/api.py b/src/cli/onefuzz/api.py index b45d4e2edb..c4ddd23287 100644 --- a/src/cli/onefuzz/api.py +++ b/src/cli/onefuzz/api.py @@ -9,6 +9,7 @@ import re import subprocess # nosec import uuid +from memoization import cached from shutil import which from typing import Callable, Dict, List, Optional, Tuple, Type, TypeVar from uuid import UUID @@ -146,6 +147,7 @@ class Files(Endpoint): endpoint = "files" + @cached def _get_client(self, container: str) -> ContainerWrapper: sas = self.onefuzz.containers.get(container).sas_url return ContainerWrapper(sas) From 3c2704341a674221126211d5d4e61632328af4cc Mon Sep 17 00:00:00 2001 From: Anshuman Goel Date: Wed, 28 Oct 2020 13:35:32 -0700 Subject: [PATCH 2/4] adding ttl --- src/cli/onefuzz/api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cli/onefuzz/api.py b/src/cli/onefuzz/api.py index c4ddd23287..fb46fcf047 100644 --- a/src/cli/onefuzz/api.py +++ b/src/cli/onefuzz/api.py @@ -9,13 +9,13 @@ import re import subprocess # nosec import uuid -from memoization import cached from shutil import which from typing import Callable, Dict, List, Optional, Tuple, Type, TypeVar from uuid import UUID import pkg_resources import semver +from memoization import cached from onefuzztypes import enums, models, primitives, requests, responses from pydantic import BaseModel from six.moves import input # workaround for static analysis @@ -34,6 +34,8 @@ # This was generated randomly and should be preserved moving forwards ONEFUZZ_GUID_NAMESPACE = uuid.UUID("27f25e3f-6544-4b69-b309-9b096c5a9cbc") +ONE_HOUR_IN_SECONDS = 3600 + DEFAULT_LINUX_IMAGE = "Canonical:UbuntuServer:18.04-LTS:latest" DEFAULT_WINDOWS_IMAGE = "MicrosoftWindowsDesktop:Windows-10:rs5-pro:latest" @@ -147,7 +149,7 @@ class Files(Endpoint): endpoint = "files" - @cached + @cached(ttl=ONE_HOUR_IN_SECONDS) def _get_client(self, container: str) -> ContainerWrapper: sas = self.onefuzz.containers.get(container).sas_url return ContainerWrapper(sas) From eafce1461d6574198f20b0dac32fb67c19eec052 Mon Sep 17 00:00:00 2001 From: Anshuman Goel Date: Wed, 28 Oct 2020 14:00:10 -0700 Subject: [PATCH 3/4] any complain --- src/cli/onefuzz/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/onefuzz/api.py b/src/cli/onefuzz/api.py index fb46fcf047..523cc1abb4 100644 --- a/src/cli/onefuzz/api.py +++ b/src/cli/onefuzz/api.py @@ -10,7 +10,7 @@ import subprocess # nosec import uuid from shutil import which -from typing import Callable, Dict, List, Optional, Tuple, Type, TypeVar +from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar from uuid import UUID import pkg_resources @@ -166,7 +166,7 @@ def delete(self, container: str, filename: str) -> None: client = self._get_client(container) client.delete_blob(filename) - def get(self, container: str, filename: str) -> bytes: + def get(self, container: str, filename: str) -> Any: """ get a file from a container """ self.logger.debug("getting file from container: %s:%s", container, filename) client = self._get_client(container) From 37f3bc0e0d1cfd618557ae449981046e51ff91d0 Mon Sep 17 00:00:00 2001 From: Anshuman Goel Date: Wed, 28 Oct 2020 14:18:25 -0700 Subject: [PATCH 4/4] adding cast --- src/cli/onefuzz/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cli/onefuzz/api.py b/src/cli/onefuzz/api.py index 523cc1abb4..d236eebbd7 100644 --- a/src/cli/onefuzz/api.py +++ b/src/cli/onefuzz/api.py @@ -10,7 +10,7 @@ import subprocess # nosec import uuid from shutil import which -from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar +from typing import Callable, Dict, List, Optional, Tuple, Type, TypeVar, cast from uuid import UUID import pkg_resources @@ -166,11 +166,12 @@ def delete(self, container: str, filename: str) -> None: client = self._get_client(container) client.delete_blob(filename) - def get(self, container: str, filename: str) -> Any: + def get(self, container: str, filename: str) -> bytes: """ get a file from a container """ self.logger.debug("getting file from container: %s:%s", container, filename) client = self._get_client(container) - return client.download_blob(filename) + downloaded = cast(bytes, client.download_blob(filename)) + return downloaded def upload_file( self, container: str, file_path: str, blob_name: Optional[str] = None