Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API for downloading LDML files from projects that allow sharing WS data #1309

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions hgweb/command-runner.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

# Define the list of allowed commands
allowed_commands=("verify" "tip" "tipdate" "reposizeinkb" "wesaylexentrycount" "lexentrycount" "flexprojectid" "flexwritingsystems" "flexmodelversion" "recover" "healthz" "invalidatedircache")
allowed_commands=("verify" "tip" "tipdate" "ldmlzip" "reposizeinkb" "wesaylexentrycount" "lexentrycount" "flexprojectid" "flexwritingsystems" "flexmodelversion" "recover" "healthz" "invalidatedircache")

# Get the project code and command name from the URL
IFS='/' read -ra PATH_SEGMENTS <<< "$PATH_INFO"
project_code="${PATH_SEGMENTS[1]}"
command_name="${PATH_SEGMENTS[2]}"

# Ensure the project code and command name are safe to use in a shell command
if [[ ! $project_code =~ ^[a-z0-9][a-z0-9-]*$ ]] || [[ ! $command_name =~ ^[a-zA-Z0-9]+$ ]]; then
if [[ ! "$project_code" =~ ^[a-z0-9][a-z0-9-]*$ ]] || [[ ! "$command_name" =~ ^[a-zA-Z0-9]+$ ]]; then
echo "Content-type: text/plain"
echo "Status: 400 Bad Request"
echo ""
Expand Down Expand Up @@ -38,8 +38,22 @@ if [[ $command_name == "healthz" ]]; then
exit 0
fi

if [[ $command_name == "ldmlzip" ]]; then
# Preflight check: ldml zip access is only allowed if LexiconSettings.plsx contains addToSldr="true"
if (chg -R /var/hg/repos/$first_char/$project_code cat -r tip CachedSettings/SharedSettings/LexiconSettings.plsx | grep '<WritingSystems' | grep 'addToSldr="true"'); then
rmunn marked this conversation as resolved.
Show resolved Hide resolved
CONTENT_TYPE="application/zip"
else
echo "Content-type: text/plain"
echo "Status: 403 Forbidden"
echo ""
echo "Forbidden. Project does not allow sharing writing systems with SLDR or project does not exist"
exit 1
fi
fi

CONTENT_TYPE="${CONTENT_TYPE:-text/plain}"
# Start outputting the result right away so the HTTP connection won't be timed out
echo "Content-type: text/plain"
echo "Content-type: ${CONTENT_TYPE}"
echo ""

# Run the hg command, simply output to stdout
Expand Down Expand Up @@ -90,6 +104,11 @@ case $command_name in
du -ks .hg | cut -f1
;;

ldmlzip)
# -p '.' so that resulting zipfiles will *not* have the project name in the file paths
chg archive -p '.' -t zip -r tip -I 'CachedSettings/WritingSystemStore/*.ldml' -
;;

verify)
# Env var PYTHONUNBUFFERED required for commands like verify and recover, so that output can stream back to the project page
export PYTHONUNBUFFERED=1
Expand Down
Loading