mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-02 01:07:57 +00:00
refactor: Remove scaffolding for unused mutable config functions
Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
6b5617be15
commit
ac4866170e
@ -1,5 +1,4 @@
|
|||||||
import * as Bluebird from 'bluebird';
|
import * as Bluebird from 'bluebird';
|
||||||
import { Transaction } from 'knex';
|
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
|
|
||||||
@ -8,21 +7,8 @@ import supervisorVersion = require('../lib/supervisor-version');
|
|||||||
import Config from '.';
|
import Config from '.';
|
||||||
import * as constants from '../lib/constants';
|
import * as constants from '../lib/constants';
|
||||||
import * as osRelease from '../lib/os-release';
|
import * as osRelease from '../lib/os-release';
|
||||||
import { ConfigValue } from '../lib/types';
|
|
||||||
|
|
||||||
// A provider for schema entries with source 'func'
|
type ConfigProviderFunction = () => Bluebird<any>;
|
||||||
type ConfigProviderFunctionGetter = () => Bluebird<any>;
|
|
||||||
type ConfigProviderFunctionSetter = (
|
|
||||||
value: ConfigValue,
|
|
||||||
tx?: Transaction,
|
|
||||||
) => Bluebird<void>;
|
|
||||||
type ConfigProviderFunctionRemover = () => Bluebird<void>;
|
|
||||||
|
|
||||||
interface ConfigProviderFunction {
|
|
||||||
get: ConfigProviderFunctionGetter;
|
|
||||||
set?: ConfigProviderFunctionSetter;
|
|
||||||
remove?: ConfigProviderFunctionRemover;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConfigProviderFunctions {
|
export interface ConfigProviderFunctions {
|
||||||
[key: string]: ConfigProviderFunction;
|
[key: string]: ConfigProviderFunction;
|
||||||
@ -32,117 +18,97 @@ export function createProviderFunctions(
|
|||||||
config: Config,
|
config: Config,
|
||||||
): ConfigProviderFunctions {
|
): ConfigProviderFunctions {
|
||||||
return {
|
return {
|
||||||
version: {
|
version: () => {
|
||||||
get: () => {
|
return Bluebird.resolve(supervisorVersion);
|
||||||
return Bluebird.resolve(supervisorVersion);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
currentApiKey: {
|
currentApiKey: () => {
|
||||||
get: () => {
|
return config
|
||||||
return config
|
.getMany(['apiKey', 'deviceApiKey'])
|
||||||
.getMany(['apiKey', 'deviceApiKey'])
|
.then(({ apiKey, deviceApiKey }) => {
|
||||||
.then(({ apiKey, deviceApiKey }) => {
|
return 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' };
|
|
||||||
});
|
});
|
||||||
},
|
|
||||||
},
|
},
|
||||||
extendedEnvOptions: {
|
provisioned: () => {
|
||||||
get: () => {
|
return config
|
||||||
return config.getMany([
|
.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',
|
'uuid',
|
||||||
'listenPort',
|
'userId',
|
||||||
'name',
|
'applicationId',
|
||||||
'apiSecret',
|
'apiKey',
|
||||||
'deviceApiKey',
|
'deviceApiKey',
|
||||||
'version',
|
|
||||||
'deviceType',
|
'deviceType',
|
||||||
'osVersion',
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
fetchOptions: {
|
|
||||||
get: () => {
|
|
||||||
return config.getMany([
|
|
||||||
'uuid',
|
|
||||||
'currentApiKey',
|
|
||||||
'apiEndpoint',
|
'apiEndpoint',
|
||||||
'deltaEndpoint',
|
'apiTimeout',
|
||||||
'delta',
|
'registered_at',
|
||||||
'deltaRequestTimeout',
|
'deviceId',
|
||||||
'deltaApplyTimeout',
|
])
|
||||||
'deltaRetryCount',
|
.then(conf => {
|
||||||
'deltaRetryInterval',
|
return {
|
||||||
'deltaVersion',
|
uuid: conf.uuid,
|
||||||
]);
|
applicationId: conf.applicationId,
|
||||||
},
|
userId: conf.userId,
|
||||||
},
|
deviceType: conf.deviceType,
|
||||||
unmanaged: {
|
provisioningApiKey: conf.apiKey,
|
||||||
get: () => {
|
deviceApiKey: conf.deviceApiKey,
|
||||||
return config.get('apiEndpoint').then(apiEndpoint => {
|
apiEndpoint: conf.apiEndpoint,
|
||||||
return !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;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ export class Config extends EventEmitter {
|
|||||||
}
|
}
|
||||||
switch (this.schema[key].source) {
|
switch (this.schema[key].source) {
|
||||||
case 'func':
|
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);
|
console.error(`Error getting config value for ${key}`, e, e.stack);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@ -162,8 +162,6 @@ export class Config extends EventEmitter {
|
|||||||
acc.configJsonVals[key] = val;
|
acc.configJsonVals[key] = val;
|
||||||
} else if (this.schema[key].source === 'db') {
|
} else if (this.schema[key].source === 'db') {
|
||||||
acc.dbVals[key] = val;
|
acc.dbVals[key] = val;
|
||||||
} else if (this.schema[key].source === 'func') {
|
|
||||||
acc.fnVals[key] = val;
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unknown config backend for key: ${key}, backend: ${
|
`Unknown config backend for key: ${key}, backend: ${
|
||||||
|
Loading…
x
Reference in New Issue
Block a user