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

Cache SAS tokens used for container file management #224

Merged
merged 7 commits into from
Oct 29, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 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 Any, 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
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 @@ -162,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:
anshuman-goel marked this conversation as resolved.
Show resolved Hide resolved
""" get a file from a container """
self.logger.debug("getting file from container: %s:%s", container, filename)
client = self._get_client(container)
Expand Down