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
ca013100
Commit
ca013100
authored
10 years ago
by
Sameer Al-Sakran
Browse files
Options
Downloads
Patches
Plain Diff
partial validation
parent
5bb8d486
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
resources/frontend_client/app/setup/setup.controllers.js
+1
-1
1 addition, 1 deletion
resources/frontend_client/app/setup/setup.controllers.js
src/metabase/api/meta/db.clj
+17
-5
17 additions, 5 deletions
src/metabase/api/meta/db.clj
src/metabase/util.clj
+30
-0
30 additions, 0 deletions
src/metabase/util.clj
with
48 additions
and
6 deletions
resources/frontend_client/app/setup/setup.controllers.js
+
1
−
1
View file @
ca013100
...
...
@@ -111,7 +111,7 @@ SetupControllers.controller('SetupConnection', ['$scope', '$routeParams', '$loca
}
// Validate the connection string
Metabase
.
validate_connection
(
database
,
function
(
result
){
Metabase
.
validate_connection
(
$scope
.
connection
,
function
(
result
){
if
(
newConnection
)
{
Metabase
.
db_create
(
database
,
success
,
error
);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/metabase/api/meta/db.clj
+
17
−
5
View file @
ca013100
(
ns
metabase.api.meta.db
"/api/meta/db endpoints."
(
:require
[
compojure.core
:refer
[
GET
POST
PUT
DELETE
]]
[
clojure.tools.logging
:as
log
]
[
korma.core
:refer
:all
]
[
medley.core
:as
medley
]
[
metabase.api.common
:refer
:all
]
...
...
@@ -30,12 +31,23 @@
{
:timezones
metabase.models.common/timezones
:engines
driver/available-drivers
})
{{
:body
{}}
:body
}
;Stub function that will eventually validate a connection string
(
defendpoint
POST
"/validate"
[]
(
if
(
=
(
rand-int
2
)
1
)
{
:status
200
:body
{
:valid
true
}}
(
let
[
error-message
(
rand-nth
[
"Host not reachable"
"Invalid Port"
"Invalid User or Password"
])]
{
:status
400
:body
{
:valid
false
:message
error-message
}}
)))
(
defendpoint
POST
"/validate"
[
:as
{{
:keys
[
host
port
]}
:body
}]
(
require-params
host
port
)
(
log/debug
host
port
)
(
cond
(
not
(
u/host-up?
host
))
{
:status
400
:body
{
:valid
false
:message
"Host not reachable"
}}
(
not
(
u/host-port-up?
host
(
Integer.
port
)))
{
:status
400
:body
{
:valid
false
:message
"Invalid port"
}}
(
=
(
rand-int
2
)
1
)
{
:status
400
:body
{
:valid
false
:message
"Invalid User or Password"
}}
:else
{
:status
200
:body
{
:valid
true
}}
))
(
defendpoint
GET
"/:id"
[
id
]
(
->404
(
sel
:one
Database
:id
id
)
...
...
This diff is collapsed.
Click to expand it.
src/metabase/util.clj
+
30
−
0
View file @
ca013100
(
ns
metabase.util
"Common utility functions useful throughout the codebase."
(
:require
[
medley.core
:refer
:all
]
[
clojure.tools.logging
:as
log
]
[
clj-time.format
:as
time
]
[
clj-time.coerce
:as
coerce
]))
...
...
@@ -149,3 +150,32 @@
false
(
boolean
(
re-matches
#
"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
(
clojure.string/lower-case
v
)))))
(
import
'
(
java.io
IOException
)
'
(
java.net
Socket
)
'
(
java.net
InetSocketAddress
)
'
(
java.net
InetAddress
)
'
(
java.net
SocketTimeoutException
)
'
(
java.net
UnknownHostException
))
(
defn
host-port-up?
[
hostname
port
]
(
log/debug
"in host-port-up?"
hostname
port
)
(
let
[
sock-addr
(
InetSocketAddress.
hostname
port
)
timeout
5000
]
(
try
(
with-open
[
sock
(
Socket.
)]
(
.
sock
connect
sock-addr
timeout
)
true
)
(
catch
IOException
e
false
)
(
catch
SocketTimeoutException
e
false
)
(
catch
UnknownHostException
e
false
))))
(
defn
host-up?
[
hostname
]
(
let
[
host-addr
(
.
InetAddress
getByName
hostname
)
timeout
5000
]
(
try
(
.
host-addr
isReachable
timeout
)
(
catch
IOException
e
false
)
(
catch
SocketTimeoutException
e
false
)
(
catch
UnknownHostException
e
false
))))
\ No newline at end of file
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