mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
ADB connect now respects auth keys in the settings page.
This commit is contained in:
parent
0a67c8c272
commit
e6c1de5194
12 changed files with 322 additions and 49 deletions
|
@ -1,10 +1,19 @@
|
|||
var r = require('rethinkdb')
|
||||
var util = require('util')
|
||||
|
||||
var db = require('./')
|
||||
var wireutil = require('../wire/util')
|
||||
|
||||
var dbapi = Object.create(null)
|
||||
|
||||
dbapi.DuplicateSecondaryIndexError = function DuplicateSecondaryIndexError() {
|
||||
Error.call(this)
|
||||
this.name = 'DuplicateSecondaryIndexError'
|
||||
Error.captureStackTrace(this, DuplicateSecondaryIndexError)
|
||||
}
|
||||
|
||||
util.inherits(dbapi.DuplicateSecondaryIndexError, Error)
|
||||
|
||||
dbapi.close = function(options) {
|
||||
return db.close(options)
|
||||
}
|
||||
|
@ -48,6 +57,49 @@ dbapi.resetUserSettings = function(email) {
|
|||
}))
|
||||
}
|
||||
|
||||
dbapi.insertUserAdbKey = function(email, key) {
|
||||
return db.run(r.table('users').get(email).update({
|
||||
adbKeys: r.row('adbKeys').default([]).append({
|
||||
title: key.title
|
||||
, fingerprint: key.fingerprint
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
dbapi.deleteUserAdbKey = function(email, fingerprint) {
|
||||
return db.run(r.table('users').get(email).update({
|
||||
adbKeys: r.row('adbKeys').default([]).filter(function(key) {
|
||||
return key('fingerprint').ne(fingerprint)
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
dbapi.lookupUsersByAdbKey = function(fingerprint) {
|
||||
return db.run(r.table('users').getAll(fingerprint, {
|
||||
index: 'adbKeys'
|
||||
}))
|
||||
}
|
||||
|
||||
dbapi.lookupUserByAdbFingerprint = function(fingerprint) {
|
||||
return db.run(r.table('users').getAll(fingerprint, {
|
||||
index: 'adbKeys'
|
||||
})
|
||||
.pluck('email', 'name', 'group'))
|
||||
.then(function(cursor) {
|
||||
return cursor.toArray()
|
||||
})
|
||||
.then(function(groups) {
|
||||
switch (groups.length) {
|
||||
case 1:
|
||||
return groups[0]
|
||||
case 0:
|
||||
return null
|
||||
default:
|
||||
throw new Error('Found multiple users for same ADB fingerprint')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
dbapi.addUserForward = function(email, forward) {
|
||||
var devicePort = forward.devicePort
|
||||
return db.run(r.table('users').get(email).update({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue