Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Adding cache for sas return (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuman-goel authored Oct 29, 2020
1 parent f4b874e commit 99b69d3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cli/onefuzz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import subprocess # nosec
import uuid
from shutil import which
from typing import 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
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
Expand All @@ -33,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"

Expand Down Expand Up @@ -146,6 +149,7 @@ class Files(Endpoint):

endpoint = "files"

@cached(ttl=ONE_HOUR_IN_SECONDS)
def _get_client(self, container: str) -> ContainerWrapper:
sas = self.onefuzz.containers.get(container).sas_url
return ContainerWrapper(sas)
Expand All @@ -166,7 +170,8 @@ 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
Expand Down

0 comments on commit 99b69d3

Please sign in to comment.