Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
2cc51e10
Commit
2cc51e10
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
postgres now handles SSL in a way that one could consider sensible
parent
4173538b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/driver/postgres.clj
+19
-32
19 additions, 32 deletions
src/metabase/driver/postgres.clj
with
19 additions
and
32 deletions
src/metabase/driver/postgres.clj
+
19
−
32
View file @
2cc51e10
...
...
@@ -77,25 +77,18 @@
;; ## CONNECTION
(
defn-
connection-details->connection-spec
[
details-map
]
(
kdb/postgres
(
rename-keys
details-map
{
:dbname
:db
})))
(
def
^
:private
^
:const
ssl-params
{
:ssl
true
:sslmode
"require"
:sslfactory
"org.postgresql.ssl.NonValidatingFactory"
})
; HACK Why enable SSL if we disable certificate validation?
(
def
^
:private
ssl-supported?
"Determine wheter we can make an SSL connection.
Do that by checking whether we can connect with SSL params assoced with DETAILS-MAP.
This call is memoized."
(
memoize
(
fn
[
details-map
]
(
try
(
i/can-connect-with-details?
driver
(
merge
details-map
ssl-params
))
; only calls connection-details->connection-spec
true
(
catch
Throwable
e
(
log/info
(
.getMessage
e
))
false
)))))
"Params to include in the JDBC connection spec for an SSL connection."
{
:ssl
true
:sslmode
"require"
:sslfactory
"org.postgresql.ssl.NonValidatingFactory"
})
; HACK Why enable SSL if we disable certificate validation?
(
defn-
connection-details->connection-spec
[{
:keys
[
use-ssl
]
:as
details-map
}]
(
->
details-map
(
merge
(
when
use-ssl
ssl-params
))
(
rename-keys
{
:dbname
:db
})
kdb/postgres
))
(
defn-
database->connection-details
[
database
]
(
let
[
details
(
-<>>
database
:details
:conn_str
; get conn str like "password=corvus user=corvus ..."
...
...
@@ -104,20 +97,14 @@
(
let
[[
k
v
]
(
s/split
pair
#
"="
)]
{(
keyword
k
)
v
})))
(
reduce
conj
{}))
; combine into single dict
{
:keys
[
host
dbname
port
host
]}
details
details-map
(
->
details
(
assoc
:host
host
; e.g. "localhost"
:make-pool?
false
:db-type
:postgres
:port
(
Integer/parseInt
port
))
(
rename-keys
{
:dbname
:db
}))]
; convert :port to an Integer
;; Determine whether we should use an SSL connection, and assoc relevant params if so.
;; If config option mb-postgres-ssl is true, the always use SSL;
;; otherwise, call ssl-supported? to try and see if we can make an SSL connection.
(
cond->
details-map
(
or
(
config/config-bool
:mb-postgres-ssl
)
(
ssl-supported?
details-map
))
(
merge
ssl-params
))))
{
:keys
[
host
port
]}
details
]
(
->
details
(
assoc
:host
host
:make-pool?
false
:db-type
:postgres
; What purpose is this serving?
:use-ssl
(
:ssl
(
:details
database
))
:port
(
Integer/parseInt
port
))
(
rename-keys
{
:dbname
:db
}))))
;; ## QP
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment