Skip to content

Commit

Permalink
remove custom content-type support for Conformity API
Browse files Browse the repository at this point in the history
  • Loading branch information
ronald-bautista committed Mar 4, 2022
1 parent 1243657 commit 7578110
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions src/conformity_migration_tool/di.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from typing import Any, Dict

from requests import Response, Session
from requests import Session

from conformity_migration.conformity_api import (
ConformityAPI,
Expand All @@ -13,44 +13,13 @@
from .utils import str2bool


class SessionDecorator(Session):
def __init__(self, sess: Session) -> None:
self._sess = sess

def __getattr__(self, name):
return getattr(self._sess, name)

def __setattr__(self, name: str, value: Any) -> None:
if name == "_sess":
return super().__setattr__(name, value)
return setattr(self._sess, name, value)


class CustomContentTypeSession(SessionDecorator):
def __init__(self, sess: Session, content_type: str) -> None:
super().__init__(sess)
self._content_type = content_type

def request(self, *args, **kwargs) -> Response:
headers = kwargs.setdefault("headers", dict())
headers["Content-Type"] = self._content_type
return super().request(*args, **kwargs)


class AppDependencies:
def __init__(self, conf: Dict[str, Any]) -> None:
self._conf = conf
log_backoff = str2bool(os.getenv("LOG_BACKOFF", "False"))
if log_backoff:
logging.getLogger("backoff").addHandler(logging.StreamHandler())

def custom_content_type_http(self) -> Session:
sess = Session()
http_content_type = os.getenv("C1_HTTP_CONTENT_TYPE")
if http_content_type:
sess = CustomContentTypeSession(sess=sess, content_type=http_content_type)
return sess

def legacy_conformity_api(self) -> ConformityAPI:
api_key = self._conf["LEGACY_CONFORMITY"]["API_KEY"]
base_url = self._conf["LEGACY_CONFORMITY"]["API_BASE_URL"]
Expand All @@ -62,10 +31,7 @@ def c1_conformity_api(self) -> ConformityAPI:
api_key = self._conf["CLOUD_ONE_CONFORMITY"]["API_KEY"]
base_url = self._conf["CLOUD_ONE_CONFORMITY"]["API_BASE_URL"]

api = DefaultConformityAPI(
api_key=api_key, base_url=base_url, http=self.custom_content_type_http()
)
# return api
api = DefaultConformityAPI(api_key=api_key, base_url=base_url, http=Session())
return WorkaroundFixConformityAPI(api)


Expand Down

0 comments on commit 7578110

Please sign in to comment.