[Bug] SecretsManager get function supports env_var pararmeters.#3201
[Bug] SecretsManager get function supports env_var pararmeters.#32010yukali0 wants to merge 1 commit intoflyteorg:masterfrom
Conversation
|
Thank you for opening this pull request! 🙌 These tips will help get your PR across the finish line:
|
Code Review Agent Run Status
|
Code Review Agent Run Status
|
Code Review Agent Run #2389d5Actionable Suggestions - 1
Review Details
|
Changelist by BitoThis pull request implements the following key changes.
|
flytekit/core/context_manager.py
Outdated
| if os.path.exists(fpath): | ||
| with open(fpath, encode_mode) as f: | ||
| return f.read().strip() | ||
| env_vars = ",".join([k for k in filter(None, (group_env_var, env_var))]) |
There was a problem hiding this comment.
The variable group_env_var might be undefined when reaching line 433. If none of the environment prefixes in the loop produces a valid group_env_var (e.g., when the loop is not entered or when env_prefixes is empty), then group_env_var will be undefined when constructing the env_vars string. Consider initializing group_env_var to None at the beginning of the function.
Code suggestion
Check the AI-generated fix before applying
@@ -401,0 +402 @@
+ group_env_var: Optional[str] = None,
Code Review Run #2389d5
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
Code Review Agent Run Status
|
Code Review Agent Run #98d23dActionable Suggestions - 0Review Details
|
|
/review |
Code Review Agent Run #f74fd8Actionable Suggestions - 1
Review Details
|
flytekit/core/context_manager.py
Outdated
| raise ValueError( | ||
| f"Please make sure to add secret_requests=[Secret(group={group}, key={key})] in @task. Unable to find secret for key {key} in group {group} " | ||
| f"in Env Var:{env_var} and FilePath: {fpath}" | ||
| f"in Env Var:{env_var}, {group_env_var} and FilePath: {fpath}" |
There was a problem hiding this comment.
The error message now includes both env_var and group_env_var, but group_env_var might be undefined if the code path doesn't go through the loop at lines 415-422. This could potentially lead to a reference error.
Code suggestion
Check the AI-generated fix before applying
| f"in Env Var:{env_var}, {group_env_var} and FilePath: {fpath}" | |
| f"in Env Var:{env_var}{', ' + group_env_var if group_env_var is not None else ''} and FilePath: {fpath}" |
Code Review Run #f74fd8
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
Signed-off-by: yuteng <a08h0283@gmail.com>
|
/review |
Code Review Agent Run #ba9449Actionable Suggestions - 0Review Details
|
Code Review Agent Run #21673eActionable Suggestions - 0Review Details
|
Tracking issue
flyteorg/flyte#
Why are the changes needed?
In flytekit secretsManager, it will check whether the secret exist in an env var "" or in a file "/etc/secrets//".
In flytekit secret, create a env "MY_SECRET" when setting "env_var=MY_SECRET" parameters.
SecretManager won't find it with naming rule with "".
What changes were proposed in this pull request?
Adding env_var pararmeters in secreateManager get function.
Initially, secretManager search the secret with following orders.
In this PR, its order will be
2 . env_var
How was this patch tested?
make test
os.environ["LOCAL_ENV_VAR"] = "value" assert sec.get(group="group", key="key2", env_var="LOCAL_ENV_VAR") == "value" assert sec.get(key="key", env_var="LOCAL_ENV_VAR") == "value" assert sec.get(env_var="LOCAL_ENV_VAR") == "value"Setup process
Screenshots
Check all the applicable boxes
Related PRs
Docs link
Summary by Bito
This PR fixes a bug in SecretsManager by adjusting secret lookup order and adding an optional 'env_var' parameter. It includes renaming and reordering variables in the context_manager module with updated type annotations. The changes enhance reliability and clarity of secret management in flytekit.Unit tests added: True
Estimated effort to review (1-5, lower is better): 1