refactor: Remove scaffolding for unused mutable config functions

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-01-03 13:13:39 +00:00
parent 6b5617be15
commit ac4866170e
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 85 additions and 121 deletions

View File

@ -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<any>;
type ConfigProviderFunctionSetter = (
value: ConfigValue,
tx?: Transaction,
) => Bluebird<void>;
type ConfigProviderFunctionRemover = () => Bluebird<void>;
interface ConfigProviderFunction {
get: ConfigProviderFunctionGetter;
set?: ConfigProviderFunctionSetter;
remove?: ConfigProviderFunctionRemover;
}
type ConfigProviderFunction = () => Bluebird<any>;
export interface ConfigProviderFunctions {
[key: string]: ConfigProviderFunction;
@ -32,41 +18,30 @@ export function createProviderFunctions(
config: Config,
): ConfigProviderFunctions {
return {
version: {
get: () => {
version: () => {
return Bluebird.resolve(supervisorVersion);
},
},
currentApiKey: {
get: () => {
currentApiKey: () => {
return config
.getMany(['apiKey', 'deviceApiKey'])
.then(({ apiKey, deviceApiKey }) => {
return apiKey || deviceApiKey;
});
},
},
provisioned: {
get: () => {
provisioned: () => {
return config
.getMany(['uuid', 'apiEndpoint', 'registered_at', 'deviceId'])
.then(requiredValues => {
return _.every(_.values(requiredValues), Boolean);
});
},
},
osVersion: {
get: () => {
osVersion: () => {
return osRelease.getOSVersion(constants.hostOSVersionPath);
},
},
osVariant: {
get: () => {
osVariant: () => {
return osRelease.getOSVariant(constants.hostOSVersionPath);
},
},
provisioningOptions: {
get: () => {
provisioningOptions: () => {
return config
.getMany([
'uuid',
@ -95,9 +70,7 @@ export function createProviderFunctions(
};
});
},
},
mixpanelHost: {
get: () => {
mixpanelHost: () => {
return config.get('apiEndpoint').then(apiEndpoint => {
if (!apiEndpoint) {
return null;
@ -106,9 +79,7 @@ export function createProviderFunctions(
return { host: url.host, path: '/mixpanel' };
});
},
},
extendedEnvOptions: {
get: () => {
extendedEnvOptions: () => {
return config.getMany([
'uuid',
'listenPort',
@ -120,9 +91,7 @@ export function createProviderFunctions(
'osVersion',
]);
},
},
fetchOptions: {
get: () => {
fetchOptions: () => {
return config.getMany([
'uuid',
'currentApiKey',
@ -136,13 +105,10 @@ export function createProviderFunctions(
'deltaVersion',
]);
},
},
unmanaged: {
get: () => {
unmanaged: () => {
return config.get('apiEndpoint').then(apiEndpoint => {
return !apiEndpoint;
});
},
},
};
}

View File

@ -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: ${