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
a5573350
Unverified
Commit
a5573350
authored
2 years ago
by
Noah Moss
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor GeoJSON URL fetching logic (#25816)
* disable following redirects * add type hint
parent
cdc53287
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/api/geojson.clj
+17
-12
17 additions, 12 deletions
src/metabase/api/geojson.clj
with
17 additions
and
12 deletions
src/metabase/api/geojson.clj
+
17
−
12
View file @
a5573350
(
ns
metabase.api.geojson
(
:require
[
clojure.java.io
:as
io
]
(
:require
[
clj-http.client
:as
http
]
[
clojure.java.io
:as
io
]
[
compojure.core
:refer
[
GET
]]
[
metabase.api.common
:as
api
]
[
metabase.api.common.validation
:as
validation
]
...
...
@@ -9,7 +10,8 @@
[
ring.util.codec
:as
codec
]
[
ring.util.response
:as
response
]
[
schema.core
:as
s
])
(
:import
[
java.net
InetAddress
URL
]
(
:import
java.io.BufferedReader
[
java.net
InetAddress
URL
]
org.apache.commons.io.input.ReaderInputStream
))
(
defsetting
custom-geojson-enabled
...
...
@@ -101,6 +103,17 @@
(
setting/set-value-of-type!
:json
:custom-geojson
new-value
)))
:visibility
:public
)
(
defn-
read-url-and-respond
"Reads the provided URL and responds with the contents as a stream."
[
url
respond
]
(
with-open
[
^
BufferedReader
reader
(
if-let
[
resource
(
io/resource
url
)]
(
io/reader
resource
)
(
:body
(
http/get
url
{
:as
:reader
:redirect-strategy
:none
})))
is
(
ReaderInputStream.
reader
)]
(
respond
(
->
(
response/response
is
)
(
response/content-type
"application/json"
)))))
(
api/defendpoint-async
GET
"/:key"
"Fetch a custom GeoJSON file as defined in the `custom-geojson` setting. (This just acts as a simple proxy for the
file specified for `key`)."
...
...
@@ -110,11 +123,7 @@
(
raise
(
ex-info
(
tru
"Custom GeoJSON is not enabled"
)
{
:status-code
400
})))
(
if-let
[
url
(
get-in
(
custom-geojson
)
[(
keyword
key
)
:url
])]
(
try
(
with-open
[
reader
(
io/reader
(
or
(
io/resource
url
)
url
))
is
(
ReaderInputStream.
reader
)]
(
respond
(
->
(
response/response
is
)
(
response/content-type
"application/json"
))))
(
read-url-and-respond
url
respond
)
(
catch
Throwable
_e
(
raise
(
ex-info
(
tru
"GeoJSON URL failed to load"
)
{
:status-code
400
}))))
(
raise
(
ex-info
(
tru
"Invalid custom GeoJSON key: {0}"
key
)
{
:status-code
400
}))))
...
...
@@ -132,11 +141,7 @@
(
when-not
(
valid-geojson-url?
decoded-url
)
(
throw
(
ex-info
(
invalid-location-msg
)
{
:status-code
400
})))
(
try
(
with-open
[
reader
(
io/reader
(
or
(
io/resource
decoded-url
)
decoded-url
))
is
(
ReaderInputStream.
reader
)]
(
respond
(
->
(
response/response
is
)
(
response/content-type
"application/json"
))))
(
read-url-and-respond
decoded-url
respond
)
(
catch
Throwable
_
(
throw
(
ex-info
(
tru
"GeoJSON URL failed to load"
)
{
:status-code
400
}))))
(
catch
Throwable
e
...
...
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