mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-23 12:35:44 +00:00
Auto-merge for PR #692 via VersionBot
Remove resinApiEndpoint meta-endpoint and use config.json entry instead
This commit is contained in:
commit
7dad63b470
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
|
||||
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## v7.14.0 - 2018-07-12
|
||||
|
||||
* Remove resinApiEndpoint meta-endpoint and use config.json entry instead #692 [Cameron Diver]
|
||||
|
||||
## v7.13.3 - 2018-07-12
|
||||
|
||||
* Correctly apply current commit value to applications #691 [Cameron Diver]
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "resin-supervisor",
|
||||
"description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.",
|
||||
"version": "7.13.3",
|
||||
"version": "7.14.0",
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -63,47 +63,47 @@ module.exports = class APIBinder
|
||||
release()
|
||||
|
||||
initClient: =>
|
||||
@config.getMany([ 'offlineMode', 'resinApiEndpoint', 'currentApiKey' ])
|
||||
.then ({ offlineMode, resinApiEndpoint, currentApiKey }) =>
|
||||
@config.getMany([ 'offlineMode', 'apiEndpoint', 'currentApiKey' ])
|
||||
.then ({ offlineMode, apiEndpoint, currentApiKey }) =>
|
||||
if offlineMode
|
||||
console.log('Offline Mode is set, skipping API client initialization')
|
||||
return
|
||||
baseUrl = url.resolve(resinApiEndpoint, '/v4/')
|
||||
baseUrl = url.resolve(apiEndpoint, '/v4/')
|
||||
passthrough = _.cloneDeep(requestOpts)
|
||||
passthrough.headers ?= {}
|
||||
passthrough.headers.Authorization = "Bearer #{currentApiKey}"
|
||||
@resinApi = new PinejsClient
|
||||
apiPrefix: baseUrl
|
||||
passthrough: passthrough
|
||||
baseUrlLegacy = url.resolve(resinApiEndpoint, '/v2/')
|
||||
baseUrlLegacy = url.resolve(apiEndpoint, '/v2/')
|
||||
@resinApiLegacy = new PinejsClient
|
||||
apiPrefix: baseUrlLegacy
|
||||
passthrough: passthrough
|
||||
@cachedResinApi = @resinApi.clone({}, cache: {})
|
||||
|
||||
start: =>
|
||||
@config.getMany([ 'resinApiEndpoint', 'offlineMode', 'bootstrapRetryDelay' ])
|
||||
.then ({ resinApiEndpoint, offlineMode, bootstrapRetryDelay }) =>
|
||||
@config.getMany([ 'apiEndpoint', 'offlineMode', 'bootstrapRetryDelay' ])
|
||||
.then ({ apiEndpoint, offlineMode, bootstrapRetryDelay }) =>
|
||||
if offlineMode
|
||||
console.log('Offline Mode is set, skipping API binder initialization')
|
||||
# If we are offline because there is no apiEndpoint, there's a chance
|
||||
# we've went through a deprovision. We need to set the initialConfigReported
|
||||
# value to '', to ensure that when we do re-provision, we'll report
|
||||
# the config and hardward-specific options won't be lost
|
||||
if !Boolean(resinApiEndpoint)
|
||||
if !Boolean(apiEndpoint)
|
||||
return @config.set({ initialConfigReported: '' })
|
||||
return
|
||||
console.log('Ensuring device is provisioned')
|
||||
@provisionDevice()
|
||||
.then =>
|
||||
@config.getMany([ 'initialConfigReported', 'resinApiEndpoint' ])
|
||||
.then ({ initialConfigReported, resinApiEndpoint }) =>
|
||||
@config.getMany([ 'initialConfigReported', 'apiEndpoint' ])
|
||||
.then ({ initialConfigReported, apiEndpoint }) =>
|
||||
|
||||
# Either we haven't reported our initial config or we've
|
||||
# been re-provisioned
|
||||
if resinApiEndpoint != initialConfigReported
|
||||
if apiEndpoint != initialConfigReported
|
||||
console.log('Reporting initial configuration')
|
||||
@reportInitialConfig(resinApiEndpoint, bootstrapRetryDelay)
|
||||
@reportInitialConfig(apiEndpoint, bootstrapRetryDelay)
|
||||
.then =>
|
||||
console.log('Starting current state report')
|
||||
@startCurrentStateReport()
|
||||
@ -308,7 +308,7 @@ module.exports = class APIBinder
|
||||
|
||||
_sendLogsRequest: (uuid, data) =>
|
||||
reqBody = _.map(data, (msg) -> _.mapKeys(msg, (v, k) -> _.snakeCase(k)))
|
||||
@config.get('resinApiEndpoint')
|
||||
@config.get('apiEndpoint')
|
||||
.then (resinApiEndpoint) =>
|
||||
endpoint = url.resolve(resinApiEndpoint, "/device/v2/#{uuid}/logs")
|
||||
requestParams = _.extend
|
||||
@ -364,9 +364,9 @@ module.exports = class APIBinder
|
||||
@reportInitialConfig(apiEndpoint, retryDelay)
|
||||
|
||||
getTargetState: =>
|
||||
@config.getMany([ 'uuid', 'resinApiEndpoint', 'apiTimeout' ])
|
||||
.then ({ uuid, resinApiEndpoint, apiTimeout }) =>
|
||||
endpoint = url.resolve(resinApiEndpoint, "/device/v2/#{uuid}/state")
|
||||
@config.getMany([ 'uuid', 'apiEndpoint', 'apiTimeout' ])
|
||||
.then ({ uuid, apiEndpoint, apiTimeout }) =>
|
||||
endpoint = url.resolve(apiEndpoint, "/device/v2/#{uuid}/state")
|
||||
|
||||
requestParams = _.extend
|
||||
method: 'GET'
|
||||
@ -422,7 +422,7 @@ module.exports = class APIBinder
|
||||
return _.pickBy(diff, _.negate(_.isEmpty))
|
||||
|
||||
_sendReportPatch: (stateDiff, conf) =>
|
||||
endpoint = url.resolve(conf.resinApiEndpoint, "/device/v2/#{conf.uuid}/state")
|
||||
endpoint = url.resolve(conf.apiEndpoint, "/device/v2/#{conf.uuid}/state")
|
||||
requestParams = _.extend
|
||||
method: 'PATCH'
|
||||
url: "#{endpoint}"
|
||||
@ -432,7 +432,7 @@ module.exports = class APIBinder
|
||||
@cachedResinApi._request(requestParams)
|
||||
|
||||
_report: =>
|
||||
@config.getMany([ 'deviceId', 'apiTimeout', 'resinApiEndpoint', 'uuid' ])
|
||||
@config.getMany([ 'deviceId', 'apiTimeout', 'apiEndpoint', 'uuid' ])
|
||||
.then (conf) =>
|
||||
stateDiff = @_getStateDiff()
|
||||
if _.size(stateDiff) is 0
|
||||
|
@ -272,7 +272,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
).get(appId)
|
||||
|
||||
getTargetApp: (appId) =>
|
||||
@config.get('resinApiEndpoint').then (endpoint = '') ->
|
||||
@config.get('apiEndpoint').then (endpoint = '') ->
|
||||
@db.models('app').where({ appId, source: endpoint }).select()
|
||||
.then ([ app ]) =>
|
||||
if !app?
|
||||
@ -714,7 +714,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
@_targetVolatilePerImageId[imageId] = {}
|
||||
|
||||
getTargetApps: =>
|
||||
@config.get('resinApiEndpoint'). then (source = '') =>
|
||||
@config.get('apiEndpoint'). then (source = '') =>
|
||||
Promise.map(@db.models('app').where({ source }), @normaliseAndExtendAppFromDB)
|
||||
.map (app) =>
|
||||
if !_.isEmpty(app.services)
|
||||
|
@ -49,7 +49,6 @@ class Config extends EventEmitter {
|
||||
currentApiKey: { source: 'func' },
|
||||
offlineMode: { source: 'func' },
|
||||
pubnub: { source: 'func' },
|
||||
resinApiEndpoint: { source: 'func' },
|
||||
provisioned: { source: 'func' },
|
||||
osVersion: { source: 'func' },
|
||||
osVariant: { source: 'func' },
|
||||
|
@ -75,9 +75,9 @@ export function createProviderFunctions(config: Config, db: DB): ConfigProviderF
|
||||
},
|
||||
offlineMode: {
|
||||
get: () => {
|
||||
return config.getMany([ 'resinApiEndpoint', 'supervisorOfflineMode' ])
|
||||
.then(({ resinApiEndpoint, supervisorOfflineMode }) => {
|
||||
return Boolean(supervisorOfflineMode) || !Boolean(resinApiEndpoint);
|
||||
return config.getMany([ 'apiEndpoint', 'supervisorOfflineMode' ])
|
||||
.then(({ apiEndpoint, supervisorOfflineMode }) => {
|
||||
return Boolean(supervisorOfflineMode) || !Boolean(apiEndpoint);
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -93,21 +93,11 @@ export function createProviderFunctions(config: Config, db: DB): ConfigProviderF
|
||||
});
|
||||
},
|
||||
},
|
||||
resinApiEndpoint: {
|
||||
get: () => {
|
||||
// Fallback to checking if an API endpoint was passed via env vars if there's none
|
||||
// in config.json (legacy)
|
||||
return config.get('apiEndpoint')
|
||||
.then((apiEndpoint) => {
|
||||
return apiEndpoint || (constants.apiEndpointFromEnv || '');
|
||||
});
|
||||
},
|
||||
},
|
||||
provisioned: {
|
||||
get: () => {
|
||||
return config.getMany([
|
||||
'uuid',
|
||||
'resinApiEndpoint',
|
||||
'apiEndpoint',
|
||||
'registered_at',
|
||||
'deviceId',
|
||||
])
|
||||
@ -135,7 +125,7 @@ export function createProviderFunctions(config: Config, db: DB): ConfigProviderF
|
||||
'apiKey',
|
||||
'deviceApiKey',
|
||||
'deviceType',
|
||||
'resinApiEndpoint',
|
||||
'apiEndpoint',
|
||||
'apiTimeout',
|
||||
'registered_at',
|
||||
'deviceId',
|
||||
@ -147,7 +137,7 @@ export function createProviderFunctions(config: Config, db: DB): ConfigProviderF
|
||||
deviceType: conf.deviceType,
|
||||
provisioningApiKey: conf.apiKey,
|
||||
deviceApiKey: conf.deviceApiKey,
|
||||
apiEndpoint: conf.resinApiEndpoint,
|
||||
apiEndpoint: conf.apiEndpoint,
|
||||
apiTimeout: conf.apiTimeout,
|
||||
registered_at: conf.registered_at,
|
||||
deviceId: conf.deviceId,
|
||||
@ -157,7 +147,7 @@ export function createProviderFunctions(config: Config, db: DB): ConfigProviderF
|
||||
},
|
||||
mixpanelHost: {
|
||||
get: () => {
|
||||
return config.get('resinApiEndpoint')
|
||||
return config.get('apiEndpoint')
|
||||
.then((apiEndpoint) => {
|
||||
return `${apiEndpoint}/mixpanel`;
|
||||
});
|
||||
@ -182,7 +172,7 @@ export function createProviderFunctions(config: Config, db: DB): ConfigProviderF
|
||||
return config.getMany([
|
||||
'uuid',
|
||||
'currentApiKey',
|
||||
'resinApiEndpoint',
|
||||
'apiEndpoint',
|
||||
'deltaEndpoint',
|
||||
'delta',
|
||||
'deltaRequestTimeout',
|
||||
|
@ -166,7 +166,7 @@ module.exports = class DeviceState extends EventEmitter
|
||||
|
||||
@config.getMany([
|
||||
'initialConfigSaved', 'listenPort', 'apiSecret', 'osVersion', 'osVariant', 'logsChannelSecret',
|
||||
'version', 'provisioned', 'resinApiEndpoint', 'connectivityCheckEnabled', 'legacyAppsPresent'
|
||||
'version', 'provisioned', 'apiEndpoint', 'connectivityCheckEnabled', 'legacyAppsPresent'
|
||||
])
|
||||
.then (conf) =>
|
||||
Promise.try =>
|
||||
@ -200,8 +200,8 @@ module.exports = class DeviceState extends EventEmitter
|
||||
.then =>
|
||||
@triggerApplyTarget({ initial: true })
|
||||
|
||||
initNetworkChecks: ({ resinApiEndpoint, connectivityCheckEnabled }) =>
|
||||
network.startConnectivityCheck resinApiEndpoint, connectivityCheckEnabled, (connected) =>
|
||||
initNetworkChecks: ({ apiEndpoint, connectivityCheckEnabled }) =>
|
||||
network.startConnectivityCheck apiEndpoint, connectivityCheckEnabled, (connected) =>
|
||||
@connected = connected
|
||||
@config.on 'change', (changedConfig) ->
|
||||
if changedConfig.connectivityCheckEnabled?
|
||||
@ -242,7 +242,7 @@ module.exports = class DeviceState extends EventEmitter
|
||||
|
||||
setTarget: (target) ->
|
||||
Promise.join(
|
||||
@config.get('resinApiEndpoint'),
|
||||
@config.get('apiEndpoint'),
|
||||
validateState(target),
|
||||
(source) =>
|
||||
@usingWriteLockTarget =>
|
||||
|
@ -25,7 +25,6 @@ const constants = {
|
||||
configJsonPathOnHost: checkString(process.env.CONFIG_JSON_PATH),
|
||||
proxyvisorHookReceiver:
|
||||
checkString(process.env.RESIN_PROXYVISOR_HOOK_RECEIVER) || 'http://0.0.0.0:1337',
|
||||
apiEndpointFromEnv: checkString(process.env.API_ENDPOINT),
|
||||
configJsonNonAtomicPath: '/boot/config.json',
|
||||
defaultPubnubSubscribeKey: process.env.DEFAULT_PUBNUB_SUBSCRIBE_KEY,
|
||||
defaultPubnubPublishKey: process.env.DEFAULT_PUBNUB_PUBLISH_KEY,
|
||||
|
@ -58,7 +58,7 @@ module.exports = class DockerUtils extends DockerToolbelt
|
||||
fetchDeltaWithProgress: (imgDest, fullDeltaOpts, onProgress) =>
|
||||
{
|
||||
deltaRequestTimeout, deltaApplyTimeout, deltaRetryCount, deltaRetryInterval,
|
||||
uuid, currentApiKey, deltaEndpoint, resinApiEndpoint,
|
||||
uuid, currentApiKey, deltaEndpoint, apiEndpoint,
|
||||
deltaSource, deltaSourceId, deltaVersion, startFromEmpty = false
|
||||
} = fullDeltaOpts
|
||||
retryCount = checkInt(deltaRetryCount)
|
||||
@ -80,7 +80,7 @@ module.exports = class DockerUtils extends DockerToolbelt
|
||||
|
||||
log("Starting delta to #{imgDest}")
|
||||
Promise.join @getRegistryAndName(imgDest), @getRegistryAndName(deltaSource), (dstInfo, srcInfo) ->
|
||||
tokenEndpoint = "#{resinApiEndpoint}/auth/v1/token"
|
||||
tokenEndpoint = "#{apiEndpoint}/auth/v1/token"
|
||||
opts =
|
||||
auth:
|
||||
user: 'd_' + uuid
|
||||
|
Loading…
x
Reference in New Issue
Block a user