Skip to content

Commit db7778d

Browse files
committed
initial commit
1 parent f6e0710 commit db7778d

File tree

6 files changed

+224
-0
lines changed

6 files changed

+224
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
All you need you do is drop the driver and netsuite JDBC NQjc.jar in your `/path/to/metabase/plugins/` directory.
2+
3+
## Building the driver
4+
5+
## Prereq: Install the Clojure CLI
6+
7+
Make sure you have the `clojure` CLI version `1.10.3.933` or newer installed; you can check this with `clojure
8+
--version`. Follow the instructions at https://clojure.org/guides/getting_started if you need to install a
9+
newer version.
10+
11+
## Prereq: Download JDBC jar
12+
13+
You need \~/NetSuiteJDBCDrivers/NQjc.jar from https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_3994742720.html but also the oracle one even if though it's unused just because we inherit that driver
14+
15+
## Prereq: Configure paths in `~/.clojure/deps.edn`
16+
17+
See https://github.com/metabase/sudoku-driver/blob/master/README.md#hacking-on-the-driver-locally
18+
19+
## Build it
20+
21+
```sh
22+
clojure -X:build :project-dir "\"$(pwd)\""
23+
```
24+
25+
will create `target/netsuite.metabase-driver.jar`. Copy this file and NQjc.jar to `/path/to/metabase/plugins/` and restart your
26+
server, and the driver will show up.
27+
28+
## Testing
29+
30+
Sample driver stuff might work https://github.com/metabase/sample-driver#interactive-testing
31+
32+
e.g. this does work:
33+
34+
MB_NETSUITE_DRIVER_TEST_PLUGIN_MANIFEST_PATH=/path/to/metabase-netsuite-driver/resources/metabase-plugin.yaml clojure -M:dev:ee:ee-dev:drivers:drivers-dev:user:trace:deps-alpha:user/metabase-netsuite-driver:nrepl

deps.edn

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{:paths
2+
["src" "resources"]
3+
4+
; Old version may have previously been publicly available but doesn't seem to be there anymore:
5+
; :mvn/repos
6+
; {"Mulesoft" {:url "https://repository.mulesoft.org/nexus/content/repositories/public/"}}
7+
; :deps
8+
; {com.netsuite.jdbc/NQjc {:mvn/version "7.20.50-atlassian-1"}}
9+
10+
; Developed with 8.10.136.0 from https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_3994742720.html
11+
:deps
12+
{com.netsuite.jdbc/NQjc {:local/root "../NetSuiteJDBCDrivers/NQjc.jar"}}
13+
14+
:aliases
15+
{:oss
16+
;; JDBC driver isn't GPL-compatible
17+
{:replace-deps {}
18+
:replace-paths ["src" "resources"]}
19+
20+
;; build the driver with clojure -X:build
21+
:build
22+
;; to avoid hardcoding these paths in the project-level deps file, an alias pointing to these extra-deps can be defined in user-specific ~/.clojure/deps.edn
23+
;; files instead; suppose we do so, and call it :metabase-core-deps, then we can simply add :metabase-core-deps to the build invocation above
24+
{:extra-deps {metabase/metabase-core {:local/root "../metabase"}
25+
metabase/build-drivers {:local/root "../metabase/bin/build-drivers"}}
26+
:exec-fn build-drivers.build-driver/build-driver!
27+
:exec-args {:driver :netsuite
28+
:project-dir "."
29+
:target-dir "./target"}}}}

resources/metabase-plugin.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
info:
2+
name: Metabase Netsuite Driver
3+
version: 1.0.0-SNAPSHOT
4+
description: Allows Metabase to connect to Netsuite databases.
5+
dependencies:
6+
- class: com.netsuite.jdbc.openaccess.OpenAccessDriver
7+
message: >
8+
Metabase requires the Netsuite JDBC driver in order to connect to Netsuite databases, but we can't ship it as part
9+
of Metabase due to licensing restrictions. See
10+
https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_3994742720.html for more details.
11+
driver:
12+
name: netsuite
13+
display-name: Netsuite
14+
lazy-load: true
15+
parent: oracle
16+
connection-properties:
17+
- host
18+
- merge:
19+
- port
20+
- default: 1708
21+
- name: account-id
22+
display-name: Netsuite Account ID
23+
- name: role-id
24+
display-name: Netsuite Role Id
25+
- user
26+
- password
27+
- cloud-ip-address-info
28+
- advanced-options-start
29+
- name: additional-options
30+
display-name: Additional JDBC options
31+
placeholder: StaticSchema=1
32+
required: false
33+
visible-if:
34+
advanced-options: true
35+
- default-advanced-options
36+
connection-properties-include-tunnel-config: true
37+
init:
38+
- step: load-namespace
39+
namespace: metabase.driver.netsuite
40+
- step: register-jdbc-driver
41+
class: com.netsuite.jdbc.openaccess.OpenAccessDriver

