Skip to content
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

set embedding-secret-key when embedding is enabled #40813

Merged
merged 2 commits into from
Apr 4, 2024

Conversation

npretto
Copy link
Member

@npretto npretto commented Mar 29, 2024

Note: this is stacked on top of a bunch of PRs from #40005

Description

In add new settings for embedding homepage I enable embedding when the user is interested in embedding, but I don't set the secret key.
This cause the embed modal to crash as it expects to find it.

The solution I attempted in this PR is to move the logic to set the secret key from the FE to the BE, on the setter of the setting, so that when the embedding is enabled, if no secret key is found, a new one is created.

I think this is a more robust solution now that we have two places to enable embedding.

How to verify

  • Do a setup of a new instance and answer that you're interested in embedding
  • if you go to the settings you should find the secret key populated

or

  • Do a setup saying you're interested in embedding
  • Enable embedding manually
  • You should also find the populated secret key for static embedding (as it's already on master from the FE)

Copy link

replay-io bot commented Mar 29, 2024

Status Complete ↗︎
Commit cad018c
Results
1 Failed
⚠️ 9 Flaky
2371 Passed

@npretto npretto force-pushed the embed-homepage-fix-secret-key-be branch from fd1556d to dda6cca Compare March 29, 2024 16:41
cy.request("PUT", "/api/setting/embedding-secret-key", {
value: METABASE_SECRET_KEY,
});
cy.request("PUT", "/api/setting/enable-embedding", { value: true }).then(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make sure we don't run into race conditions between the two calls, making the tests flaky

@npretto npretto changed the title [OPEN FOR E2E] set embedding-secret-key when embedding is enabled set embedding-secret-key when embedding is enabled Mar 29, 2024
@npretto npretto requested review from a team March 29, 2024 16:54
Comment on lines 30 to 31
(when (and new-value (str/blank? (setting/get :embedding-secret-key)))
(setting/set! :embedding-secret-key (crypto-random/hex 32)))
Copy link
Member

@noahmoss noahmoss Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general we prefer using the automatically-generated getter/setter functions for settings which are the same as the setting name, with a ! suffix for the setter.

Suggested change
(when (and new-value (str/blank? (setting/get :embedding-secret-key)))
(setting/set! :embedding-secret-key (crypto-random/hex 32)))
(when (and new-value (str/blank? (embedding-secret-key)))
(embedding-secret-key! (crypto-random/hex 32)))

(This assumes that embedding-secret-key is defined in the same namespace... if not you'll have to include the namespace as well.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @noahmoss, the IDE suggested to use :refer when importing, but I saw in other places we usually just import the namespace and do namespace/function so that' what I did in dca0965

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks good

Copy link
Member

@noahmoss noahmoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stamping BE change

@npretto npretto force-pushed the embed-homepage-dismiss branch 2 times, most recently from 31bda47 to 3faee3a Compare April 4, 2024 16:20
Base automatically changed from embed-homepage-dismiss to embed-homepage April 4, 2024 16:23
@npretto npretto force-pushed the embed-homepage-fix-secret-key-be branch from dca0965 to cad018c Compare April 4, 2024 16:28
@npretto npretto merged commit 1ff8d29 into embed-homepage Apr 4, 2024
75 of 76 checks passed
@npretto npretto deleted the embed-homepage-fix-secret-key-be branch April 4, 2024 16:30
Copy link
Contributor

@rafpaf rafpaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

deniskaber pushed a commit that referenced this pull request Apr 5, 2024
* create ui for the full embedding homepage, without any logic (#40251)

* wip ui for the full embedding homepage

* adds missing link + fix keys

* remove done TODO

* Update frontend/src/metabase/home/components/EmbedHomepage/InteractiveTabContent.tsx

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>

* destructure props in the function arguments

* rename customerFacingAnalyticsDocsUrl to analyticsDocsUrl

---------

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>

* add new settings for embedding homepage (#40455)

* remove old minimal version

* adds new embedding homepage settings and sets them at the end of the setup

* comment e2e test

* add tests for embedding homepage flags

* more tests

* remove unit tests related to old minimal version

* fixes flags descriptions

* :keyword for embedding-homepage

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>

* replace reloadSettings and refreshSettingsList with initializeSettings

* `value => value === true` -> `Boolean`

* toMatchObject -> toEqual for more strict tests

* remove useless undefined check for settings, the component is conditionally rendered based on a setting so it means they're loaded anyway

* fix: use :hidden as we changed the type to :keyword

* specifically check for the `embedding` feature in the tokenFeatures object instead of checking if any feature is active

* remove double \n

Co-authored-by: Noah Moss <32746338+noahmoss@users.noreply.github.com>

---------

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>
Co-authored-by: Noah Moss <32746338+noahmoss@users.noreply.github.com>

* connect settings to the embed homepage and show it (#40528)

* fix nested a warnings in browser console

* connect settings to the embed homepage and show it

* fix stories

* remove localStorage.clear() as we're not using it in the logic anymore

* dismiss without feedback for the embedding homepage (#40587)

* feat: add dismiss functionality to the embed homepage

* update setup e2e to check for the dismissal of embedding homepage

* use List from metabase/ui (#40638)

* set embedding-secret-key when embedding is enabled (#40813)

* set embedding-secret-key when embedding is enabled

* use "named" setters and getters as suggested by Noah

* Fix tests for ms1 after updating on master (#41069)

---------

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>
Co-authored-by: Noah Moss <32746338+noahmoss@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants