Skip to content

Commit

Permalink
Merge pull request #41 from dacort/feature/cn-endpoints
Browse files Browse the repository at this point in the history
Add support for cn regions
  • Loading branch information
dacort authored Aug 2, 2020
2 parents c9f38b8 + c7c682e commit 9e4c872
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/metabase/driver/athena.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@

;;; ---------------------------------------------- sql-jdbc.connection -----------------------------------------------

(defn endpoint-for-region
"Returns the endpoint URL for a specific region"
[region]
(cond
(str/starts-with? region "cn-") ".amazonaws.com.cn"
:else ".amazonaws.com"))

(defmethod sql-jdbc.conn/connection-details->spec :athena [_ {:keys [region access_key secret_key s3_staging_dir workgroup db], :as details}]
(-> (merge
{:classname "com.simba.athena.jdbc.Driver"
:subprotocol "awsathena"
:subname (str "//athena." region ".amazonaws.com:443")
:subname (str "//athena." region (endpoint-for-region region) ":443")
:user access_key
:password secret_key
:s3_staging_dir s3_staging_dir
Expand Down
21 changes: 21 additions & 0 deletions test_unit/metabase/driver/athena_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns metabase.driver.athena-test
(:require [clojure.test :refer :all]
[metabase.driver.athena :refer [endpoint-for-region]]))

(deftest endpoint
(testing "AWS Endpoint URL"
(is (=
".amazonaws.com"
(endpoint-for-region "us-east-1")))

(is (=
".amazonaws.com"
(endpoint-for-region "us-west-2")))

(is (=
".amazonaws.com.cn"
(endpoint-for-region "cn-north-1")))

(is (=
".amazonaws.com.cn"
(endpoint-for-region "cn-northwest-1")))))

0 comments on commit 9e4c872

Please sign in to comment.