Skip to content

Commit

Permalink
Merge pull request #33 from clear-street/awheelock/sc-58933/gestalt-a…
Browse files Browse the repository at this point in the history
…dd-read-from-role-functionality

Add support for not nested data in response
  • Loading branch information
adisunw authored Jun 1, 2023
2 parents 948ea23 + aa3ccfb commit e5c0fa1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ jobs:
VAULT_TOKEN: "myroot"
run: |
pytest -s --cov=gestalt tests/*.py
codecov
- name: Typecheck with mypy
run: |
# run mypy strict mode on gestalt
Expand Down
2 changes: 1 addition & 1 deletion gestalt/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get(self, key: str, path: str, filter: str) -> Any:
dynamic_token = ("dynamic", response['lease_id'],
response['lease_duration'])
self.dynamic_token_queue.put_nowait(dynamic_token)
requested_data = response["data"]["data"]
requested_data = response["data"].get("data", response["data"])
except hvac.exceptions.InvalidPath:
raise RuntimeError(
"Gestalt Error: The secret path or mount is set incorrectly")
Expand Down
2 changes: 1 addition & 1 deletion requirements.test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mypy==0.910
mypy-extensions==0.4.3
pytest==6.1.0
pytest-cov==2.8.1
codecov==2.0.16
pytest-mock==3.2.0
hvac>=1.0.2,<1.1.0
types-requests==2.25.2
types-PyYAML==5.4.6
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def readme():
reqs_list = list(map(lambda x: x.rstrip(), reqs))

setup(name='gestalt-cfg',
version='3.1.1',
version='3.2.0',
description='A sensible configuration library for Python',
long_description=readme(),
long_description_content_type="text/markdown",
Expand Down
46 changes: 46 additions & 0 deletions tests/test_gestalt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,43 @@
import os
import gestalt
import hvac
import requests


class MockSession(requests.Session):
def request(self, *_, **__):
resp = {
'request_id': '230f5e67-e55d-bdae-bd24-c7bc13c1a3e9',
'lease_id': '',
'renewable': False,
'lease_duration': 0,
'data': {
'last_vault_rotation': '2023-05-31T14:24:41.724285249Z',
'password': 'foo',
'rotation_period': 60,
'ttl': 0,
'username': 'foo'
},
'wrap_info': None,
'warnings': None,
'auth': None
}
return MockResponse(resp, 200)


class MockResponse:
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
self.ok = True

def json(self):
return self.json_data


@pytest.fixture
def mock_db_role_request(mocker):
mocker.patch("requests.Session", MockSession)


# Testing member function
Expand Down Expand Up @@ -575,6 +612,15 @@ def test_nest_key_for_vault(env_setup, nested_setup):
assert secret_slack == "random-token"


def test_read_no_nest_db_role(env_setup, mock_db_role_request):
g = gestalt.Gestalt()
g.add_config_file("./tests/testvault/testsfdynamic.json")
g.configure_provider("vault", Vault(role=None, jwt=None))
g.build_config()
secret_username = g.get_string("snowflake.username")
assert secret_username == "foo"


def test_set_vault_key(env_setup, nested_setup):
g = gestalt.Gestalt()
g.configure_provider("vault", Vault(role=None, jwt=None))
Expand Down
3 changes: 3 additions & 0 deletions tests/testvault/testsfdynamic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"snowflake": "ref+vault://database/creds/my-role#"
}

0 comments on commit e5c0fa1

Please sign in to comment.