src/metabase/driver/netsuite.clj

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
(ns metabase.driver.netsuite
2+
(:require [clojure.java.jdbc :as jdbc]
3+
[clojure.string :as str]
4+
[clojure.tools.logging :as log]
5+
[honeysql.core :as hsql]
6+
[honeysql.format :as hformat]
7+
[java-time :as t]
8+
[metabase.config :as config]
9+
[metabase.driver :as driver]
10+
[metabase.driver.common :as driver.common]
11+
[metabase.driver.impl :as driver.impl]
12+
[metabase.driver.sql :as sql]
13+
[metabase.driver.sql-jdbc.common :as sql-jdbc.common]
14+
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
15+
[metabase.driver.sql-jdbc.execute :as sql-jdbc.execute]
16+
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync]
17+
[metabase.driver.sql.query-processor :as sql.qp]
18+
[metabase.driver.sql.util :as sql.u]
19+
[metabase.driver.sql.util.unprepare :as unprepare]
20+
[metabase.models.secret :as secret]
21+
[metabase.util :as u]
22+
[metabase.util.honeysql-extensions :as hx]
23+
[metabase.util.i18n :refer [trs]])
24+
(:import [java.sql Connection ResultSet Types]
25+
[java.time Instant OffsetDateTime ZonedDateTime]))
26+
27+
(driver/register! :netsuite, :parent :oracle)
28+
29+
(defn- netsuite-spec [details spec host port account-id role-id]
30+
(-> (assoc spec :subname (str "//" host
31+
":" port
32+
";ServerDataSource=NetSuite2.com;encrypted=1;CustomProperties=(AccountID=" account-id
33+
";RoleID=" role-id ");NegotiateSSLClose=false"))
34+
(sql-jdbc.common/handle-additional-options details)))
35+
36+
(defmethod sql-jdbc.conn/connection-details->spec :netsuite
37+
[_ {:keys [host port account-id role-id]
38+
:or {host "localhost", port 1708}
39+
:as details}]
40+
(let [spec {:classname "com.netsuite.jdbc.openaccess.OpenAccessDriver", :subprotocol "ns"}
41+
finish-fn (partial netsuite-spec details)]
42+
(-> (merge spec details)
43+
(dissoc :host :port :account-id :role-id)
44+
(finish-fn host port account-id role-id))))
45+
46+
(defmethod driver/can-connect? :netsuite
47+
[driver details]
48+
(sql-jdbc.conn/can-connect? driver details))
49+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(ns metabase.driver.netsuite-test
2+
"Tests for specific behavior of the Netsuite driver."
3+
(:require [clojure.java.jdbc :as jdbc]
4+
[clojure.string :as str]
5+
[clojure.test :refer :all]
6+
[honeysql.core :as hsql]
7+
[metabase.api.common :as api]
8+
[metabase.driver :as driver]
9+
[metabase.driver.netsuite :as netsuite]
10+
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
11+
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync]
12+
[metabase.driver.sql.query-processor :as sql.qp]
13+
[metabase.driver.util :as driver.u]
14+
[metabase.models.database :refer [Database]]
15+
[metabase.models.field :refer [Field]]
16+
[metabase.models.table :refer [Table]]
17+
[metabase.public-settings.premium-features :as premium-features]
18+
[metabase.query-processor :as qp]
19+
[metabase.query-processor-test :as qp.test]
20+
[metabase.query-processor-test.order-by-test :as qp-test.order-by-test] ; used for one SSL connectivity test
21+
[metabase.sync :as sync]
22+
metabase.sync.util
23+
[metabase.test :as mt]
24+
[metabase.test.data.interface :as tx]
25+
[metabase.test.data.netsuite :as netsuite.tx]
26+
[metabase.test.data.sql :as sql.tx]
27+
[metabase.test.data.sql.ddl :as ddl]
28+
[metabase.test.util :as tu]
29+
[metabase.util :as u]
30+
[metabase.util.honeysql-extensions :as hx]
31+
[toucan.db :as db]
32+
[toucan.util.test :as tt])
33+
(:import java.util.Base64))
34+
35+
(deftest connection-details->spec-test
36+
(doseq [[^String message expected-spec details]
37+
[["You should be able to connect"
38+
{:classname "com.netsuite.jdbc.openaccess.OpenAccessDriver"
39+
:subprotocol "ns"
40+
:subname "//1.2.3.4:5678;ServerDataSource=NetSuite2.com;encrypted=1;CustomProperties=(AccountID=910;RoleID=1112);NegotiateSSLClose=false"}
41+
{:host "1.2.3.4"
42+
:port 5678
43+
:account-id 910
44+
:role-id 1112}]
45+
]]
46+
(let [actual-spec (sql-jdbc.conn/connection-details->spec :netsuite details)]
47+
(is (= (dissoc expected-spec)
48+
(dissoc actual-spec))
49+
message))))
50+

test/metabase/test/data/nesuite.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(ns metabase.test.data.netsuite
2+
(:require [clojure.java.jdbc :as jdbc]
3+
[clojure.set :as set]
4+
[clojure.string :as str]
5+
[honeysql.format :as hformat]
6+
[medley.core :as m]
7+
[metabase.db :as mdb]
8+
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
9+
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync]
10+
[metabase.models :refer [Database Table]]
11+
[metabase.test.data.impl :as data.impl]
12+
[metabase.test.data.interface :as tx]
13+
[metabase.test.data.sql :as sql.tx]
14+
[metabase.test.data.sql-jdbc :as sql-jdbc.tx]
15+
[metabase.test.data.sql-jdbc.execute :as execute]
16+
[metabase.test.data.sql-jdbc.load-data :as load-data]
17+
[metabase.test.data.sql.ddl :as ddl]
18+
[metabase.util :as u]
19+
[toucan.db :as db]))
20+
21+
(sql-jdbc.tx/add-test-extensions! :netsuite)

0 commit comments

Comments
 (0)