def _put_object(self, key: str, bucket: str, body: bytes, **kwargs) -> str: try: self.client.put_object(Bucket=bucket, Key=key, Body=body, **kwargs) except ClientError as e: status_code = e.response["ResponseMetadata"]["HTTPStatusCode"] exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response["Error"]["Message"]) from e return key
def _fetch_dynamodb(self, quadkey: str) -> Dict: try: return self.table.get_item( Key={"mosaicId": self.mosaic_name, "quadkey": quadkey} ).get("Item", {}) except ClientError as e: status_code = e.response["ResponseMetadata"]["HTTPStatusCode"] exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response["Error"]["Message"]) from e
def _get_object(self, key: str, bucket: str) -> bytes: try: response = self.client.get_object(Bucket=bucket, Key=key) except ClientError as e: status_code = e.response["ResponseMetadata"]["HTTPStatusCode"] exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response["Error"]["Message"]) from e return response["Body"].read()
def _get_object(self, key: str, bucket: str) -> bytes: try: gcs_bucket = self.client.bucket(bucket) response = gcs_bucket.blob(key).download_as_bytes() except GoogleAuthError as e: status_code = e.response["ResponseMetadata"]["HTTPStatusCode"] exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response["Error"]["Message"]) from e return response
def _put_object(self, key: str, bucket: str, body: bytes, **kwargs) -> str: try: gcs_bucket = self.client.bucket(bucket) blob = gcs_bucket.blob(key) blob.upload_from_string(body) except GoogleAuthError as e: status_code = e.response["ResponseMetadata"]["HTTPStatusCode"] exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response["Error"]["Message"]) from e return key
def _aws_get_data(key, bucket, client: boto3_session.client = None) -> bytes: if not client: session = boto3_session() client = session.client("s3") try: response = client.get_object(Bucket=bucket, Key=key) except ClientError as e: status_code = e.response["ResponseMetadata"]["HTTPStatusCode"] exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response["Error"]["Message"]) from e return response["Body"].read()
def _stac_search(url: str, q: Dict): try: r = requests.post(url, headers=headers, json=q) r.raise_for_status() except requests.exceptions.HTTPError as e: # post-flight errors status_code = e.response.status_code exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response.content) from e except requests.exceptions.RequestException as e: # pre-flight errors raise MosaicError(e.args[0].reason) from e return r.json()
def _aws_put_data(key: str, bucket: str, body: bytes, client: boto3_session.client = None, **kwargs) -> str: if not client: session = boto3_session() client = session.client("s3") try: client.put_object(Bucket=bucket, Key=key, Body=body, **kwargs) except ClientError as e: status_code = e.response["ResponseMetadata"]["HTTPStatusCode"] exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response["Error"]["Message"]) from e return key
def _read(self, gzip: bool = None) -> MosaicJSON: # type: ignore """Get mosaicjson document.""" try: r = requests.get(self.path) r.raise_for_status() except requests.exceptions.HTTPError as e: # post-flight errors status_code = e.response.status_code exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response.content) from e except requests.exceptions.RequestException as e: # pre-flight errors raise MosaicError(e.args[0].reason) from e body = r.content self._file_byte_size = len(body) if gzip or (gzip is None and self.path.endswith(".gz")): body = _decompress_gz(body) return MosaicJSON(**json.loads(body))
def _read(self) -> MosaicJSON: # type: ignore """Get mosaicjson document.""" try: r = httpx.get(self.input) r.raise_for_status() except httpx.HTTPStatusError as e: # post-flight errors status_code = e.response.status_code exc = _HTTP_EXCEPTIONS.get(status_code, MosaicError) raise exc(e.response.content) from e except httpx.RequestError as e: # pre-flight errors raise MosaicError(e.args[0].reason) from e body = r.content self._file_byte_size = len(body) if self.input.endswith(".gz"): body = _decompress_gz(body) return MosaicJSON(**json.loads(body))