Skip to content

Commit

Permalink
substitution regex
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx committed Nov 2, 2023
1 parent d894f18 commit 3cbe866
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions mod/provider/cloudfront.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module.exports = async ref => {

try {

const url = (ref.params?.url || ref).replace(/\{{1}(.+?)\}{1}/g,
matched => process.env[`SRC_${matched.replace(/\{{1}|\}{1}/g, '')}`] || matched)
// Subtitutes {*} with process.env.SRC_* key values.
const url = (ref.params?.url || ref).replace(/{(.*?)}/g,
matched => process.env[`SRC_${matched.replace(/(^{)|(}$)/g, '')}`])

const date = new Date(Date.now())
date.setDate(date.getDate() + 1);
Expand Down
5 changes: 3 additions & 2 deletions mod/provider/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const { join } = require('path')
module.exports = async ref => {
try {

const path = (ref.params?.url || ref).replace(/\{{1}(.+?)\}{1}/g,
matched => process.env[`SRC_${matched.replace(/\{{1}|\}{1}/g, '')}`] || matched)
// Subtitutes {*} with process.env.SRC_* key values.
const path = (ref.params?.url || ref).replace(/{(.*?)}/g,
matched => process.env[`SRC_${matched.replace(/(^{)|(}$)/g, '')}`])

const file = readFileSync(join(__dirname, `../../${path}`))

Expand Down
4 changes: 2 additions & 2 deletions mod/workspace/_workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ async function locale(req, res) {
return res.status(403).send('Role access denied.')
}

// Subtitutes ${*} in locale with process.env.SRC_* values.
// Subtitutes ${*} with process.env.SRC_* key values.
locale = JSON.parse(
JSON.stringify(locale).replace(/\$\{(.*?)\}/g,
matched => process.env[`SRC_${matched.replace(/\$|\{|\}/g, '')}`] || matched)
matched => process.env[`SRC_${matched.replace(/(^\${)|(}$)/g, '')}`])
)

// Check layer access.
Expand Down
4 changes: 2 additions & 2 deletions mod/workspace/getTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module.exports = async (template) => {
return template
}

// Substitute parameter in src string.
// Subtitutes ${*} with process.env.SRC_* key values.
template.src = template.src.replace(/\$\{(.*?)\}/g,
(matched) => process.env[`SRC_${matched.replace(/(^\${)|(}$)/g, '')}`]);
matched => process.env[`SRC_${matched.replace(/(^\${)|(}$)/g, '')}`]);


if (!Object.hasOwn(getFrom, template.src.split(':')[0])) {
Expand Down

0 comments on commit 3cbe866

Please sign in to comment.