Esempio n. 1
0
    def __init__(self, config):
        """A FileStore instance that allows pre-seeding the cache from an archive
        downloaded from a URL.

        Example configuration:

            file = {
                driver = "seeded-file",
                path = "/path/to/cache",
                url = "https://example.com/cache.tar.gz"
            }

        Configuration can include:

            path: Path on the local file system to store the cache.
            url: Where to download the preseed data from.
            archive_relpath: Path within the archive pointing to the root of the cache data.
            reseed_interval: Time in minutes after which the data will be
                              seeded again (defaults to no reseeding).

        Supported archive formats include `.zip`, `.tar`, `.tar.gz`, `.tar.bz2` or `.tar.zst`.
        """
        self._url = config["url"]
        self._reseed_interval = config.get("reseed_interval", 0)
        self._archive_relpath = config.get("archive_relpath")

        self._session = get_session()

        kwargs = {
            "directory": config["path"],
        }
        if "hash_type" in config:
            kwargs["hash_type"] = config["hash_type"]

        super(SeededFileStore, self).__init__(**kwargs)
Esempio n. 2
0
    def _get_resource(self, url):
        r = get_session("hgmo").get(url)

        if r.status_code == 404:
            raise PushNotFound(**self.context)

        r.raise_for_status()
        return r.json()
Esempio n. 3
0
    def _get_resource(self, url):
        try:
            r = get_session("hgmo").get(url)
        except requests.exceptions.RetryError as e:
            raise PushNotFound(f"{e} error when getting {url}", **self.context)

        if r.status_code == 404:
            raise PushNotFound(f"{r.status_code} response from {url}", **self.context)

        r.raise_for_status()
        return r.json()
Esempio n. 4
0
def _do_request(url, force_get=False, **kwargs):
    session = get_session()
    if kwargs and not force_get:
        response = session.post(url, **kwargs)
    else:
        response = session.get(url, stream=True, **kwargs)
    if response.status_code >= 400:
        # Consume content before raise_for_status, so that the connection can be
        # reused.
        response.content
    response.raise_for_status()
    return response
Esempio n. 5
0
    def _get_resource(cls, url, context=None):
        context = context or getattr(cls, "context", {})
        context.setdefault("branch", "unknown branch")
        context.setdefault("rev", "unknown")

        try:
            r = get_session().get(url)
        except requests.exceptions.RetryError as e:
            raise PushNotFound(f"{e} error when getting {url}", **context)

        if not r.ok:
            raise PushNotFound(f"{r.status_code} response from {url}",
                               **context)

        return r.json()
Esempio n. 6
0
 def _get_resource(self, url):
     r = get_session("hgmo").get(url)
     r.raise_for_status()
     return r.json()
Esempio n. 7
0
 def session(self):
     session = get_session()
     session.headers = {"User-Agent": "mozci"}
     return session