mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 16:43:26 +02:00
Implement addAdbPublicKey endpoint
Reason: manually approve adb connection from web UI does not scale for test automation. Especially those that are using different adb keys on each session (eg: via container) This changes also added swagger doc endpoint. Using `stf local` command, it will end up at: `http://localhost:7106/docs/`
This commit is contained in:
@@ -3,7 +3,7 @@ var util = require('util')
|
||||
var _ = require('lodash')
|
||||
var Promise = require('bluebird')
|
||||
var uuid = require('uuid')
|
||||
|
||||
var adbkit = require('adbkit')
|
||||
var dbapi = require('../../../db/api')
|
||||
var logger = require('../../../util/logger')
|
||||
var datautil = require('../../../util/datautil')
|
||||
@@ -23,6 +23,7 @@ module.exports = {
|
||||
, remoteConnectUserDeviceBySerial: remoteConnectUserDeviceBySerial
|
||||
, remoteDisconnectUserDeviceBySerial: remoteDisconnectUserDeviceBySerial
|
||||
, getUserAccessTokens: getUserAccessTokens
|
||||
, addAdbPublicKey: addAdbPublicKey
|
||||
}
|
||||
|
||||
function getUser(req, res) {
|
||||
@@ -400,3 +401,57 @@ function getUserAccessTokens(req, res) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function addAdbPublicKey(req, res) {
|
||||
var data = req.swagger.params.adb.value
|
||||
adbkit.util.parsePublicKey(data.publickey)
|
||||
.then(function(key) {
|
||||
return dbapi.lookupUsersByAdbKey(key.fingerprint)
|
||||
.then(function(cursor) {
|
||||
return cursor.toArray()
|
||||
})
|
||||
.then(function(users) {
|
||||
return {
|
||||
key: {
|
||||
title: data.title || key.comment,
|
||||
fingerprint: key.fingerprint
|
||||
},
|
||||
users: users
|
||||
}
|
||||
})
|
||||
})
|
||||
.then(function(data) {
|
||||
|
||||
if (data.users.length) {
|
||||
return res.json({
|
||||
success: true
|
||||
})
|
||||
}
|
||||
else {
|
||||
return dbapi.insertUserAdbKey(req.user.email, data.key)
|
||||
.then(function() {
|
||||
return res.json({
|
||||
success: true
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
.then(function() {
|
||||
req.options.push.send([
|
||||
req.user.group
|
||||
, wireutil.envelope(new wire.AdbKeysUpdatedMessage())
|
||||
])
|
||||
})
|
||||
.catch(dbapi.DuplicateSecondaryIndexError, function() {
|
||||
// No-op
|
||||
return res.json({
|
||||
success: true
|
||||
})
|
||||
}).catch(function(err) {
|
||||
log.error('Failed to insert new adb key fingerprint: ', err.stack)
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Unable to insert new adb key fingerprint to database"
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user