Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement activedirectory.rotate_credentials and ldap.rotate_static_credentials #1161

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions hvac/api/secrets_engines/active_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,18 @@ def generate_credentials(self, name, mount_point=DEFAULT_MOUNT_POINT):
return self._adapter.get(
url=api_path,
)

def rotate_credentials(self, name, mount_point=DEFAULT_MOUNT_POINT):
"""This endpoint triggers a force rotate LDAP password for the associated account

:param name: Specifies the name of the role to request credentials from.
:type name: str | unicode
:param mount_point: Specifies the place where the secrets engine will be accessible (default: ad).
:type mount_point: str | unicode
:return: The response of the request.
:rtype: requests.Response
"""
api_path = utils.format_url("/v1/{}/rotate-role/{}", mount_point, name)
return self._adapter.post(
url=api_path,
)
15 changes: 15 additions & 0 deletions hvac/api/secrets_engines/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,18 @@ def generate_static_credentials(self, name, mount_point=DEFAULT_MOUNT_POINT):
return self._adapter.get(
url=api_path,
)

def rotate_static_credentials(self, name, mount_point=DEFAULT_MOUNT_POINT):
"""This endpoint triggers a force rotate LDAP password for the associated account

:param name: Specifies the name of the role to request credentials from.
:type name: str | unicode
:param mount_point: Specifies the place where the secrets engine will be accessible (default: ldap).
:type mount_point: str | unicode
:return: The response of the request.
:rtype: requests.Response
"""
api_path = utils.format_url("/v1/{}/rotate-role/{}", mount_point, name)
return self._adapter.post(
url=api_path,
)
28 changes: 28 additions & 0 deletions tests/unit_tests/api/secrets_engines/test_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,34 @@ def test_generate_static_credentials(
second=response,
)

@parameterized.expand(
[
("default mount point", DEFAULT_MOUNT_POINT),
("custom mount point", "other-ldap-tree"),
]
)
def test_rotate_static_credentials(self, test_label, mount_point, requests_mocker):
expected_status_code = 204
role_name = "hvac"
mock_url = "http://localhost:8200/v1/{mount_point}/rotate-role/{name}".format(
mount_point=mount_point,
name=role_name,
)
requests_mocker.register_uri(
method="POST",
url=mock_url,
status_code=expected_status_code,
)
ldap = Ldap(adapter=JSONAdapter())
response = ldap.rotate_static_credentials(
name=role_name,
mount_point=mount_point,
)
self.assertEqual(
first=expected_status_code,
second=response.status_code,
)

@parameterized.expand(
[
("default mount point", DEFAULT_MOUNT_POINT),
Expand Down