mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 17:37:30 -02:30
[Policy as Code] Monkey patch opa_client.base.BaseClient (#6865)
Workaround bug described in https://github.com/Turall/OPA-python-client/issues/29
This commit is contained in:
@@ -2,10 +2,13 @@ import json
|
|||||||
import tempfile
|
import tempfile
|
||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
|
from typing import Optional, Union
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from flags.state import flag_enabled
|
from flags.state import flag_enabled
|
||||||
from opa_client import OpaClient
|
from opa_client import OpaClient
|
||||||
|
from opa_client.base import BaseClient
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework import fields
|
from rest_framework import fields
|
||||||
@@ -14,6 +17,29 @@ from awx.main import models
|
|||||||
from awx.main.exceptions import PolicyEvaluationError
|
from awx.main.exceptions import PolicyEvaluationError
|
||||||
|
|
||||||
|
|
||||||
|
# Monkey patching opa_client.base.BaseClient to fix retries and timeout settings
|
||||||
|
_original_opa_base_client_init = BaseClient.__init__
|
||||||
|
|
||||||
|
|
||||||
|
def _opa_base_client_init_fix(
|
||||||
|
self,
|
||||||
|
host: str = "localhost",
|
||||||
|
port: int = 8181,
|
||||||
|
version: str = "v1",
|
||||||
|
ssl: bool = False,
|
||||||
|
cert: Optional[Union[str, tuple]] = None,
|
||||||
|
headers: Optional[dict] = None,
|
||||||
|
retries: int = 2,
|
||||||
|
timeout: float = 1.5,
|
||||||
|
):
|
||||||
|
_original_opa_base_client_init(self, host, port, version, ssl, cert, headers)
|
||||||
|
self.retries = retries
|
||||||
|
self.timeout = timeout
|
||||||
|
|
||||||
|
|
||||||
|
BaseClient.__init__ = _opa_base_client_init_fix
|
||||||
|
|
||||||
|
|
||||||
class _UserSerializer(serializers.ModelSerializer):
|
class _UserSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.User
|
model = models.User
|
||||||
@@ -212,8 +238,8 @@ def opa_client(headers=None):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
ssl=settings.OPA_SSL,
|
ssl=settings.OPA_SSL,
|
||||||
cert=cert_temp_file_name,
|
cert=cert_temp_file_name,
|
||||||
retries=settings.OPA_REQUEST_RETRIES,
|
|
||||||
timeout=settings.OPA_REQUEST_TIMEOUT,
|
timeout=settings.OPA_REQUEST_TIMEOUT,
|
||||||
|
retries=settings.OPA_REQUEST_RETRIES,
|
||||||
) as client:
|
) as client:
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Markdown # used for formatting API help
|
|||||||
maturin # pydantic-core build dep
|
maturin # pydantic-core build dep
|
||||||
msgpack<1.0.6 # 1.0.6+ requires cython>=3
|
msgpack<1.0.6 # 1.0.6+ requires cython>=3
|
||||||
msrestazure
|
msrestazure
|
||||||
OPA-python-client
|
OPA-python-client==2.0.2 # Code contain monkey patch targeted to 2.0.2 to fix https://github.com/Turall/OPA-python-client/issues/29
|
||||||
openshift
|
openshift
|
||||||
opentelemetry-api~=1.24 # new y streams can be drastically different, in a good way
|
opentelemetry-api~=1.24 # new y streams can be drastically different, in a good way
|
||||||
opentelemetry-sdk~=1.24
|
opentelemetry-sdk~=1.24
|
||||||
|
|||||||
Reference in New Issue
Block a user