wrappers icon indicating copy to clipboard operation
wrappers copied to clipboard

Allow api_key_name for Hubspot

Open daviddripps opened this issue 9 months ago • 3 comments

Bug report

I tried to submit this as a PR, but I got a 403. Nothing in the CONTRIBUTING documentation was helpful. I'll just drop the diff here for someone else to pick up and land.

Describe the bug

In order to use env vars across different environments in a Supabase FDW, you have to reference the Vault secret by name. This adds the ability to specify api_key_name in the Hubspot similar to the Stripe FDW.

To Reproduce

diff --git a/wasm-wrappers/fdw/hubspot_fdw/src/lib.rs b/wasm-wrappers/fdw/hubspot_fdw/src/lib.rs
index 101976b..239212a 100644
--- a/wasm-wrappers/fdw/hubspot_fdw/src/lib.rs
+++ b/wasm-wrappers/fdw/hubspot_fdw/src/lib.rs
@@ -219,12 +219,15 @@ impl Guest for HubspotFdw {
         // get foreign server options
         let opts = ctx.get_options(OptionsType::Server);
         this.base_url = opts.require_or("api_url", "https://api.hubapi.com/crm/v3");
-        let api_key = match opts.get("api_key") {
-            Some(key) => key,
-            None => {
-                let key_id = opts.require("api_key_id")?;
-                utils::get_vault_secret(&key_id).unwrap_or_default()
-            }
+
+        // Get API key in order of preference: api_key -> api_key_id -> api_key_name
+        let api_key = if let Some(key) = opts.get("api_key") {
+            key
+        } else if let Some(id) = opts.get("api_key_id") {
+            utils::get_vault_secret(&id).unwrap_or_default()
+        } else {
+            let key_name = opts.require("api_key_name")?;
+            utils::get_vault_secret_by_name(&key_name).unwrap_or_default()
         };
 
         // HubSpot API authentication

Expected behavior

I should be able to specify api_key_name to the Hubspot FDW server.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

Add any other context about the problem here.

daviddripps avatar Mar 22 '25 06:03 daviddripps

I tried to submit this as a PR, but I got a 403.

Could you please elaborate when you got a 403, i.e. which action failed for you?

Nothing in the CONTRIBUTING documentation was helpful.

We'd love to improve the docs if you can point out what is missing.

imor avatar Mar 25 '25 05:03 imor

I got the 403 while trying to create a remote branch in the repo. CLI output below.

david@Davids-M1-MacBook-Pro wrappers % git push --set-upstream origin feat/hubspot-api-key-name
remote: Permission to supabase/wrappers.git denied to daviddripps.
fatal: unable to access 'https://github.com/supabase/wrappers.git/': The requested URL returned error: 403

CONTRIBUTING.md directs me to https://fdw.dev/contributing/core/. There's nothing in that documentation regarding requesting access to the repo or submitting PRs, which is what I was trying to do.

daviddripps avatar Mar 25 '25 21:03 daviddripps

@daviddripps the contributing doc assumes basic familiarity with the Github pull request flow. You don't have permissions to push code to the https://github.com/supabase/wrappers.git/ repo directly. The usual flow for contributing to the a repo on Github is to first create a fork which in your case would create a repo under your name: https://github.com/daviddripps/wrappers.git/. You will have permissions to push to your own fork. You should push your changes in a branch in your fork then open a PR. The whole flow is described in much more detail in this doc: https://gist.github.com/Chaser324/ce0505fbed06b947d962. Hope this helps.

imor avatar Mar 26 '25 06:03 imor