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
c1e97894
Commit
c1e97894
authored
8 years ago
by
Tom Robinson
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix-geojson-validation' of github.com:metabase/metabase into geojson-ci-fixes
parents
9ad05c48
31c7c498
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/api/geojson.clj
+28
-9
28 additions, 9 deletions
src/metabase/api/geojson.clj
with
28 additions
and
9 deletions
src/metabase/api/geojson.clj
+
28
−
9
View file @
c1e97894
(
ns
metabase.api.geojson
(
:require
[
cheshire.core
:as
json
]
(
:require
[
clojure.java.io
:as
io
]
[
cheshire.core
:as
json
]
[
compojure.core
:refer
[
defroutes
GET
]]
[
schema.core
:as
s
]
[
metabase.api.common
:refer
:all
]
[
metabase.models.setting
:refer
[
defsetting
]
,
:as
setting
]
[
metabase.util
:as
u
]))
(
defn-
valid-json?
"Does this URL-OR-RESOURCE point to valid JSON?
URL-OR-RESOURCE should be something that can be passed to `slurp`, like an HTTP URL or a `java.net.URL` (which is what `io/resource` returns below)."
[
url-or-resource
]
(
u/with-timeout
5000
(
json/parse-string
(
slurp
url-or-resource
)))
true
)
(
def
^
:private
valid-json-url?
(
defn-
valid-json-resource?
"Does this RELATIVE-PATH point to a valid local JSON resource? (RELATIVE-PATH is something like \"app/charts/us-states.json\".)"
[
relative-path
]
(
when-let
[
^
java.net.URI
uri
(
u/ignore-exceptions
(
java.net.URI.
relative-path
))]
(
when-not
(
.isAbsolute
uri
)
(
valid-json?
(
io/resource
(
str
"frontend_client"
uri
))))))
(
defn-
valid-json-url?
"Is URL a valid HTTP URL and does it point to valid JSON?"
[
url
]
(
when
(
u/is-url?
url
)
(
valid-json?
url
)))
(
def
^
:private
valid-json-url-or-resource?
"Check that remote URL points to a valid JSON file, or throw an exception.
Since the remote file isn't likely to change, this check isn't repeated for URLs that have already succeded;
if the check fails, an exception is thrown (thereby preventing memoization)."
(
memoize
(
fn
[
url
]
(
assert
(
u/is-url?
url
)
(
str
"Invalid URL: "
url
))
(
u/with-timeout
5000
(
json/parse-string
(
slurp
url
)))
true
)))
(
memoize
(
fn
[
url-or-resource-path
]
(
or
(
valid-json-url?
url-or-resource-path
)
(
valid-json-resource?
url-or-resource-path
)
(
throw
(
Exception.
(
str
"Invalid JSON URL or resource: "
url-or-resource-path
)))))))
(
def
^
:private
CustomGeoJSON
{
s/Keyword
{
:name
s/Str
:url
(
s/constrained
s/Str
valid-json-url?
"URL must point to a valid JSON file."
)
:url
(
s/constrained
s/Str
valid-json-url
-or-resource
?
"URL must point to a valid JSON file."
)
:region_key
(
s/maybe
s/Str
)
:region_name
(
s/maybe
s/Str
)}})
...
...
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