diff --git a/executor/python_executor/credential.py b/executor/python_executor/credential.py index e190345..299cd7a 100644 --- a/executor/python_executor/credential.py +++ b/executor/python_executor/credential.py @@ -1,24 +1,29 @@ from typing import Any, Dict from oocana import InputHandleDef class CredentialInput: - def __init__(self, type: str, value: str): + def __init__(self, type: str, id: str): self.type = type - self.value = value + self.id = id def generate_credential_input(credential_path: str) -> CredentialInput | None: """Generate a CredentialInput from a credential path string. - The credential path should be in the format `${{OO_CREDENTIAL:type,id}}`. If the format is incorrect, + The credential path should be in the format `${{OO_CREDENTIAL:type,name,id}}`. If the format is incorrect, the function returns None. """ if not (credential_path.startswith("${{OO_CREDENTIAL:") and credential_path.endswith("}}")): + # logger warning("Credential path format is incorrect. Expected to start with '${{OO_CREDENTIAL:' and end with '}}'.") + return None + + if credential_path.count(",") != 2: + # logger warning("Credential path format is incorrect. Expected exactly two commas.") return None credential_path = credential_path.removeprefix("${{OO_CREDENTIAL:").removesuffix("}}") if credential_path: try: - type, id = credential_path.split(",", maxsplit=1) + type, _name, id = credential_path.split(",", maxsplit=2) return CredentialInput(type, id) except ValueError: return None diff --git a/executor/tests/test_credential.py b/executor/tests/test_credential.py index 6b59317..d030f84 100644 --- a/executor/tests/test_credential.py +++ b/executor/tests/test_credential.py @@ -3,7 +3,7 @@ from oocana import InputHandleDef from typing import cast -ORIGIN_VALUE = "Custom,credential_id" +ORIGIN_VALUE = "Custom,credential_name,credential_id" class TestCredential(unittest.TestCase): @@ -33,7 +33,7 @@ def test_replace_credential(self): cred_input = v.get("c") self.assertIsInstance(cred_input, CredentialInput) self.assertEqual(cred_input.type, "Custom") - self.assertEqual(cred_input.value, "credential_id") + self.assertEqual(cred_input.id, "credential_id") def test_credential_without_content_media(self): @@ -70,20 +70,20 @@ def test_credential_in_other_string(self): def test_generate_credential_input_valid(self): """Test valid credential input generation""" - result = generate_credential_input("${{OO_CREDENTIAL:AWS,my_credential_id}}") + result = generate_credential_input("${{OO_CREDENTIAL:AWS,my_credential_name,my_credential_id}}") self.assertIsInstance(result, CredentialInput) result = cast(CredentialInput, result) self.assertEqual(result.type, "AWS") - self.assertEqual(result.value, "my_credential_id") + self.assertEqual(result.id, "my_credential_id") def test_generate_credential_input_invalid_format(self): """Test invalid credential input format""" # Missing prefix - result = generate_credential_input("AWS,my_credential_id") + result = generate_credential_input("AWS,my_credential_name,my_credential_id") self.assertIsNone(result) # Missing suffix - result = generate_credential_input("${{OO_CREDENTIAL:AWS,my_credential_id") + result = generate_credential_input("${{OO_CREDENTIAL:AWS,my_credential_name,my_credential_id") self.assertIsNone(result) # Wrong prefix @@ -98,5 +98,9 @@ def test_generate_credential_input_invalid_format(self): result = generate_credential_input("${{OO_CREDENTIAL:AWS}}") self.assertIsNone(result) + # Only two parameters (missing third) + result = generate_credential_input("${{OO_CREDENTIAL:AWS,my_credential}}") + self.assertIsNone(result) + if __name__ == '__main__': unittest.main() \ No newline at end of file