diff --git a/docs/guide/deploy.md b/docs/guide/deploy.md index f504838b24..3b00de61cb 100644 --- a/docs/guide/deploy.md +++ b/docs/guide/deploy.md @@ -178,7 +178,9 @@ Then run the following script with the appropriate options: node tools/pipelines/register-es-pipelines.js register --host=http://localhost:9090 ``` -The `--host` option is used to point to the ElasticSearch instance. Additionally, the `--records-index` option can be used if the index containing the metadata records is not called `gn-records`. +The `--host` option is used to point to the ElasticSearch instance. +If ElasticSearch is secured, `--username` and `--password` can be used to pass HTTP Authentication. +Additionally, the `--records-index` option can be used if the index containing the metadata records is not called `gn-records`. ### Option B: Running a docker image diff --git a/tools/pipelines/register-es-pipelines.js b/tools/pipelines/register-es-pipelines.js index 31b0424de2..5acb18ccfd 100644 --- a/tools/pipelines/register-es-pipelines.js +++ b/tools/pipelines/register-es-pipelines.js @@ -9,6 +9,8 @@ program .command('register') .description('Register pipelines') .option('--host ', 'ElasticSearch host', 'http://localhost:9200') + .option('--username ', 'ElasticSearch user', '') + .option('--password ', 'ElasticSearch password', '') .option( '--records-index ', 'Name of the index used by GeoNetwork for records', @@ -17,7 +19,13 @@ program .action((options) => { const esUrl = options.host.replace(/\/$/, '') // remove trailing slash if any const recordsIndex = options.recordsIndex - registerPipelines(esUrl, recordsIndex) + const username = options.username + const password = options.password + const authHeader = + options.username && options.password + ? 'Basic ' + btoa(username + ':' + password) + : '' + registerPipelines(esUrl, recordsIndex, authHeader) }) program .command('clear') @@ -27,9 +35,17 @@ program 'ElasticSearch host, default is http://localhost:9090', 'http://localhost:9200' ) + .option('--username ', 'ElasticSearch user', '') + .option('--password ', 'ElasticSearch password', '') .action((options) => { const esUrl = options.host.replace(/\/$/, '') // remove trailing slash if any - clearPipelines(esUrl) + const username = options.username + const password = options.password + const authHeader = + options.username && options.password + ? 'Basic ' + btoa(username + ':' + password) + : '' + clearPipelines(esUrl, authHeader) }) program.parse(process.argv) @@ -129,13 +145,14 @@ for(int i = ctx.format.length - 1; i >= 0; i--) { ], } -async function registerPipeline(esHost, name, payload) { +async function registerPipeline(esHost, name, payload, authHeader) { console.log(`adding ${name} pipeline...`) await fetch(`${esHost}/_ingest/pipeline/${name}`, { method: 'PUT', body: JSON.stringify(payload), headers: { + Authorization: authHeader, 'Content-Type': 'application/json', }, }) @@ -150,11 +167,14 @@ async function registerPipeline(esHost, name, payload) { console.log(`${name} pipeline was successfully registered!`) } -async function clearPipeline(esHost, name) { +async function clearPipeline(esHost, name, authHeader) { console.log(`clearing ${name} pipeline...`) await fetch(`${esHost}/_ingest/pipeline/${name}`, { method: 'DELETE', + headers: { + Authorization: authHeader, + }, }) .then((resp) => resp.json()) .then((result) => { @@ -167,13 +187,14 @@ async function clearPipeline(esHost, name) { console.log(`${name} pipeline was successfully cleaned!`) } -async function setDefaultPipeline(esHost, recordsIndex, name) { +async function setDefaultPipeline(esHost, recordsIndex, name, authHeader) { console.log(`setting ${name} as default pipeline...`) await fetch(`${esHost}/${recordsIndex}/_settings`, { method: 'PUT', body: JSON.stringify({ 'index.default_pipeline': name }), headers: { + Authorization: authHeader, 'Content-Type': 'application/json', }, }) @@ -188,12 +209,14 @@ async function setDefaultPipeline(esHost, recordsIndex, name) { console.log(`${name} pipeline was successfully set as default!`) } -async function registerPipelines(esHost, recordsIndex) { +async function registerPipelines(esHost, recordsIndex, authHeader) { console.log('querying currently registered pipelines...') - const pipelines = await fetch(`${esHost}/_ingest/pipeline`).then((resp) => - resp.json() - ) + const pipelines = await fetch(`${esHost}/_ingest/pipeline`, { + headers: { + Authorization: authHeader, + }, + }).then((resp) => resp.json()) const names = Object.keys(pipelines) names.forEach((name) => { @@ -203,10 +226,15 @@ async function registerPipelines(esHost, recordsIndex) { }) console.log('') - await registerPipeline(esHost, 'geonetwork-ui', GEONETWORK_UI_PIPELINE) + await registerPipeline( + esHost, + 'geonetwork-ui', + GEONETWORK_UI_PIPELINE, + authHeader + ) console.log('') - await setDefaultPipeline(esHost, recordsIndex, 'geonetwork-ui') + await setDefaultPipeline(esHost, recordsIndex, 'geonetwork-ui', authHeader) } async function clearPipelines(esHost) {