@wilmouths wilmouths authored on 28 Jun
.husky build: run lint on commited files 4 months ago
config config: remove scope for master key 3 months ago
elastic test: update mock 3 months ago
lib style: add application name on response log 3 months ago
openapi docs: update OpenAPI 3 months ago
routes refactor: remove POST routes and update GET to use lucene query 3 months ago
.dockerignore build: add ignore files 5 months ago
.eslintignore typo: rename file 3 months ago
.eslintrc.js style: adding eslint jest plugins 4 months ago
.gitignore update docker-compose files 3 months ago
.npmrc build: adding versions files 5 months ago
.nvmrc build: adding versions files 5 months ago
Dockerfile build: write Dockerfile and docker-compose files 4 months ago
README.md style: fix color 3 months ago
app.js doc: write JSDoc 4 months ago
docker-compose.debug.yml update docker-compose files 3 months ago
docker-compose.yml update docker-compose files 3 months ago
package-lock.json Version 1.1.0 3 months ago
package.json Version 1.1.0 3 months ago
server.js refactor: remove apiKeyManager 3 months ago
README.md

RESEDA API Search

Prerequisites

Installation

$ git clone https://gitbucket.inist.fr/git/METADoRe/reseda-search.git
$ cd ./reseda-search

Production

$ docker-compose up -d api

Usage

API Key

A master API key is created at the first launch of the application, API keys are stored in ./api-keys.json file.

An API key gives access to more fields returned by the API, for examples:

{
  "scope": [],
  "fields": {
    "employees": [],
    "structures": []
  },
  "metadata": {
    "application": "",
    "tags": []
  }
}
Key Type Description
scope Array[String] The scope defines the access to the routes, if it is not defined the key cannot access the different routes. You have to add "employees" and/or "structures" to give access. (ex: "scope": ["employees"])
fields.employees Array[String] Define the fields returned by the API, if empty all fields are returned. (default: [])
fields.structures Array[String] Define the fields returned by the API, if empty all fields are returned. (default: [])
metadata.application String It is necessary to fill in the name of the application that will use the API key to ensure a follow-up of the requests.
metadata.tags Array[String] Different tags can be filled in or not, you can indicate the information you want. (default: [])

There are one way to use an api key, by the header x-api-key.

Examples:

$ curl -H "x-api-key: 6596ae25fdfdc83b85a7" http://localhost:3000/employees

$ curl http://localhost:3000/employees?apiKey=6596ae25fdfdc83b85a7

Development

$ npm install # Install Node.JS dependencies
$ docker-compose -f docker-compose.debug.yml run --rm elastic chown -R elasticsearch /usr/share/elasticsearch/ # Chown ElasticSearch volume
$ docker-compose -f docker-compose.debug.yml up -d elastic # Run ElasticSearch
$ docker-compose -f docker-compose.debug.yml up -d api # Run API in development mode

Tests

$ npm run test

Environment variables

Name Type Description
APP_PORT Integer Application port (default: 3000)
ELASTICSEARCH_SCHEME String URI scheme (default: https)
ELASTICSEARCH_HOST String ElasticSerach host (default: localhost)
ELASTICSEARCH_PORT Integer ElasticSerach port (default: 9200)
ELASTICSEARCH_USERNAME String ElasticSerach host (default: elastic)
ELASTICSEARCH_PASSWORD String ElasticSerach host (default: changeme)
RESEDA_EMPLOYEES_INDEX String Reseda employees index name (default: employees)
RESEDA_STRUCTURES_INDEX String Reseda structures index name (default: structures)
RESEDA_TOKENS_INDEX String API Key index name (default: tokens)
PARAMS_MAX_SIZE Integer Query max size (default: 1000)
PARAMS_DEFAULT_SIZE Integer Query default size (default: 25)
RESEDA_DOC_URL String OpenAPI URL (default: docs)
FIELDS_NAME JSON Default returned fields (default: { "employees": [ "nomUsage", "prenom", "UUIDPersonne", "affectationAdministrative.codeUnite" ], "structures": [ "codeUnite", "intituleUnite" ] })
SCROLL_TIME String Scroll time (default: 5m)
MASTER_TOKEN_KEY String Master token key to manage tokens (default: b1230abd533c8e9c41cb9e562b1b2017bcb968322dacd973162ce5135baf15b8)
MASTER_TOKEN_PARAMS JSON Master token key to manage tokens (default: { "scope": ["managment", "admin"], "metadata": { "application": "@metadore/reseda-search", "tags": ["apiKey", "@metadore/reseda-search"] } })

OpenAPI

The OpenAPI page is by default available on /docs, example: http://localhost:3000/docs. You can change the URL via the environment variable RESEDA_DOC_URL.