From ac4866170eb55b956a480a57c1e05dfa14c6b953 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Thu, 3 Jan 2019 13:13:39 +0000 Subject: [PATCH] refactor: Remove scaffolding for unused mutable config functions Change-type: patch Signed-off-by: Cameron Diver --- src/config/functions.ts | 202 +++++++++++++++++----------------------- src/config/index.ts | 4 +- 2 files changed, 85 insertions(+), 121 deletions(-) diff --git a/src/config/functions.ts b/src/config/functions.ts index d1d3d644..ed3514e5 100644 --- a/src/config/functions.ts +++ b/src/config/functions.ts @@ -1,5 +1,4 @@ import * as Bluebird from 'bluebird'; -import { Transaction } from 'knex'; import * as _ from 'lodash'; import { URL } from 'url'; @@ -8,21 +7,8 @@ import supervisorVersion = require('../lib/supervisor-version'); import Config from '.'; import * as constants from '../lib/constants'; import * as osRelease from '../lib/os-release'; -import { ConfigValue } from '../lib/types'; -// A provider for schema entries with source 'func' -type ConfigProviderFunctionGetter = () => Bluebird; -type ConfigProviderFunctionSetter = ( - value: ConfigValue, - tx?: Transaction, -) => Bluebird; -type ConfigProviderFunctionRemover = () => Bluebird; - -interface ConfigProviderFunction { - get: ConfigProviderFunctionGetter; - set?: ConfigProviderFunctionSetter; - remove?: ConfigProviderFunctionRemover; -} +type ConfigProviderFunction = () => Bluebird; export interface ConfigProviderFunctions { [key: string]: ConfigProviderFunction; @@ -32,117 +18,97 @@ export function createProviderFunctions( config: Config, ): ConfigProviderFunctions { return { - version: { - get: () => { - return Bluebird.resolve(supervisorVersion); - }, + version: () => { + return Bluebird.resolve(supervisorVersion); }, - currentApiKey: { - get: () => { - return config - .getMany(['apiKey', 'deviceApiKey']) - .then(({ apiKey, deviceApiKey }) => { - return apiKey || deviceApiKey; - }); - }, - }, - provisioned: { - get: () => { - return config - .getMany(['uuid', 'apiEndpoint', 'registered_at', 'deviceId']) - .then(requiredValues => { - return _.every(_.values(requiredValues), Boolean); - }); - }, - }, - osVersion: { - get: () => { - return osRelease.getOSVersion(constants.hostOSVersionPath); - }, - }, - osVariant: { - get: () => { - return osRelease.getOSVariant(constants.hostOSVersionPath); - }, - }, - provisioningOptions: { - get: () => { - return config - .getMany([ - 'uuid', - 'userId', - 'applicationId', - 'apiKey', - 'deviceApiKey', - 'deviceType', - 'apiEndpoint', - 'apiTimeout', - 'registered_at', - 'deviceId', - ]) - .then(conf => { - return { - uuid: conf.uuid, - applicationId: conf.applicationId, - userId: conf.userId, - deviceType: conf.deviceType, - provisioningApiKey: conf.apiKey, - deviceApiKey: conf.deviceApiKey, - apiEndpoint: conf.apiEndpoint, - apiTimeout: conf.apiTimeout, - registered_at: conf.registered_at, - deviceId: conf.deviceId, - }; - }); - }, - }, - mixpanelHost: { - get: () => { - return config.get('apiEndpoint').then(apiEndpoint => { - if (!apiEndpoint) { - return null; - } - const url = new URL(apiEndpoint as string); - return { host: url.host, path: '/mixpanel' }; + currentApiKey: () => { + return config + .getMany(['apiKey', 'deviceApiKey']) + .then(({ apiKey, deviceApiKey }) => { + return apiKey || deviceApiKey; }); - }, }, - extendedEnvOptions: { - get: () => { - return config.getMany([ + provisioned: () => { + return config + .getMany(['uuid', 'apiEndpoint', 'registered_at', 'deviceId']) + .then(requiredValues => { + return _.every(_.values(requiredValues), Boolean); + }); + }, + osVersion: () => { + return osRelease.getOSVersion(constants.hostOSVersionPath); + }, + osVariant: () => { + return osRelease.getOSVariant(constants.hostOSVersionPath); + }, + provisioningOptions: () => { + return config + .getMany([ 'uuid', - 'listenPort', - 'name', - 'apiSecret', + 'userId', + 'applicationId', + 'apiKey', 'deviceApiKey', - 'version', 'deviceType', - 'osVersion', - ]); - }, - }, - fetchOptions: { - get: () => { - return config.getMany([ - 'uuid', - 'currentApiKey', 'apiEndpoint', - 'deltaEndpoint', - 'delta', - 'deltaRequestTimeout', - 'deltaApplyTimeout', - 'deltaRetryCount', - 'deltaRetryInterval', - 'deltaVersion', - ]); - }, - }, - unmanaged: { - get: () => { - return config.get('apiEndpoint').then(apiEndpoint => { - return !apiEndpoint; + 'apiTimeout', + 'registered_at', + 'deviceId', + ]) + .then(conf => { + return { + uuid: conf.uuid, + applicationId: conf.applicationId, + userId: conf.userId, + deviceType: conf.deviceType, + provisioningApiKey: conf.apiKey, + deviceApiKey: conf.deviceApiKey, + apiEndpoint: conf.apiEndpoint, + apiTimeout: conf.apiTimeout, + registered_at: conf.registered_at, + deviceId: conf.deviceId, + }; }); - }, + }, + mixpanelHost: () => { + return config.get('apiEndpoint').then(apiEndpoint => { + if (!apiEndpoint) { + return null; + } + const url = new URL(apiEndpoint as string); + return { host: url.host, path: '/mixpanel' }; + }); + }, + extendedEnvOptions: () => { + return config.getMany([ + 'uuid', + 'listenPort', + 'name', + 'apiSecret', + 'deviceApiKey', + 'version', + 'deviceType', + 'osVersion', + ]); + }, + fetchOptions: () => { + return config.getMany([ + 'uuid', + 'currentApiKey', + 'apiEndpoint', + 'deltaEndpoint', + 'delta', + 'deltaRequestTimeout', + 'deltaApplyTimeout', + 'deltaRetryCount', + 'deltaRetryInterval', + 'deltaVersion', + ]); + }, + unmanaged: () => { + return config.get('apiEndpoint').then(apiEndpoint => { + return !apiEndpoint; + }); }, }; } diff --git a/src/config/index.ts b/src/config/index.ts index c8fedc1e..5ec9f79a 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -108,7 +108,7 @@ export class Config extends EventEmitter { } switch (this.schema[key].source) { case 'func': - return this.providerFunctions[key].get().catch(e => { + return this.providerFunctions[key]().catch(e => { console.error(`Error getting config value for ${key}`, e, e.stack); return null; }); @@ -162,8 +162,6 @@ export class Config extends EventEmitter { acc.configJsonVals[key] = val; } else if (this.schema[key].source === 'db') { acc.dbVals[key] = val; - } else if (this.schema[key].source === 'func') { - acc.fnVals[key] = val; } else { throw new Error( `Unknown config backend for key: ${key}, backend: ${