Skip to content

Commit 5db1ff4

Browse files
authored
Merge pull request #503 from atlanhq/APP-5372
APP-5372: Added validation checks for `CredentialClient.Creator()`
2 parents 16ff849 + 91d227d commit 5db1ff4

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

pyatlan/client/credential.py

+5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ def creator(self, credential: Credential, test: bool = True) -> CredentialRespon
4646
(`False`) before creation, defaults to `True`.
4747
:returns: A CredentialResponse instance.
4848
:raises ValidationError: If the provided `credential` is invalid.
49+
:raises InvalidRequestError: If `test` is `False` and the credential contains a `username` or `password`.
4950
"""
51+
52+
if not test and any((credential.username, credential.password)):
53+
raise ErrorCode.UNABLE_TO_CREATE_CREDENTIAL.exception_with_parameters()
54+
5055
raw_json = self._client._call_api(
5156
api=CREATE_CREDENTIALS.format_path_with_params(),
5257
query_params={"testCredential": test},

pyatlan/errors.py

+7
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,13 @@ class ErrorCode(Enum):
615615
"Check the details of the server's message to correct your request.",
616616
InvalidRequestError,
617617
)
618+
UNABLE_TO_CREATE_CREDENTIAL = (
619+
400,
620+
"ATLAN-PYTHON-400-071",
621+
"Credentials cannot include a `username` or `password` when `test` is `False`.",
622+
"Set `test` to `True` or remove `username` and `password`.",
623+
InvalidRequestError,
624+
)
618625
AUTHENTICATION_PASSTHROUGH = (
619626
401,
620627
"ATLAN-PYTHON-401-000",

tests/unit/test_credential_client.py

+27
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,33 @@ def test_creator_success(
356356
assert response.level is None
357357

358358

359+
@pytest.mark.parametrize(
360+
"credential_data",
361+
[
362+
(
363+
Credential(
364+
name="test-name",
365+
description="test-desc",
366+
connector_config_name="test-ccn",
367+
connector="test-conn",
368+
connector_type="test-ct",
369+
auth_type="test-at",
370+
host="test-host",
371+
port=123,
372+
username="test-user",
373+
password="test-password",
374+
extra={"some": "value"},
375+
)
376+
),
377+
],
378+
)
379+
def test_cred_creator_with_test_false_with_username_password(
380+
credential_data, client: CredentialClient
381+
):
382+
with pytest.raises(Exception, match="ATLAN-PYTHON-400-071"):
383+
client.creator(credential=credential_data, test=False)
384+
385+
359386
@pytest.mark.parametrize("test_guid", [[123], set(), dict()])
360387
def test_cred_purge_by_guid_wrong_params_raises_validation_error(
361388
test_guid, client: CredentialClient

0 commit comments

Comments
 (0)