diff --git a/util/config/provider/k8sprovider.py b/util/config/provider/k8sprovider.py index 94b1f15f5..c3965f015 100644 --- a/util/config/provider/k8sprovider.py +++ b/util/config/provider/k8sprovider.py @@ -57,9 +57,9 @@ class KubernetesConfigProvider(FileConfigProvider): def volume_file_exists(self, filename): secret = self._lookup_secret() - if not secret: + if not secret or not secret.get('data'): return False - return filename in secret + return filename in secret['data'] def list_volume_directory(self, path): @@ -69,7 +69,7 @@ class KubernetesConfigProvider(FileConfigProvider): return [] paths = [] - for filename in secret: + for filename in secret.get('data', {}): if filename.startswith(path): paths.append(filename[len(path) + 1:]) return paths @@ -132,10 +132,7 @@ class KubernetesConfigProvider(FileConfigProvider): response = self._execute_k8s_api('GET', secret_url) if response.status_code != 200: return None - secret_resp = json.loads(response.text) - if "data" not in secret_resp: - return secret_resp - return secret_resp["data"] + return json.loads(response.text) def _execute_k8s_api(self, method, relative_url, data=None): headers = { diff --git a/util/config/provider/test/test_k8sprovider.py b/util/config/provider/test/test_k8sprovider.py index 197a97ff7..d64dcee7b 100644 --- a/util/config/provider/test/test_k8sprovider.py +++ b/util/config/provider/test/test_k8sprovider.py @@ -26,8 +26,7 @@ def test_get_volume_path(directory, filename, expected): @pytest.mark.parametrize('response,expected', [ - (Mock(text="{\"license\":\"test\"}", status_code=200), {"license":"test"}), - (Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=200), {"license":"test"}), + (Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=200), {"data": {"license":"test"}}), (Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=404), None), ]) def test_lookup_secret(response, expected): @@ -37,9 +36,7 @@ def test_lookup_secret(response, expected): @pytest.mark.parametrize('response,key,expected', [ - (Mock(text="{\"license\":\"test\"}", status_code=200), "license", True), (Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=200), "license", True), - (Mock(text="{\"license\":\"test\"}", status_code=200), "config.yaml", False), (Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=200), "config.yaml", False), (Mock(text="", status_code=404), "license", False), ]) @@ -50,7 +47,6 @@ def test_volume_file_exists(response, key, expected): @pytest.mark.parametrize('response,expected', [ - (Mock(text="{\"extra_license\":\"test\"}", status_code=200), ["license"]), (Mock(text="{\"data\": {\"extra_license\":\"test\"}}", status_code=200), ["license"]), (Mock(text="", status_code=404), []), ])