-
Notifications
You must be signed in to change notification settings - Fork 5
feat(credentials): add referenced credential element management (#7850) #348
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
Open
Gabriel Pezé (gabriel-peze)
wants to merge
7
commits into
main
Choose a base branch
from
issue/7850
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
77a6339
feat(credentials): add credentials types and utils (#7850)
gabriel-peze 3564347
feat(credentials): increase coverage (#7850)
gabriel-peze 7fc7e2d
feat(credentials): add utils file (#7850)
gabriel-peze dfcf539
feat(credentials): refactor (#7850)
gabriel-peze 20d547d
feat(stratus): change default multiple value (#7850)
gabriel-peze 94a5ecb
feat(credentials): fix pr feedbacks (#7850)
gabriel-peze e0486b2
feat(credentials): fix black (#7850)
gabriel-peze File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from .types import CredentialType | ||
|
|
||
|
|
||
| def build_single_referenced_credential_element(provider_name: str): | ||
| from .utils import ( | ||
| build_single_referenced_credential_element as _build_single_referenced_credential_element, | ||
| ) | ||
|
|
||
| return _build_single_referenced_credential_element(provider_name) | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "CredentialType", | ||
| "build_single_referenced_credential_element", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """Credential reference types shared with the OpenAEV platform. | ||
|
|
||
| This enum is the Python mirror of the OpenAEV backend credential-type enum | ||
| used by credential secret references. Values must stay label-for-label in sync | ||
| with the platform so contracts can declare credential references without any | ||
| translation layer. | ||
| """ | ||
|
|
||
| from enum import Enum | ||
|
|
||
|
|
||
| class CredentialType(str, Enum): | ||
| IDENTITY = "IDENTITY" | ||
| CLOUD_AWS = "CLOUD_AWS" | ||
| CLOUD_AZURE = "CLOUD_AZURE" | ||
| CLOUD_GCP = "CLOUD_GCP" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Helpers centralizing how injectors declare credential-reference fields. | ||
|
|
||
| Injectors can call ``build_single_referenced_credential_element`` instead of | ||
| re-implementing provider-to-credential-type mapping in each project. This keeps | ||
| contract generation consistent across the Python ecosystem and aligns the | ||
| serialized contract payload with the OpenAEV platform's expected values. | ||
| """ | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from pyoaev.contracts.contract_config import ContractReferencedCredential | ||
| from pyoaev.credential.types import CredentialType | ||
|
|
||
| _PROVIDER_TO_CREDENTIAL_TYPE = { | ||
| "aws": CredentialType.CLOUD_AWS, | ||
| "eks": CredentialType.CLOUD_AWS, | ||
| "azure": CredentialType.CLOUD_AZURE, | ||
| "gcp": CredentialType.CLOUD_GCP, | ||
| } | ||
|
|
||
|
|
||
| def _resolve_credential_type(provider_name: str) -> Optional[CredentialType]: | ||
| normalized_provider = provider_name.casefold() | ||
| return _PROVIDER_TO_CREDENTIAL_TYPE.get(normalized_provider) | ||
|
|
||
|
|
||
| def build_single_referenced_credential_element( | ||
| provider_name: str, | ||
| ) -> ContractReferencedCredential: | ||
| """Build a credential-reference field for a provider-specific contract | ||
| with ``multiple`` value at ``False``. | ||
|
|
||
| This is the centralized entry point injectors should use when they need the | ||
| OpenAEV inject form to ask for one referenced credential. The helper keeps | ||
| provider-to-``CredentialType`` mapping consistent across injector projects. | ||
| """ | ||
|
|
||
| return ContractReferencedCredential( | ||
| credential_reference_type=_resolve_credential_type(provider_name), | ||
| multiple=False, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import json | ||
| import unittest | ||
|
|
||
| from pyoaev import utils | ||
| from pyoaev.contracts.contract_config import ( | ||
| ContractFieldKey, | ||
| ContractFieldType, | ||
| ContractReferencedCredential, | ||
| ) | ||
| from pyoaev.credential.types import CredentialType | ||
|
|
||
|
|
||
| def _serialize(field): | ||
| return json.loads(json.dumps(field, cls=utils.EnhancedJSONEncoder)) | ||
|
|
||
|
|
||
| class ContractReferencedCredentialTest(unittest.TestCase): | ||
| def test_defaults_match_platform_contract_expectations(self): | ||
| field = ContractReferencedCredential() | ||
| serialized = _serialize(field) | ||
|
|
||
| self.assertEqual(field.key, ContractFieldKey.CredentialReference.value) | ||
| self.assertEqual(field.label, "Select a credential reference") | ||
| self.assertTrue(field.mandatory) | ||
| self.assertTrue(field.multiple) | ||
| self.assertIsNone(field.credential_reference_type) | ||
| self.assertEqual(field.type, ContractFieldType.CredentialReference.value) | ||
| self.assertEqual(serialized["key"], "credential_reference") | ||
| self.assertEqual(serialized["type"], "credential-reference") | ||
| self.assertEqual(serialized["label"], "Select a credential reference") | ||
| self.assertTrue(serialized["mandatory"]) | ||
| self.assertTrue(serialized["multiple"]) | ||
| self.assertIsNone(serialized["credential_reference_type"]) | ||
|
|
||
| def test_explicit_credential_type_serializes_to_platform_label(self): | ||
| field = ContractReferencedCredential( | ||
| credential_reference_type=CredentialType.CLOUD_AZURE | ||
| ) | ||
|
|
||
| self.assertEqual(field.credential_reference_type, CredentialType.CLOUD_AZURE) | ||
| self.assertEqual(_serialize(field)["credential_reference_type"], "CLOUD_AZURE") | ||
|
|
||
| def test_identity_credential_type_serializes_to_platform_label(self): | ||
| field = ContractReferencedCredential( | ||
| credential_reference_type=CredentialType.IDENTITY | ||
| ) | ||
|
|
||
| self.assertEqual(field.credential_reference_type, CredentialType.IDENTITY) | ||
| self.assertEqual(_serialize(field)["credential_reference_type"], "IDENTITY") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import unittest | ||
|
|
||
| from pyoaev.credential import CredentialType as PublicCredentialType | ||
| from pyoaev.credential.types import CredentialType | ||
|
|
||
|
|
||
| class CredentialTypeTest(unittest.TestCase): | ||
| def test_every_value_matches_the_supported_platform_labels(self): | ||
| expected_labels = { | ||
| "IDENTITY", | ||
| "CLOUD_AWS", | ||
| "CLOUD_AZURE", | ||
| "CLOUD_GCP", | ||
| } | ||
| actual_labels = {member.value for member in CredentialType} | ||
| self.assertEqual(actual_labels, expected_labels) | ||
|
|
||
| def test_identity_wire_label(self): | ||
| self.assertEqual(CredentialType.IDENTITY.value, "IDENTITY") | ||
| self.assertEqual(CredentialType.IDENTITY, "IDENTITY") | ||
|
|
||
| def test_package_re_exports_credential_type(self): | ||
| self.assertIs(PublicCredentialType, CredentialType) | ||
|
|
||
| def test_aws_wire_label(self): | ||
| self.assertEqual(CredentialType.CLOUD_AWS.value, "CLOUD_AWS") | ||
| self.assertEqual(CredentialType.CLOUD_AWS, "CLOUD_AWS") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import json | ||
| import unittest | ||
|
|
||
| from pyoaev import utils | ||
| from pyoaev.contracts.contract_config import ContractReferencedCredential | ||
| from pyoaev.credential import ( | ||
| build_single_referenced_credential_element as public_build_single_referenced_credential_element, | ||
| ) | ||
| from pyoaev.credential.types import CredentialType | ||
| from pyoaev.credential.utils import build_single_referenced_credential_element | ||
|
|
||
|
|
||
| def _serialize(field): | ||
| return json.loads(json.dumps(field, cls=utils.EnhancedJSONEncoder)) | ||
|
|
||
|
|
||
| class CredentialUtilsTest(unittest.TestCase): | ||
| def test_aws_provider_maps_to_aws_credential_reference(self): | ||
| field = build_single_referenced_credential_element("aws") | ||
|
|
||
| self.assertIsInstance(field, ContractReferencedCredential) | ||
| self.assertEqual(field.credential_reference_type, CredentialType.CLOUD_AWS) | ||
|
|
||
| def test_eks_provider_maps_to_aws_credential_reference(self): | ||
| field = build_single_referenced_credential_element("eks") | ||
|
|
||
| self.assertEqual(field.credential_reference_type, CredentialType.CLOUD_AWS) | ||
|
|
||
| def test_azure_provider_maps_to_azure_credential_reference(self): | ||
| field = build_single_referenced_credential_element("azure") | ||
|
|
||
| self.assertEqual(field.credential_reference_type, CredentialType.CLOUD_AZURE) | ||
|
|
||
| def test_gcp_provider_maps_to_gcp_credential_reference(self): | ||
| field = build_single_referenced_credential_element("gcp") | ||
|
|
||
| self.assertEqual(field.credential_reference_type, CredentialType.CLOUD_GCP) | ||
|
|
||
| def test_provider_mapping_is_case_insensitive(self): | ||
| field = build_single_referenced_credential_element("AWS") | ||
|
|
||
| self.assertEqual(field.credential_reference_type, CredentialType.CLOUD_AWS) | ||
|
|
||
| def test_package_public_helper_builds_the_same_field(self): | ||
| field = public_build_single_referenced_credential_element("azure") | ||
|
|
||
| self.assertIsInstance(field, ContractReferencedCredential) | ||
| self.assertEqual(field.credential_reference_type, CredentialType.CLOUD_AZURE) | ||
| self.assertEqual(_serialize(field)["credential_reference_type"], "CLOUD_AZURE") | ||
| self.assertFalse(field.multiple) | ||
|
|
||
| def test_unknown_provider_leaves_credential_type_empty(self): | ||
| field = build_single_referenced_credential_element("openstack") | ||
|
|
||
| self.assertIsNone(field.credential_reference_type) | ||
| self.assertIsNone(_serialize(field)["credential_reference_type"]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.