mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-17 23:53:25 +02:00
ADB connect now respects auth keys in the settings page.
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user