Skip to content

Commit

Permalink
feat: Add config setting to enable create-API-docs-mode
Browse files Browse the repository at this point in the history
Implements #447
  • Loading branch information
mountaindude committed May 14, 2022
1 parent 3cd0acc commit d9127f0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 37 deletions.
5 changes: 5 additions & 0 deletions src/config/production_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ Butler:
- /Users/goran/butler-test-dir1//abc//..
- /Users/goran/butler-test-dir2

# If set to true, Butler will be started with a focus on creating an API documentation file
# All configuration relating to outbound connetions (to Sense, email servers, MQTT broker etc) will be disabled.
# NOTE: This setting should always be false (or just deleted), unless you want to regenerate the API doc files.
restServerApiDocGenerate: true

# Enable/disable individual REST API endpoints. Set config item below to true to enable that endpoint.
restServerEndpointsEnable:
apiListEnbledEndpoints: false
Expand Down
67 changes: 37 additions & 30 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,36 +151,43 @@ const certPath = path.resolve(__dirname, config.get('Butler.cert.clientCert'));
const keyPath = path.resolve(__dirname, config.get('Butler.cert.clientCertKey'));
const caPath = path.resolve(__dirname, config.get('Butler.cert.clientCertCA'));

// Engine config
const configEngine = {
engineVersion: config.get('Butler.configEngine.engineVersion'),
host: config.get('Butler.configEngine.host'),
port: config.get('Butler.configEngine.port'),
isSecure: config.get('Butler.configEngine.useSSL'),
headers: config.get('Butler.configEngine.headers'),
cert: readCert(config.get('Butler.cert.clientCert')),
key: readCert(config.get('Butler.cert.clientCertKey')),
rejectUnauthorized: config.get('Butler.configEngine.rejectUnauthorized'),
};

// QRS config
const configQRS = {
authentication: config.get('Butler.configQRS.authentication'),
host: config.get('Butler.configQRS.host'),
port: config.get('Butler.configQRS.port'),
useSSL: config.get('Butler.configQRS.useSSL'),
headerKey: config.get('Butler.configQRS.headerKey'),
headerValue: config.get('Butler.configQRS.headerValue'),
rejectUnauthorized: config.get('Butler.configQRS.rejectUnauthorized'),
cert: readCert(certPath),
key: readCert(keyPath),
ca: readCert(caPath),
certPaths: {
certPath,
keyPath,
caPath,
},
};
let configEngine;
let configQRS;
if (config.has('Butler.restServerApiDocGenerate') === false || config.get('Butler.restServerApiDocGenerate') === false) {
logger.debug('CONFIG: API doc mode=off');
// Engine config
configEngine = {
engineVersion: config.get('Butler.configEngine.engineVersion'),
host: config.get('Butler.configEngine.host'),
port: config.get('Butler.configEngine.port'),
isSecure: config.get('Butler.configEngine.useSSL'),
headers: config.get('Butler.configEngine.headers'),
cert: readCert(config.get('Butler.cert.clientCert')),
key: readCert(config.get('Butler.cert.clientCertKey')),
rejectUnauthorized: config.get('Butler.configEngine.rejectUnauthorized'),
};

// QRS config
configQRS = {
authentication: config.get('Butler.configQRS.authentication'),
host: config.get('Butler.configQRS.host'),
port: config.get('Butler.configQRS.port'),
useSSL: config.get('Butler.configQRS.useSSL'),
headerKey: config.get('Butler.configQRS.headerKey'),
headerValue: config.get('Butler.configQRS.headerValue'),
rejectUnauthorized: config.get('Butler.configQRS.rejectUnauthorized'),
cert: readCert(certPath),
key: readCert(keyPath),
ca: readCert(caPath),
certPaths: {
certPath,
keyPath,
caPath,
},
};
} else {
logger.debug('CONFIG: API doc mode=on');
}

// MS Teams notification objects
let teamsTaskFailureObj;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/slack_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function slackSend(slackConfig, logger) {
logger.debug(`SLACKSEND: Result from POST to Slack webhook: ${res.statusText} (${res.status}): ${res.data}`);
return res;
} catch (err) {
logger.error(`SLACKSEND: ${err}, "${err.response.data}"`);
logger.error(`SLACKSEND: ${err}"`);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/routes/sense_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const { logRESTCall } = require('../lib/log_rest_call');
const { apiPutAppReload } = require('../api/sense_app');

// Set up enigma.js configuration
// eslint-disable-next-line import/no-dynamic-require
const qixSchema = require(`enigma.js/schemas/${globals.configEngine.engineVersion}`);

async function handlerPutAppReload(request, reply) {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const qixSchema = require(`enigma.js/schemas/${globals.configEngine.engineVersion}`);

logRESTCall(request);

// TODO: Add app exists test. Return error if not existing.
Expand Down
5 changes: 3 additions & 2 deletions src/routes/sense_app_dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const { logRESTCall } = require('../lib/log_rest_call');
const { apiGetSenseAppDump, apiGetAppDump } = require('../api/sense_app_dump');

// Set up enigma.js configuration
// eslint-disable-next-line import/no-dynamic-require
const qixSchema = require(`enigma.js/schemas/${globals.configEngine.engineVersion}`);

function handlerGetSenseAppDump(request, reply) {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const qixSchema = require(`enigma.js/schemas/${globals.configEngine.engineVersion}`);

logRESTCall(request);

if (request.params.appId === undefined) {
Expand Down
5 changes: 3 additions & 2 deletions src/routes/sense_list_apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const { logRESTCall } = require('../lib/log_rest_call');
const { apiGetSenseListApps, apiGetAppsList } = require('../api/sense_list_apps');

// Set up enigma.js configuration
// eslint-disable-next-line import/no-dynamic-require
const qixSchema = require(`enigma.js/schemas/${globals.configEngine.engineVersion}`);

function handlerGetSenseListApps(request, reply) {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const qixSchema = require(`enigma.js/schemas/${globals.configEngine.engineVersion}`);

logRESTCall(request);

// create a new session
Expand Down

0 comments on commit d9127f0

Please sign in to comment.