Skip to content

Commit

Permalink
trifid: allow using the CLI without the need of a config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicm67 committed Mar 1, 2024
1 parent f52e978 commit 1f2e258
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-dancers-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trifid": minor
---

Allow to start Trifid using the CLI without requiring a path to a configuration file.
14 changes: 4 additions & 10 deletions packages/sparql-proxy/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Trifid plugin for `sparql-proxy`

## Supported options

Here are all supported options: https://github.com/zazuko/sparql-proxy#usage

## Quick start

Install this Trifid plugin using:
Expand All @@ -21,10 +17,8 @@ middlewares:
module: "@zazuko/trifid-plugin-sparql-proxy"
paths: /query
config:
enableProxy: true # enable support for `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables
sparqlEndpoint:
url: https://example.com/query
username: admin
password: secret
# …other configuration fields
endpointUrl: https://example.com/query
# The following fields are not required:
username: admin
password: secret
```
2 changes: 2 additions & 0 deletions packages/sparql-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const defaultConfiguration = {
endpointUrl: '',
username: '',
password: '',
}

/** @type {import('../core/types/index.js').TrifidMiddleware} */
Expand Down
3 changes: 3 additions & 0 deletions packages/trifid/instances/docker-fetch/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

globals:
datasetBaseUrl: env:DATASET_BASE_URL
endpoints:
default:
url: /query

middlewares:
static-assets:
Expand Down
14 changes: 6 additions & 8 deletions packages/trifid/instances/docker-sparql/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

globals:
datasetBaseUrl: env:DATASET_BASE_URL
sparqlEndpoint:
url: env:SPARQL_ENDPOINT_URL
username: env:SPARQL_ENDPOINT_USERNAME
password: env:SPARQL_ENDPOINT_PASSWORD
endpoints:
default:
url: /query

middlewares:
static-assets:
Expand Down Expand Up @@ -51,10 +50,9 @@ middlewares:
config:
queryOperation: postQueryUrlencoded
rewriteQueries: true
cache:
prefix: env:SPARQL_PROXY_CACHE_PREFIX
url: env:SPARQL_PROXY_CACHE_URL
clearAtStartup: env:SPARQL_PROXY_CACHE_CLEAR_AT_STARTUP
endpointUrl: env:SPARQL_ENDPOINT_URL
username: env:SPARQL_ENDPOINT_USERNAME
password: env:SPARQL_ENDPOINT_PASSWORD

handle-redirects:
module: "@zazuko/trifid-handle-redirects"
13 changes: 10 additions & 3 deletions packages/trifid/server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env node

import { join } from 'node:path'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'

import { Command } from 'commander'
import trifid from 'trifid-core'

const program = new Command()

const defaultConfigurationFile = process.env.TRIFID_CONFIG ?? 'config.yaml'
const currentDir = dirname(fileURLToPath(import.meta.url))
const sparqlConfigPath = join(currentDir, 'instances', 'docker-sparql', 'config.yaml')
const defaultConfigurationFile = process.env.TRIFID_CONFIG || sparqlConfigPath

program
.option('-c, --config <path>', 'configuration file', defaultConfigurationFile)
Expand All @@ -20,7 +23,9 @@ program
.parse(process.argv)

const opts = program.opts()
const configFile = join(process.cwd(), opts.config)
const configFile = (opts.config && !opts.config.startsWith('/'))
? join(process.cwd(), opts.config)
: opts.config

// create a minimal configuration that extends the specified one
const config = {
Expand All @@ -39,9 +44,11 @@ if (opts.sparqlEndpointUrl) {
config.globals.sparqlEndpoint = {
url: opts.sparqlEndpointUrl,
}
process.env.SPARQL_ENDPOINT_URL = opts.sparqlEndpointUrl
}
if (opts.datasetBaseUrl) {
config.globals.datasetBaseUrl = opts.datasetBaseUrl
process.env.DATASET_BASE_URL = opts.datasetBaseUrl
}

// load the configuration and start the server
Expand Down

0 comments on commit 1f2e258

Please sign in to comment.