Skip to content

https

Download strategy class for http/https

HTTPSStrategy dataclass

Strategy for retrieving data via http.

Registers strategies:

  • ("scheme", "http")
  • ("scheme", "https")
Source code in oteapi/strategies/download/https.py
@dataclass
class HTTPSStrategy:
    """Strategy for retrieving data via http.

    **Registers strategies**:

    - `("scheme", "http")`
    - `("scheme", "https")`

    """

    download_config: "ResourceConfig"

    def initialize(self, session: "Optional[Dict[str, Any]]" = None) -> SessionUpdate:
        """Initialize."""
        return SessionUpdate()

    def get(self, session: "Optional[Dict[str, Any]]" = None) -> SessionUpdateHTTPS:
        """Download via http/https and store on local cache."""
        cache = DataCache(self.download_config.configuration)
        if cache.config.accessKey and cache.config.accessKey in cache:
            key = cache.config.accessKey
        else:
            if not self.download_config.downloadUrl:
                raise ValueError("downloadUrl not defined in configuration.")
            req = requests.get(self.download_config.downloadUrl, allow_redirects=True)
            key = cache.add(req.content)

        return SessionUpdateHTTPS(key=key)

get(self, session=None)

Download via http/https and store on local cache.

Source code in oteapi/strategies/download/https.py
def get(self, session: "Optional[Dict[str, Any]]" = None) -> SessionUpdateHTTPS:
    """Download via http/https and store on local cache."""
    cache = DataCache(self.download_config.configuration)
    if cache.config.accessKey and cache.config.accessKey in cache:
        key = cache.config.accessKey
    else:
        if not self.download_config.downloadUrl:
            raise ValueError("downloadUrl not defined in configuration.")
        req = requests.get(self.download_config.downloadUrl, allow_redirects=True)
        key = cache.add(req.content)

    return SessionUpdateHTTPS(key=key)

initialize(self, session=None)

Initialize.

Source code in oteapi/strategies/download/https.py
def initialize(self, session: "Optional[Dict[str, Any]]" = None) -> SessionUpdate:
    """Initialize."""
    return SessionUpdate()

SessionUpdateHTTPS (SessionUpdate) pydantic-model

Class for returning values from Download HTTPS strategy.

Source code in oteapi/strategies/download/https.py
class SessionUpdateHTTPS(SessionUpdate):
    """Class for returning values from Download HTTPS strategy."""

    key: str = Field(..., description="Key to access the data in the cache.")

key: str pydantic-field required

Key to access the data in the cache.

Back to top