Service Configuration

Service groups can be disabled by setting the enabled parameter in the Investigate configuration file:

web_services.my-service-group.enabled: false

Sometimes a group of web services needs to be configured at runtime. The most common example is where the services require an authentication token. You can specify that a configuration is required by adding a schema (powered by Joi v10.4.1) to the registerServices function:

import { Joi, registerServices } from '@sirensolutions/web-service-interface';
import MyService from './MyService';

export = registerServices('my-service-group', [MyService], { auth_token: Joi.string().required() });

This makes the following configuration required in the Investigate configuration file:

web_services.my-service-group.config.auth_token: 'my-auth-token'

This parameter is then available in each of the services through the this.config attribute. Note that a generic parameter must be provided to ServiceDefinition so that this.config can be typed:

export default class MyService extends ServiceDefinition<{ auth_token: string }> {
  ...
  async invoke(): Promise<SimpleMap> {
    const token = this.config.auth_token;
    ...
  }
}