Skip to content
Snippets Groups Projects
Unverified Commit c02eee85 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran Committed by GitHub
Browse files

Merge pull request #6942 from metabase/return-400-for-bad-metastore-token

Setting bad MetaStore token should return 400, not 500
parents e6bef552 ecd443f7
Branches
Tags
No related merge requests found
......@@ -2,25 +2,50 @@ import React, { Component } from "react";
import ReactRetinaImage from "react-retina-image";
import { t } from "c-3po";
import SettingsInput from "./SettingInput";
import cx from "classnames";
const PREMIUM_EMBEDDING_STORE_URL =
"https://store.metabase.com/product/embedding";
const PREMIUM_EMBEDDING_SETTING_KEY = "premium-embedding-token";
const PremiumTokenInput = ({ token, onChangeSetting }) => (
<div className="mb3">
<h3 className="mb1">
{token
? t`Premium embedding enabled`
: t`Enter the token you bought from the Metabase Store`}
</h3>
<SettingsInput
onChange={value => onChangeSetting(PREMIUM_EMBEDDING_SETTING_KEY, value)}
setting={{ value: token }}
autoFocus={!token}
/>
</div>
);
class PremiumTokenInput extends Component {
state = {
errorMessage: "",
};
render() {
const { token, onChangeSetting } = this.props;
const { errorMessage } = this.state;
let message;
if (errorMessage) {
message = errorMessage;
} else if (token) {
message = t`Premium embedding enabled`;
} else {
message = t`Enter the token you bought from the Metabase Store`;
}
return (
<div className="mb3">
<h3 className={cx("mb1", { "text-danger": errorMessage })}>
{message}
</h3>
<SettingsInput
onChange={async value => {
try {
await onChangeSetting(PREMIUM_EMBEDDING_SETTING_KEY, value);
} catch (error) {
this.setState({ errorMessage: error.data });
}
}}
setting={{ value: token }}
autoFocus={!token}
/>
</div>
);
}
}
const PremiumExplanation = ({ showEnterScreen }) => (
<div>
......
......@@ -47,15 +47,15 @@
;; slurp will throw a FileNotFoundException for 404s, so in that case just return an appropriate
;; 'Not Found' message
(catch java.io.FileNotFoundException e
{:valid false, :status "invalid token: not found."})
{:valid false, :status "Unable to validate token."})
;; if there was any other error fetching the token, log it and return a generic message about the
;; token being invalid. This message will get displayed in the Settings page in the admin panel so
;; we do not want something complicated
(catch Throwable e
(log/error "Error fetching token status:" e)
{:valid false, :status "there was an error checking whether this token was valid."})))
{:valid false, :status "There was an error checking whether this token was valid."})))
fetch-token-status-timeout-ms
{:valid false, :status "token validation timed out."})))
{:valid false, :status "Token validation timed out."})))
(defn- check-embedding-token-is-valid* [token]
(when (s/check ValidToken token)
......@@ -86,10 +86,14 @@
"Token for premium embedding. Go to the MetaStore to get yours!"
:setter (fn [new-value]
;; validate the new value if we're not unsetting it
(when (seq new-value)
(check-embedding-token-is-valid new-value)
(log/info "Token is valid."))
(setting/set-string! :premium-embedding-token new-value)))
(try
(when (seq new-value)
(check-embedding-token-is-valid new-value)
(log/info "Token is valid."))
(setting/set-string! :premium-embedding-token new-value)
(catch Throwable e
(log/error e "Error setting premium embedding token")
(throw (ex-info (.getMessage e) {:status-code 400}))))))
(defn hide-embed-branding?
"Should we hide the 'Powered by Metabase' attribution on the embedding pages? `true` if we have a valid premium
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment