Skip to content

Commit

Permalink
マージ先 release (プルリクエスト #346)
Browse files Browse the repository at this point in the history
Release enebular-agent v2.17.0
  • Loading branch information
daisuke-arakawa-uhuru committed Jul 20, 2022
2 parents 546dd64 + e1e0dda commit ff3cd08
Show file tree
Hide file tree
Showing 39 changed files with 13,688 additions and 15,414 deletions.
2 changes: 1 addition & 1 deletion agent/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": [
["@babel/preset-env", {
"targets": {
"node": "12.22.10"
"node": "14.19.1"
}
}],
["@babel/preset-flow"]
Expand Down
5,483 changes: 2,990 additions & 2,493 deletions agent/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enebular-runtime-agent",
"version": "2.16.0",
"version": "2.17.0",
"description": "The enebular-agent core for enebular",
"main": "lib/index",
"scripts": {
Expand All @@ -19,7 +19,7 @@
"test:jest": "jest --runInBand --forceExit"
},
"engines": {
"node": "12.22.10"
"node": "14.19.1"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
Expand Down Expand Up @@ -91,4 +91,4 @@
"@babel/register"
]
}
}
}
27 changes: 20 additions & 7 deletions agent/src/agent-manager-mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type DeviceStateStateUpdates = {
export default class AgentManagerMediator {
_baseUrl: string
_accessToken: string
_isDeviceMaster: boolean
_log: Logger

constructor(log: Logger) {
Expand All @@ -40,6 +41,15 @@ export default class AgentManagerMediator {
this._accessToken = accessToken
}

setIsDeviceMaster(isDeviceMaster: boolean) {
if (isDeviceMaster) {
this.debug(`Saving logs to Cloudwatch...`)
} else {
this.debug(`Saving logs to S3...`)
}
this._isDeviceMaster = isDeviceMaster
}

_accessRequirementsConfigured(): boolean {
return !!this._baseUrl && !!this._accessToken
}
Expand All @@ -55,13 +65,16 @@ export default class AgentManagerMediator {
form.append('events', fs.createReadStream(filename))

try {
await fetchJSON(`${this._baseUrl}/record-logs`, {
method: 'POST',
headers: {
Authorization: `Bearer ${this._accessToken}`
},
body: form
})
await fetchJSON(
`${this._baseUrl}/record-logs?is_device_master=${this._isDeviceMaster}`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${this._accessToken}`
},
body: form
}
)
this.debug('Log sent')
} catch (err) {
throw new Error('Failed to send log: ' + err.message)
Expand Down
25 changes: 16 additions & 9 deletions agent/src/device-auth-mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default class DeviceAuthMediator extends EventEmitter {
constructor(messageEmitter: EventEmitter, log: Logger) {
super()
this._log = log
messageEmitter.on('updateAuth', message => this._handleUpdateAuth(message))
messageEmitter.on('updateAuth', (message) =>
this._handleUpdateAuth(message)
)
this._tokenEmitter = new EventEmitter()
}

Expand All @@ -45,7 +47,7 @@ export default class DeviceAuthMediator extends EventEmitter {
this._log.info(msg, ...args)
}

_handleUpdateAuth({ idToken, accessToken, state }) {
_handleUpdateAuth({ idToken, accessToken, state, isDeviceMaster }) {
if (idToken === '-' && accessToken === '-' && state === '-') {
this.debug('updateAuth:authRequestTrigger command received')
this.startAuthAttempt()
Expand All @@ -67,13 +69,18 @@ export default class DeviceAuthMediator extends EventEmitter {
this.emit('accessTokenClear')
} else {
this.debug('accessToken provided')
this.emit('accessTokenUpdate', accessToken)
this.emit('accessTokenUpdate', { accessToken, isDeviceMaster })
}
} else {
this.debug('Tokens are not for this device - ignoring' + JSON.stringify(payload, null, 2) +
', ' + this._nonce +
', ' + state +
', ' + this._seq
this.debug(
'Tokens are not for this device - ignoring' +
JSON.stringify(payload, null, 2) +
', ' +
this._nonce +
', ' +
state +
', ' +
this._seq
)
}
} else {
Expand Down Expand Up @@ -122,7 +129,7 @@ export default class DeviceAuthMediator extends EventEmitter {
this._seq++
const state = `req-${this._seq}`
const waitTokens = this._waitForTokenUpdate()
waitTokens.catch(err => {
waitTokens.catch((err) => {
this.debug('Auth request: ' + err.message)
})

Expand All @@ -145,7 +152,7 @@ export default class DeviceAuthMediator extends EventEmitter {
async _waitForTokenUpdate() {
this.debug('Setting up wait for token update...')
return new Promise((resolve, reject) => {
this._tokenEmitter.on('tokenUpdate', accessToken => {
this._tokenEmitter.on('tokenUpdate', (accessToken) => {
resolve()
})
setTimeout(() => {
Expand Down
34 changes: 21 additions & 13 deletions agent/src/enebular-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ type AgentSetting = {
agentManagerBaseUrl?: string
}

type AccessTokenUpdate = {
accessToken: string,
isDeviceMaster: boolean
}

export type AgentState =
| 'init'
| 'registered'
Expand Down Expand Up @@ -95,7 +100,7 @@ export default class EnebularAgent extends EventEmitter {
_deviceAuth: DeviceAuthMediator
_agentMan: AgentManagerMediator
_deviceStateManager: DeviceStateManager
_deviceCommandManager: DeviceCommandManager
_deviceCommandManager: DeviceCommandManager
_agentInfoManager: AgentInfoManager
_assetManager: AssetManager
_aiModelManager: AiModelManager
Expand Down Expand Up @@ -128,16 +133,16 @@ export default class EnebularAgent extends EventEmitter {
this._connector.on('connectionChange', () =>
this._onConnectorConnectionChange()
)
this._connector.on('message', params => this._onConnectorMessage(params))
this._connector.on('ctrlMessage', params =>
this._connector.on('message', (params) => this._onConnectorMessage(params))
this._connector.on('ctrlMessage', (params) =>
this._onConnectorCtrlMessage(params)
)
}

_init() {
if (this._enebularAgentConfig) {
const configKeys = Object.keys(this._enebularAgentConfig)
configKeys.forEach(key => {
configKeys.forEach((key) => {
this._config.set(key, this._enebularAgentConfig[key])
})
}
Expand Down Expand Up @@ -168,7 +173,7 @@ export default class EnebularAgent extends EventEmitter {
this._log,
this._config.get('ENEBULAR_CONNECTOR_MESSENGER_REQ_RETYR_TIMEOUT')
)
this._connectorMessenger.on('requestConnectorCtrlMessageSend', msg =>
this._connectorMessenger.on('requestConnectorCtrlMessageSend', (msg) =>
this._onRequestConnectorCtrlMessageSend(msg)
)

Expand Down Expand Up @@ -239,7 +244,10 @@ export default class EnebularAgent extends EventEmitter {
}
)

this._agentRunnerManager = new AgentRunnerManager(this._log, this._logManager)
this._agentRunnerManager = new AgentRunnerManager(
this._log,
this._logManager
)

this._remoteLogin = new RemoteLogin(
this._deviceStateManager,
Expand All @@ -249,8 +257,8 @@ export default class EnebularAgent extends EventEmitter {
)

this._deviceAuth = new DeviceAuthMediator(this._messageEmitter, this._log)
this._deviceAuth.on('accessTokenUpdate', accessToken =>
this._onAccessTokenUpdate(accessToken)
this._deviceAuth.on('accessTokenUpdate', (body) =>
this._onAccessTokenUpdate(body)
)
this._deviceAuth.on('accessTokenClear', () => this._onAccessTokenClear())

Expand Down Expand Up @@ -448,9 +456,7 @@ export default class EnebularAgent extends EventEmitter {
}
} else {
this._log.error(
`Impossible state transition requested: ${
this._agentState
} => ${nextState}`
`Impossible state transition requested: ${this._agentState} => ${nextState}`
)
}
}
Expand Down Expand Up @@ -496,7 +502,7 @@ export default class EnebularAgent extends EventEmitter {
if (agentManagerBaseUrl) {
this._agentManagerBaseUrl = agentManagerBaseUrl
}
const formatVal = val => {
const formatVal = (val) => {
return val || 'not set'
}
this._log.debug('Config:')
Expand Down Expand Up @@ -545,8 +551,10 @@ export default class EnebularAgent extends EventEmitter {
}
}

_onAccessTokenUpdate(accessToken: string) {
_onAccessTokenUpdate(options: AccessTokenUpdate) {
const { accessToken, isDeviceMaster } = options
this._agentMan.setAccessToken(accessToken)
this._agentMan.setIsDeviceMaster(isDeviceMaster)
if (this._agentState !== 'authenticated') {
this._changeAgentState('authenticated')
}
Expand Down
3 changes: 2 additions & 1 deletion agent/src/node-red-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,9 @@ export default class NodeREDController {
} else {
this.info('credential encryption')
try {
// when loading flow credential secret is stored in runtime config
const dotconfig = fs.readFileSync(
path.join(this._getDataDir(), '.config.json'),
path.join(this._getDataDir(), '.config.runtime.json'),
'utf8'
)

Expand Down
8 changes: 4 additions & 4 deletions bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
image:
name: node:12.22.10
name: node:14.19.1
run-as-user: 1000

definitions:
Expand Down Expand Up @@ -83,7 +83,7 @@ definitions:
- dist/**
- step: &pack-x64
name: Pack (x64)
image: enebularagentdevelopers/enebular-agent-x64:node-12.22.10
image: enebularagentdevelopers/enebular-agent-x64:node-14.19.1
script:
- chmod 777 pack_enebular_agent.sh
- ./pack_enebular_agent.sh
Expand All @@ -97,7 +97,7 @@ definitions:
- step: &pack-armv7l
name: Pack (armv7l)
script:
- docker run -v $(pwd):/tmp/mount -w /tmp/mount -u`id -u`:`id -g` -i enebularagentdevelopers/enebular-agent-arm32v7:node-12.22.10 /usr/bin/qemu-arm-static -execve /bin/bash -c "source ~/.profile && ./pack_enebular_agent_arm32.sh"
- docker run -v $(pwd):/tmp/mount -w /tmp/mount -u`id -u`:`id -g` -i enebularagentdevelopers/enebular-agent-arm32v7:node-14.19.1 /usr/bin/qemu-arm-static -execve /bin/bash -c "source ~/.profile && ./pack_enebular_agent_arm32.sh"
- rm -rf .git
- mkdir -p dist
- AGENT_NAME=enebular-agent-${BITBUCKET_TAG}
Expand All @@ -111,7 +111,7 @@ definitions:
name: Pack (arm64)
size: 2x
script:
- docker run -v $(pwd):/tmp/mount -w /tmp/mount -u`id -u`:`id -g` -i enebularagentdevelopers/enebular-agent-arm64v8:node-12.22.10 /usr/bin/qemu-aarch64-static -execve /bin/bash -c "source ~/.profile && ./pack_enebular_agent_arm32.sh"
- docker run -v $(pwd):/tmp/mount -w /tmp/mount -u`id -u`:`id -g` -i enebularagentdevelopers/enebular-agent-arm64v8:node-14.19.1 /usr/bin/qemu-aarch64-static -execve /bin/bash -c "source ~/.profile && ./pack_enebular_agent_arm32.sh"
- rm -rf .git
- mkdir -p dist
- AGENT_NAME=enebular-agent-${BITBUCKET_TAG}
Expand Down
6 changes: 3 additions & 3 deletions node-red/.node-red-config/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.config.json
.config.json.backup
.config.*.json
.config.*.json.backup

flows.json
flows_cred.json

.flows.json.backup

node-red-enebular-ai-nodes/nodes/*
!node-red-enebular-ai-nodes/nodes/*/
!node-red-enebular-ai-nodes/nodes/*/
1 change: 1 addition & 0 deletions node-red/.node-red-config/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
8 changes: 6 additions & 2 deletions node-red/.node-red-config/enebular-editor-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
//credentialSecret: false,
editorTheme: {
userMenu: false,
tours: false,
page: {
title: '',
favicon: path.join(__dirname, 'img', 'favicon.ico'),
Expand All @@ -24,8 +25,11 @@ module.exports = {
type: 'simple',
label: 'Save'
},
palette: {
editable: true
codeEditor: {
lib: 'monaco'
}
},
externalModules: {
autoInstall: true
}
}
11 changes: 0 additions & 11 deletions node-red/.node-red-config/package-lock.json

This file was deleted.

Loading

0 comments on commit ff3cd08

Please sign in to comment.