Commit 17db80dc authored by Vadzim Kulyba (EPAM)'s avatar Vadzim Kulyba (EPAM) Committed by harshit aggarwal
Browse files

feat(azure): add file handing support for azure provider

parent 164c46a1
...@@ -19,6 +19,7 @@ import dataclasses ...@@ -19,6 +19,7 @@ import dataclasses
import io import io
import json import json
import logging import logging
import os
from typing import List, Tuple from typing import List, Tuple
import requests import requests
...@@ -26,7 +27,7 @@ import tenacity ...@@ -26,7 +27,7 @@ import tenacity
from osdu_api.auth.authorization import TokenRefresher, authorize from osdu_api.auth.authorization import TokenRefresher, authorize
from osdu_api.providers import blob_storage from osdu_api.providers import blob_storage
from osdu_api.providers.types import BlobStorageClient, FileLikeObject from osdu_api.providers.types import BlobStorageClient, FileLikeObject
from osdu_api.utils.request import request_raiser
from osdu_ingestion.libs.constants import RETRIES, WAIT from osdu_ingestion.libs.constants import RETRIES, WAIT
from osdu_ingestion.libs.context import Context from osdu_ingestion.libs.context import Context
from osdu_ingestion.libs.exceptions import InvalidFileRecordData from osdu_ingestion.libs.exceptions import InvalidFileRecordData
...@@ -123,6 +124,13 @@ class FileHandler(HeadersMixin): ...@@ -123,6 +124,13 @@ class FileHandler(HeadersMixin):
unsigned_url=None, unsigned_url=None,
kind=None) kind=None)
@tenacity.retry(**RETRY_SETTINGS)
@authorize()
def _send_get_request(self, headers: dict, url: str) -> requests.Response:
response = requests.get(url, headers=headers)
logger.debug(response)
return response
@tenacity.retry(**RETRY_SETTINGS) @tenacity.retry(**RETRY_SETTINGS)
@authorize() @authorize()
def _send_post_request(self, headers: dict, url: str, request_body: str) -> requests.Response: def _send_post_request(self, headers: dict, url: str, request_body: str) -> requests.Response:
...@@ -132,10 +140,14 @@ class FileHandler(HeadersMixin): ...@@ -132,10 +140,14 @@ class FileHandler(HeadersMixin):
return response return response
@tenacity.retry(**RETRY_SETTINGS) @tenacity.retry(**RETRY_SETTINGS)
@authorize() @request_raiser
def _send_get_request(self, headers: dict, url: str) -> requests.Response: def _send_put_request(self, headers: dict, url: str, request_body: str) -> requests.Response:
response = requests.get(url, headers=headers) if os.getenv("CLOUD_PROVIDER") == "azure":
logger.debug(response) headers["x-ms-blob-type"] = "BlockBlob"
logger.debug(f"{request_body}")
response = requests.put(url, request_body, headers=headers)
logger.debug(response.content)
return response return response
def _get_upload_signed_url(self, headers: dict) -> FileUploadUrlResponse: def _get_upload_signed_url(self, headers: dict) -> FileUploadUrlResponse:
...@@ -187,7 +199,7 @@ class FileHandler(HeadersMixin): ...@@ -187,7 +199,7 @@ class FileHandler(HeadersMixin):
""" """
logger.debug("Uploading file.") logger.debug("Uploading file.")
buffer.seek(0) buffer.seek(0)
requests.put(signed_url, buffer.read(), headers=headers) self._send_put_request(headers, signed_url, buffer.read())
logger.debug("File uploaded.") logger.debug("File uploaded.")
def _get_file_location_request(self, headers: dict, file_id: str) -> str: def _get_file_location_request(self, headers: dict, file_id: str) -> str:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment