Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
3e63220d
Commit
3e63220d
authored
Nov 16, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] String escaping in PostgREST configuration
parent
95ce719a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
mkconf.sh
tools/mkconf.sh
+9
-3
No files found.
tools/mkconf.sh
View file @
3e63220d
...
...
@@ -9,6 +9,11 @@ escape_ini () {
echo
-n
"
$1
"
|
sed
-e
's/[/&\]/\\&/g'
}
# See http://hackage.haskell.org/package/configurator-0.3.0.0/docs/Data-Configurator.html
escape_pgrest
()
{
echo
-n
"
$1
"
|
sed
-e
's/[$]/$$/g'
|
sed
-e
's/["\]/\\\\\\&/g'
|
sed
-e
's/[/&]/\\&/g'
}
# Adapted from https://gist.github.com/cdown/1163649
escape_url
()
{
local
_LC_COLLATE
=
$LC_COLLATE
...
...
@@ -113,16 +118,17 @@ if $DB_ACCESS && query "$PGREST_USER" "$PGREST_PASS" ""; then
fi
fi
PGREST_
DB_URI
=
"postgres://"
$(
escape_url
"
$PGREST_USER
"
)
":"
$(
escape_url
"
$PGREST_PASS
"
)
"@"
$(
escape_url
"
$DB_HOST
"
)
":"
$(
escape_url
"
$DB_PORT
"
)
"/"
$(
escape_url
"
$DB_NAME
"
)
DB_URI
=
"postgres://"
$(
escape_url
"
$PGREST_USER
"
)
":"
$(
escape_url
"
$PGREST_PASS
"
)
"@"
$(
escape_url
"
$DB_HOST
"
)
":"
$(
escape_url
"
$DB_PORT
"
)
"/"
$(
escape_url
"
$DB_NAME
"
)
# Escape variables
PGREST_DB_URI
=
$(
escape_pgrest
"
$DB_URI
"
)
PGREST_SECRET_KEY
=
$(
escape_pgrest
"
$SECRET_KEY
"
)
SECRET_KEY
=
$(
escape_ini
"
$SECRET_KEY
"
)
DB_HOST
=
$(
escape_ini
"
${
DB_HOST
:-
127
.0.0.1
}
"
)
DB_PORT
=
$(
escape_ini
"
${
DB_PORT
:-
5432
}
"
)
DB_NAME
=
$(
escape_ini
"
$DB_NAME
"
)
DB_USER
=
$(
escape_ini
"
$DB_USER
"
)
DB_PASS
=
$(
escape_ini
"
$DB_PASS
"
)
PGREST_DB_URI
=
$(
escape_ini
"
$PGREST_DB_URI
"
)
echo
"▸ Generate configuration file from
$GARGANTEXT_TEMPLATE
..."
sed
-E
-e
"s/[{]DEBUG[}]/
$DEBUG
/g"
\
...
...
@@ -138,7 +144,7 @@ sed -E -e "s/[{]DEBUG[}]/$DEBUG/g" \
echo
"▸ Generate configuration file for PostgREST from
$POSTGREST_TEMPLATE
..."
sed
-E
-e
"s/[{]DB_URI[}]/
$PGREST_DB_URI
/g"
\
-e
"s/[{]SECRET_KEY[}]/
$SECRET_KEY
/g"
\
-e
"s/[{]SECRET_KEY[}]/
$
PGREST_
SECRET_KEY
/g"
\
"
$POSTGREST_TEMPLATE
"
>
"
$POSTGREST_CONF
"
\
&&
echo
"PostgREST configuration written successfully in
$POSTGREST_CONF
."
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment