Merge pull request #2744 from ecordell/hotfix/kubernetes-secret

Revert to old secret handling, fix license loading
This commit is contained in:
josephschorr 2017-06-29 09:29:10 +03:00 committed by GitHub
commit f05b6d8c52
2 changed files with 5 additions and 12 deletions

View file

@ -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 = {

View file

@ -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), []),
])