mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-14 14:36:36 +00:00
config: Set default apiKey of empty string to avoid undefined keys
Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
142d2a7c6f
commit
b37ce5e3d9
@ -9,6 +9,7 @@ import supervisorVersion = require('../lib/supervisor-version');
|
||||
import * as constants from '../lib/constants';
|
||||
import * as osRelease from '../lib/os-release';
|
||||
import { ConfigValue } from '../lib/types';
|
||||
import { checkTruthy } from '../lib/validation';
|
||||
|
||||
// A provider for schema entries with source 'func'
|
||||
type ConfigProviderFunctionGetter = () => Bluebird<any>;
|
||||
@ -51,7 +52,9 @@ export function createProviderFunctions(
|
||||
return config
|
||||
.getMany(['apiEndpoint', 'supervisorOfflineMode'])
|
||||
.then(({ apiEndpoint, supervisorOfflineMode }) => {
|
||||
return Boolean(supervisorOfflineMode) || !Boolean(apiEndpoint);
|
||||
return (
|
||||
checkTruthy(supervisorOfflineMode as boolean) || !apiEndpoint
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
|
@ -29,7 +29,7 @@ class Config extends EventEmitter {
|
||||
deltaEndpoint: { source: 'config.json', default: 'https://delta.resin.io' },
|
||||
uuid: { source: 'config.json', mutable: true },
|
||||
apiKey: { source: 'config.json', mutable: true, removeIfNull: true },
|
||||
deviceApiKey: { source: 'config.json', mutable: true },
|
||||
deviceApiKey: { source: 'config.json', mutable: true, default: '' },
|
||||
deviceType: { source: 'config.json', default: 'unknown' },
|
||||
username: { source: 'config.json' },
|
||||
userId: { source: 'config.json' },
|
||||
@ -292,7 +292,7 @@ class Config extends EventEmitter {
|
||||
if (offlineMode) {
|
||||
return;
|
||||
}
|
||||
if (deviceApiKey == null) {
|
||||
if (!deviceApiKey) {
|
||||
return this.set({ deviceApiKey: this.newUniqueKey() });
|
||||
}
|
||||
});
|
||||
|
@ -145,7 +145,7 @@ describe 'APIBinder', ->
|
||||
expect(mode).to.equal(true)
|
||||
# Check that there is no deviceApiKey
|
||||
@config.getMany([ 'deviceApiKey', 'uuid' ]).then (conf) ->
|
||||
expect(conf['deviceApiKey']).to.be.undefined
|
||||
expect(conf['deviceApiKey']).to.be.empty
|
||||
expect(conf['uuid']).to.not.be.undefined
|
||||
|
||||
describe 'Minimal config offline mode', ->
|
||||
@ -156,5 +156,5 @@ describe 'APIBinder', ->
|
||||
@config.get('offlineMode').then (mode) =>
|
||||
expect(mode).to.equal(true)
|
||||
@config.getMany([ 'deviceApiKey', 'uuid' ]).then (conf) ->
|
||||
expect(conf['deviceApiKey']).to.be.undefined
|
||||
expect(conf['deviceApiKey']).to.be.empty
|
||||
expect(conf['uuid']).to.not.be.undefined
|
||||
|
Loading…
x
Reference in New Issue
Block a user