Skip to content

Commit

Permalink
Add URL encoding to support slashes in repo names.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctslater committed Nov 12, 2024
1 parent ba68946 commit 3d81b66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions python/lsst/production/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,37 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from flask import Flask, render_template
import urllib.parse
from werkzeug.routing import BaseConverter

from . import tractTable, logs, bokeh, cache, images


class UrlConverter(BaseConverter):

part_isolating = False
regex = ".*?"

def to_python(self, value):
print(value)
return urllib.parse.unquote(value)

def to_url(self, value):
return urllib.parse.quote_plus(value)

def create_app():
app = Flask(
"production-tools",
)
app.url_map.converters['url'] = UrlConverter

app.register_blueprint(logs.bp)
app.register_blueprint(tractTable.bp)
app.register_blueprint(bokeh.bp)
app.register_blueprint(cache.bp)
app.register_blueprint(images.bp)


@app.route("/")
def index():
return render_template("index.html", tools=["metrics", "logs", "bokeh"])
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/production/tools/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def dataId(repo, collection, plot_name, data_id):
return send_file(image, mimetype="image/png")


@bp.route("/uuid/<repo>/<uuid>")
@bp.route("/uuid/<url:repo>/<uuid>")
def index(repo, uuid):

if repo not in REPO_NAMES:
return {'error': 'Invalid repo'}, 400
return {"error": f"Invalid repo {repo}"}, 400

butler = get_butler_map(repo)
dataset_ref = butler.get_dataset(DatasetId(uuid))
Expand Down

0 comments on commit 3d81b66

Please sign in to comment.