-
Notifications
You must be signed in to change notification settings - Fork 34
feat:add new secret resolver to modules #231
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
betinacosta
wants to merge
21
commits into
feat/new-secret-resolver
Choose a base branch
from
feat/add-new-secret-resolver-to-modules
base: feat/new-secret-resolver
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
21 commits
Select commit
Hold shift + click to select a range
c64c28f
feat: adapt secret resolver for customization
betinacosta 3ba3a4d
wip: use new secrets resolver
betinacosta 1ccf218
refactor: rollback on destination implementation
betinacosta 2b75d63
refactor: reorg of secret resolver
betinacosta ea5d782
refactor: update tests
betinacosta 159a771
refactor: update userguide
betinacosta 98aa8a0
refactor: add docstring
betinacosta 1410c18
refactor: removes extra space
betinacosta 65f346c
refactor: apply pr review skill comments
betinacosta dde8df7
refactor: add new sr to adms
betinacosta 237bef2
refactor: add new sr to agent_memory
betinacosta 6915909
refactor: add new sr to destination
betinacosta c5e48c2
refactor: add new sr to adms
betinacosta f21f903
refactor: add new sr to agent memory
betinacosta 84aff29
refactor: add new sr to print service
betinacosta 6ae1b3d
refactor: add new sr to auditlog
betinacosta cc69142
refactor: add new sr to data anonymization
betinacosta cebc44d
refactor: add new sr to objectstore
betinacosta dccd068
refactor: add new sr to dms
betinacosta 8c7398f
refactor: add new sr to destination
betinacosta e4aefc2
refactor: fix unit tests imports
betinacosta 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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 |
|---|---|---|
| @@ -1,26 +1,64 @@ | ||
| """ | ||
| Secret resolver: load configuration/secrets from mounted files or environment variables | ||
| Secret resolver: load configuration/secrets from mounted files or environment variables. | ||
|
|
||
| Usage: | ||
| from dataclasses import dataclass, field | ||
| from sap_cloud_sdk.secret_resolver import read_from_mount_and_fallback_to_env_var | ||
| Built-in resolvers and chain builder:: | ||
|
|
||
| @dataclass | ||
| class MyConfig: | ||
| username: str = field(metadata={"secret": "username"}) | ||
| password: str = field(metadata={"secret": "password"}) | ||
| endpoint: str = "http://localhost" | ||
| from sap_cloud_sdk.core.secret_resolver import ( | ||
| MountResolver, | ||
| EnvVarResolver, | ||
| ChainedResolver, | ||
| ) | ||
|
|
||
| # Build a chain explicitly | ||
| resolver = ChainedResolver([MountResolver(), EnvVarResolver()]) | ||
| resolver.resolve("destination", "default", binding) | ||
|
|
||
| Legacy function-based API (still supported):: | ||
|
|
||
| from sap_cloud_sdk.core.secret_resolver import read_from_mount_and_fallback_to_env_var | ||
|
|
||
| cfg = MyConfig() | ||
| read_from_mount_and_fallback_to_env_var( | ||
| base_volume_mount="/etc/secrets/appfnd", | ||
| base_var_name="CLOUD_SDK_CFG", | ||
| module="objectstore", | ||
| module="destination", | ||
| instance="default", | ||
| target=cfg | ||
| target=binding, | ||
| ) | ||
| """ | ||
|
|
||
| from .resolver import read_from_mount_and_fallback_to_env_var, resolve_base_mount | ||
| from sap_cloud_sdk.core.secret_resolver.resolver import ( | ||
| read_from_mount_and_fallback_to_env_var, | ||
| ) | ||
| from sap_cloud_sdk.core.secret_resolver._resolvers import ( | ||
| Resolver, | ||
| ChainedResolver, | ||
| ) | ||
|
|
||
| from sap_cloud_sdk.core.secret_resolver.mount_resolver import ( | ||
| MountResolver, | ||
| resolve_base_mount, | ||
| ) | ||
| from sap_cloud_sdk.core.secret_resolver.env_resolver import EnvVarResolver | ||
|
|
||
| from sap_cloud_sdk.core.secret_resolver.sdk_config import ( | ||
| SdkConfig, | ||
| configure, | ||
| get_sdk_config, | ||
| get_resolver, | ||
| ) | ||
|
|
||
| __all__ = ["read_from_mount_and_fallback_to_env_var", "resolve_base_mount"] | ||
| __all__ = [ | ||
| # Class-based API | ||
| "Resolver", | ||
| "MountResolver", | ||
| "EnvVarResolver", | ||
| "ChainedResolver", | ||
| # Global configuration | ||
| "SdkConfig", | ||
| "configure", | ||
| "get_sdk_config", | ||
| "get_resolver", | ||
| # Legacy function-based API | ||
| "read_from_mount_and_fallback_to_env_var", | ||
| "resolve_base_mount", | ||
| ] |
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,32 @@ | ||
| """Utilities for mapping dataclass fields to secret store keys.""" | ||
|
|
||
| from typing import Any, Dict, Tuple | ||
| from dataclasses import fields, is_dataclass | ||
|
|
||
|
|
||
| def _get_field_map(target: Any) -> dict[str, tuple[str, type]]: | ||
| """ | ||
| Build a mapping from secret key -> (attribute_name, attribute_type) for a dataclass instance. | ||
|
|
||
| Priority: | ||
| 1. Use field.metadata["secret"] if present as the key | ||
| 2. Fallback to the lowercase dataclass field name | ||
| Only string-typed fields are supported. | ||
| """ | ||
| if not is_dataclass(target) or isinstance(target, type): | ||
| raise TypeError("target must be a dataclass instance") | ||
|
|
||
| mapping: Dict[str, Tuple[str, type]] = {} | ||
| for f in fields(target): | ||
| # Only support string fields for secrets (consistent with Go SDK) | ||
| # Allow plain 'str' annotations; reject others to keep behavior predictable | ||
| if f.type is not str: | ||
| raise TypeError( | ||
| f"target field '{f.name}' is not a string (only str fields are supported)" | ||
| ) | ||
| key = f.metadata.get("secret") if hasattr(f, "metadata") else None | ||
| if key and isinstance(key, str) and key.strip(): | ||
| mapping[key] = (f.name, f.type) | ||
| else: | ||
| mapping[f.name.lower()] = (f.name, f.type) | ||
| return mapping |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this encapsulation is not needed. We could also have an central enum for module names if we need it, instead of magic strings. What do you think?