Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Set enablePutGet as a Snowflake connection property (#77731)

Arik Aronov611ef3690b38
diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj
index 20eaffff391..6a8bea5c524 100644
--- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj
+++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj
@@ -1,6 +1,6 @@
(ns metabase.driver.snowflake
"Snowflake Driver."
- (:refer-clojure :exclude [select-keys empty? not-empty mapv])
+ (:refer-clojure :exclude [select-keys not-empty mapv])
(:require
[buddy.core.codecs :as codecs]
[clojure.java.jdbc :as jdbc]
@@ -38,7 +38,7 @@
[metabase.util.json :as json]
[metabase.util.log :as log]
[metabase.util.malli :as mu]
- [metabase.util.performance :refer [empty? mapv not-empty select-keys]]
+ [metabase.util.performance :refer [mapv not-empty select-keys]]
[ring.util.codec :as codec])
(:import
(java.io File)
@@ -233,12 +233,11 @@
(and (not use-password) password-details)
(conj password-details)))))
-(defn- set-put-get [additional-options]
- (cond (empty? additional-options) "enablePutGet=false"
- (re-find #"(?i)enablePutGet=" additional-options) (str/replace additional-options
- #"enablePutGet=[^&]+"
- "enablePutGet=false")
- :else (str additional-options "&enablePutGet=false")))
+(defn- normalize-additional-options [additional-options]
+ (when-not (str/blank? additional-options)
+ (not-empty
+ (str/join "&" (remove #(re-matches #"(?i)enablePutGet(=.*)?" %)
+ (str/split additional-options #"&"))))))
(defmethod sql-jdbc.conn/connection-details->spec :snowflake
[_ {:keys [account additional-options host use-hostname password use-password], :as details}]
@@ -292,10 +291,11 @@
resolve-private-key
(dissoc :host :port :timezone)))
(sql-jdbc.common/handle-additional-options (update details
- :additional-options set-put-get))
+ :additional-options normalize-additional-options))
;; Role is not respected when used as connection property if connection string is present with private key
;; file. Hence it is moved to connection url. https://github.com/metabase/metabase/issues/43600
- (maybe-add-role-to-spec-url details))))
+ (maybe-add-role-to-spec-url details)
+ (assoc :enablePutGet "false"))))
(mu/defn- database-type->base-type
[database-type :- string?
@@ -424,8 +424,8 @@
(defmethod driver/insert-into! :snowflake
[driver db-id table-name column-names values]
- ;; Snowflake's fast bulk path (`PUT` + `COPY INTO` from a stage) is unavailable because [[set-put-get]]
- ;; enforces `enablePutGet=false` on every connection (#73578), so use the generic multi-row `INSERT`.
+ ;; Snowflake's fast bulk path (`PUT` + `COPY INTO` from a stage) is unavailable because Metabase's
+ ;; Snowflake connections set `enablePutGet=false`, so use the generic multi-row `INSERT`.
((get-method driver/insert-into! :sql-jdbc)
driver db-id table-name column-names
(map #(mapv temporal-bind->string %) values)))
diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
index eae9eadac64..ea35a0155dc 100644
--- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
+++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj
@@ -170,19 +170,20 @@
(assoc :host alternative-host)
(assoc :use-hostname use-hostname))]
(sql-jdbc.conn/connection-details->spec :snowflake details))))
- true nil "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"
- true "" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"
- true " " "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"
- true "snowflake.example.com/" "//snowflake.example.com/?enablePutGet=false"
- true "snowflake.example.com" "//snowflake.example.com/?enablePutGet=false"
- false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"
- false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"
- false "snowflake.example.com/" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"
- false "snowflake.example.com" "//ls10467.us-east-2.aws.snowflakecomputing.com/?enablePutGet=false"))
+ true nil "//ls10467.us-east-2.aws.snowflakecomputing.com/"
+ true "" "//ls10467.us-east-2.aws.snowflakecomputing.com/"
+ true " " "//ls10467.us-east-2.aws.snowflakecomputing.com/"
+ true "snowflake.example.com/" "//snowflake.example.com/"
+ true "snowflake.example.com" "//snowflake.example.com/"
+ false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/"
+ false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/"
+ false "snowflake.example.com/" "//ls10467.us-east-2.aws.snowflakecomputing.com/"
+ false "snowflake.example.com" "//ls10467.us-east-2.aws.snowflakecomputing.com/"))
(testing "Unsafe options are removed"
- (let [details (assoc details :additional-options "enablePutGet=true")
- spec (sql-jdbc.conn/connection-details->spec :snowflake details)]
- (is (re-find #"enablePutGet=false" (:subname spec)))))
+ (doseq [opts [nil "enablePutGet=true"]]
+ (let [spec (sql-jdbc.conn/connection-details->spec :snowflake (assoc details :additional-options opts))]
+ (is (= "false" (:enablePutGet spec)))
+ (is (not (re-find #"(?i)enablePutGet" (str (:subname spec))))))))
(testing "Application parameter is set to identify Metabase connections"
(is (= "Metabase_Metabase"
(:application (sql-jdbc.conn/connection-details->spec :snowflake details)))))))
diff --git a/src/metabase/permissions_rest/api.clj b/src/metabase/permissions_rest/api.clj
index f52d5cea1fd..63d03ad18ea 100644
--- a/src/metabase/permissions_rest/api.clj
+++ b/src/metabase/permissions_rest/api.clj
@@ -212,7 +212,7 @@
"Fetch the details for a certain permissions group."
[{:keys [id]} :- [:map
[:id ms/PositiveInt]]]
- (perms/check-group-manager id)
+ (perms/check-manager-of-group id)
(api/check-404
(some-> (t2/select-one :model/PermissionsGroup :id id)
(t2/hydrate :members)