diff --git a/app/api/config_api.py b/app/api/config_api.py index d84a8c987cbb8e750626329fab810dbff4aa07f8..dde46d2cce01bc7bf4588ad3ee53d52daf28901a 100644 --- a/app/api/config_api.py +++ b/app/api/config_api.py @@ -12,7 +12,7 @@ import conf import _buildinfo as b import opa import correlation -import inspect +import k8s _logger = logging.getLogger(__name__) logger = correlation.DefaultExtrasAdapter(_logger, {"correlation_id": "None"}) @@ -34,6 +34,8 @@ async def show_policy_config_details(auth_data: auth.Auth = Depends(auth.require headers["X-Correlation-ID"] = correlation_id headers["Correlation-ID"] = correlation_id headers["req_id"] = correlation_id + + configmap = k8s.get_opa_config(namespace=conf.NAMESPACE, name=conf.OPA_CONFIG_MAP) try: status_url = conf.OPA_STATUS_API r_status = requests.get(status_url, timeout=10, headers=headers) @@ -69,6 +71,7 @@ async def show_policy_config_details(auth_data: auth.Auth = Depends(auth.require }, "opa_config_response_headers": r_config_headers, "conf": conf_dict, + "configmap": configmap, "env": { "CLOUD_PROVIDER": os.environ.get("CLOUD_PROVIDER"), # "POLICY_BUCKET": os.environ.get("POLICY_BUCKET"), diff --git a/app/conf.py b/app/conf.py index 2c7b207af0879e4c16a3d1281acfe7ba3cf8ab1d..4a8e574abf6e390b718f0e7fbc226b3bb8856ef7 100644 --- a/app/conf.py +++ b/app/conf.py @@ -109,5 +109,8 @@ ENABLE_VERIFY_POLICY = os.getenv("ENABLE_VERIFY_POLICY", 'False').lower() in ('t ALLOW_CONFIG_API = os.getenv("ALLOW_CONFIG_API", 'True').lower() in ('true', '1', 't') # Mask config details from /config API - MASK_OPA_CONFIG_DETAILS = os.getenv("MASK_OPA_CONFIG_DETAILS", 'False').lower() in ('true', '1', 't') + +# Kubernetes details +NAMESPACE = os.getenv("NAMESPACE", 'osdu-services') +OPA_CONFIG_MAP = os.getenv("OPA_CONFIG_MAP", 'opa-config') \ No newline at end of file diff --git a/app/requirements.txt b/app/requirements.txt index 25841c4cd3e21bdb5c494524077676adce059c69..d6baefdd8d17686c57155522f4a1a246bdec22e2 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -10,6 +10,7 @@ starlette==0.26.1 starlette-context==0.3.5 uuid7==0.1.0 uvicorn==0.22.0 +kubernetes python-multipart diff --git a/app/tests/integration/test_integration_035_eval.py b/app/tests/integration/test_integration_035_eval.py index 87b0f503d38aef79d3bb114d97cc63aea4553234..793e083000bdbe7ade3e143f987ebd19441517c9 100644 --- a/app/tests/integration/test_integration_035_eval.py +++ b/app/tests/integration/test_integration_035_eval.py @@ -52,6 +52,10 @@ def post_query(policy_id, token, data_partition, files, service_url = False, exp headers={'Authorization': 'Bearer ' + token, 'data-partition-id': data_partition}) + print(f"status code returned: {r.status_code} {r.text}") + if r.status_code == 406 == expect: + return r.json() + if not r.ok and expect == 200: json_str = json.dumps(r.json(), indent=4, sort_keys=True) filename = "pytest_eval_query_debug.json" diff --git a/app/tests/unit/test_api_unit.py b/app/tests/unit/test_api_unit.py index 580b6c7a654edd08f5ed69bb7d620d2fa9bd0aa8..5ccdf90a6a5f31860389e55acaa22326cc042416 100644 --- a/app/tests/unit/test_api_unit.py +++ b/app/tests/unit/test_api_unit.py @@ -121,9 +121,8 @@ class TryUnitTesting(unittest.TestCase): """Check config API as a member of both user and admin groups""" r = client.get(conf.SERVICE_BASE_PATH + "/config") self.assertEqual(r.status_code, 200, "Expected config Page is available") - if r.ok: - js = json.dumps(r.json(), indent=4) - print(f"{js}") + js = json.dumps(r.json(), indent=4) + print(f"{js}") #@unittest.skipIf(conf.ENABLE_DEV_DIAGNOSTICS == False, "Skipping diagnostic test - ENABLE_DEV_DIAGNOSTICS") @set_authorize_session(USER_ONLY_SVC)