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
@StrategyFactory.register(("scheme", "http"), ("scheme", "https"))
class HTTPSStrategy:
"""Strategy for retrieving data via http.
**Registers strategies**:
- `("scheme", "http")`
- `("scheme", "https")`
"""
resource_config: "ResourceConfig"
def initialize(
self, session: "Optional[Dict[str, Any]]" = None
) -> "Dict[str, Any]":
"""Initialize."""
return {}
def get(self, session: "Optional[Dict[str, Any]]" = None) -> "Dict[str, Any]":
"""Download via http/https and store on local cache."""
cache = DataCache(self.resource_config.configuration)
if cache.config.accessKey and cache.config.accessKey in cache:
key = cache.config.accessKey
else:
if not self.resource_config.downloadUrl:
raise ValueError("downloadUrl not defined in configuration.")
req = requests.get(self.resource_config.downloadUrl, allow_redirects=True)
key = cache.add(req.content)
return {"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) -> "Dict[str, Any]":
"""Download via http/https and store on local cache."""
cache = DataCache(self.resource_config.configuration)
if cache.config.accessKey and cache.config.accessKey in cache:
key = cache.config.accessKey
else:
if not self.resource_config.downloadUrl:
raise ValueError("downloadUrl not defined in configuration.")
req = requests.get(self.resource_config.downloadUrl, allow_redirects=True)
key = cache.add(req.content)
return {"key": key}
initialize(self, session=None)
¶
Initialize.
Source code in oteapi/strategies/download/https.py
def initialize(
self, session: "Optional[Dict[str, Any]]" = None
) -> "Dict[str, Any]":
"""Initialize."""
return {}