feat: allow vault secret lookup by name in _id options#591
feat: allow vault secret lookup by name in _id options#591burmecia merged 2 commits intosupabase:mainfrom
Conversation
Change `get_vault_secret()` to fall back to name-based lookup when the input is not a valid UUID. This allows all FDW `*_id` options (e.g. `conn_string_id`, `api_key_id`, `bearer_token_id`) to accept either a vault secret UUID or a human-readable name, making configuration easier: ```sql -- Before: only UUID worked OPTIONS (conn_string_id 'a1b2c3d4-e5f6-...') -- Now: name also works OPTIONS (conn_string_id 'my_mysql_prod') ``` Since vault secret names are human-readable labels that cannot be valid UUIDs, there is no ambiguity. Existing UUID-based usage is completely unaffected.
|
@coderabbitai review |
|
There is already a get_vault_secret_by_name() function, should we use that instead? |
|
Good point! Yes, Err(_) => get_vault_secret_by_name(secret_id),The motivation for putting the auto-detection in
The alternative would be adding a Happy to take a different approach if you prefer keeping |
Summary
get_vault_secret()to fall back toget_vault_secret_by_name()when the input is not a valid UUID*_idoptions (conn_string_id,api_key_id,bearer_token_id,sa_key_id, etc.) now accept either a vault secret UUID or a human-readable nameMotivation
Currently, to reference a vault secret you must use the UUID returned by
vault.create_secret():CREATE SERVER mysql_server FOREIGN DATA WRAPPER mysql_wrapper OPTIONS (conn_string_id 'a1b2c3d4-e5f6-7890-abcd-ef1234567890');UUIDs are hard to remember and make DDL less readable. With this change, you can use the human-readable name:
How it works
get_vault_secret()triesUuid::try_parse()first:idorkey_id(existing behavior, unchanged)get_vault_secret_by_name()(lookup byname)Since vault secret names are human-readable labels that cannot be valid UUID format, there is no ambiguity.
Scope
Only one file changed:
supabase-wrappers/src/utils.rs(1 function, ~10 lines changed). All native and Wasm FDWs that callget_vault_secret()automatically benefit without any code changes.Test plan
Existing UUID-based vault lookups are already covered by FDW integration tests. The name fallback uses the existing
get_vault_secret_by_name()function which is already tested through Stripe FDW'sapi_key_nameoption. No new test infrastructure is needed since this is a simple routing change based onUuid::try_parse().