mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 00:03:28 +02:00
* Upgrading STF for security reasons Signed-off-by: Denis barbaron <denis.barbaron@orange.com> * update semaphore files Signed-off-by: Denis barbaron <denis.barbaron@orange.com> * upgrading STF for security reasons v2 Signed-off-by: Denis barbaron <denis.barbaron@orange.com> * update yarn.lock file Signed-off-by: Denis barbaron <denis.barbaron@orange.com> --------- Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
//
|
|
// Copyright © 2022-2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
|
|
//
|
|
|
|
/* global BigInt */
|
|
/* eslint no-extend-native: ["error", { "exceptions": ["BigInt"] }] */
|
|
|
|
BigInt.prototype.toJSON = function() {
|
|
return Number(this)
|
|
}
|
|
|
|
var uuid = require('uuid')
|
|
|
|
var wire = require('./')
|
|
|
|
var wireutil = {
|
|
global: '*ALL'
|
|
, makePrivateChannel: function() {
|
|
return uuid.v4(null, Buffer.alloc(16)).toString('base64')
|
|
}
|
|
, toDeviceStatus: function(type) {
|
|
return wire.DeviceStatus[{
|
|
device: 'ONLINE'
|
|
, emulator: 'ONLINE'
|
|
, unauthorized: 'UNAUTHORIZED'
|
|
, offline: 'OFFLINE'
|
|
, connecting: 'CONNECTING'
|
|
, authorizing: 'AUTHORIZING'
|
|
}[type]]
|
|
}
|
|
, toDeviceRequirements: function(requirements) {
|
|
return Object.keys(requirements).map(function(name) {
|
|
var item = requirements[name]
|
|
return new wire.DeviceRequirement(
|
|
name
|
|
, item.value
|
|
, wire.RequirementType[item.match.toUpperCase()]
|
|
)
|
|
})
|
|
}
|
|
, envelope: function(message) {
|
|
return new wire.Envelope(message.$code, message.encode()).encodeNB()
|
|
}
|
|
, transaction: function(channel, message) {
|
|
return new wire.Envelope(
|
|
message.$code
|
|
, message.encode()
|
|
, channel
|
|
)
|
|
.encodeNB()
|
|
}
|
|
, reply: function(source) {
|
|
var seq = 0
|
|
return {
|
|
okay: function(data, body) {
|
|
return wireutil.envelope(new wire.TransactionDoneMessage(
|
|
source
|
|
, seq++
|
|
, true
|
|
, data === null ? null : (data || 'success')
|
|
, body ? JSON.stringify(body) : null
|
|
))
|
|
}
|
|
, fail: function(data, body) {
|
|
return wireutil.envelope(new wire.TransactionDoneMessage(
|
|
source
|
|
, seq++
|
|
, false
|
|
, data || 'fail'
|
|
, body ? JSON.stringify(body) : null
|
|
))
|
|
}
|
|
, progress: function(data, progress) {
|
|
return wireutil.envelope(new wire.TransactionProgressMessage(
|
|
source
|
|
, seq++
|
|
, data
|
|
, ~~progress
|
|
))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = wireutil
|