Skip to content
This repository has been archived by the owner. It is now read-only.

Add support for "device commands" feature. #2449

Merged
merged 1 commit into from Jun 27, 2018
Merged

Add support for "device commands" feature. #2449

merged 1 commit into from Jun 27, 2018

Conversation

@rfk
Copy link
Member

@rfk rfk commented May 22, 2018

This is an extension of and alternative to the "device messages" feature from #2328, that's designed to support the latest requirements of new-send-tab while being a step along to road to a more general peer discovery API.

As part of its device registration, a device can include a set of "supported commands". This is a simple mapping where the keys are string URIs naming commands that the device can be asked to perform, and the values are additional metadata necessary in order to invoke the command. Other devices can query the device list to discover their peers and the commands that they support, and can invoke a command on another device by issuing a POST request.

A good place to start is the new device registration documentation that's included as part of this PR. This feature branch is also deployed to https://pushbox2.dev.lcip.org if you'd like to poke at the API live.

Connects to #2318

@ghost ghost assigned rfk May 22, 2018
@ghost ghost added the waffle:active label May 22, 2018
@rfk rfk force-pushed the feature.pushbox-ng branch from 0c9d891 to 9164d7f May 22, 2018
with additional event-specific data.

The currently supported commands are:

This comment has been minimized.

@eoger

eoger May 22, 2018
Contributor

Should we also talk about the payload-less command that means "account/session verified"?

@rfk rfk force-pushed the feature.pushbox-ng branch 18 times, most recently from 82cb0a0 to 1da476f May 23, 2018
@rfk rfk force-pushed the feature.pushbox-ng branch from 1da476f to 3fc0041 May 29, 2018
@@ -85,7 +85,7 @@
"acorn": "5.0.3",
"commander": "2.9.0",
"eslint-plugin-fxa": "git+https://github.com/mozilla/eslint-plugin-fxa#master",
"fxa-auth-db-mysql": "git+https://github.com/mozilla/fxa-auth-db-mysql.git#master",
"fxa-auth-db-mysql": "git+https://github.com/mozilla/fxa-auth-db-mysql.git#feature.pushbox-ng",

This comment has been minimized.

@rfk

rfk May 29, 2018
Author Member

We'll need to revert this before merge.

@@ -101,8 +101,6 @@ describe('remote session', function() {
})
.then(() => {
return client.api.sessionStatus(sessionTokenCreate)
}, () => {
assert(false, 'failed to destroy the session')

This comment has been minimized.

@rfk

rfk May 29, 2018
Author Member

This was unnecessary given that we catch and check the error below.

@rfk rfk force-pushed the feature.pushbox-ng branch from 3fc0041 to 234647a May 29, 2018
@rfk rfk changed the title WIP Add support for "device commands" feature. Add support for "device commands" feature. May 29, 2018
@rfk
Copy link
Member Author

@rfk rfk commented Jun 7, 2018

"https://identity.mozilla.com/cmd/open-uri"

Aha, my regex was not allowing the "." character in this string. If you use a short name like "open-uri" for testing then it should work. I'll see about getting an update pushed on the rebuilt box shortly.

@rfk rfk force-pushed the feature.pushbox-ng branch 4 times, most recently from cd96491 to 1cbe3fe Jun 20, 2018
@rfk
Copy link
Member Author

@rfk rfk commented Jun 20, 2018

So, we've had this up and running for a while on https://pushbox2.dev.lcip.org and it seems to be working as intended. @eoger was able to point a desktop implementation of send-tab at it and things worked correctly. I've done another pass, fleshed out the docs and addressed a few nits, so I think it's ready for a final r?

@eoger, do you have any final commentary or changes to the naming here based on your client implementation? In particular I'm wondering about changing "messages" to "commands" in the response for /account/device/commands, but any other feedback before we land will be valuable.

@mozilla/fxa-devs r?

@rfk rfk requested review from eoger and mozilla/fxa-devs Jun 20, 2018
docs/api.md Outdated
The time in milliseconds after which the command should expire,
if not processed by the device.

<!--end-request-body-post-accountdevicesinvoke_command-ttl-->

This comment has been minimized.

@philbooth

philbooth Jun 20, 2018
Contributor

Excellent docs, thanks!

url: {
doc: 'Pushbox Server URL',
format: 'url',
default: 'http://localhost:8057/',

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jun 20, 2018
Member

Do we still default to production values? Is this the production value?

This comment has been minimized.

@rfk

rfk Jun 20, 2018
Author Member

You're right we should, but we don't (yet) have a production value until the service gets deployed. I'll find out if that's been decided yet. Also note that we land it preffed off by default.

@@ -278,6 +280,8 @@ for `code` and `errno` are:
A TOTP token not found.
* `code: 400, errno: 156`:
Recovery code not found.
* `code: 400, errno: 157`:

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jun 20, 2018
Member

Is this errno ever surfaced to the content server? If so, we'll need to add an entry for it.

This comment has been minimized.

@vbudhram

vbudhram Jun 20, 2018
Contributor

Tracking this here.

This comment has been minimized.

@rfk

rfk Jun 20, 2018
Author Member

The content-server should never see an "unavailable device command" error unless it tries to invoke a device command for itself, which I don't think we've got plans to do anytime soon.

This comment has been minimized.

@vbudhram

vbudhram Jun 20, 2018
Contributor

@shane-tomlinson I misread your comment as recovery code was not surfaced. I'll keep the linked bug open since we could do a little cleanup there.

The device may wish to update
any cached list of other connected devices.
* `fxaccounts:device_disconnected`:
A device has been disconnected to the account.

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jun 20, 2018
Member

to the account => from the account

## Device Commands

Connected devices may be able to
offer functionality to one other

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jun 20, 2018
Member

to one other or one another?

lib/db.js Outdated
const mergedInfo = Object.assign({}, device, token)
return {
id: device.id,
sessionToken: device.sessionTokenId,

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jun 20, 2018
Member

Shouldn't sessionTokenId already be in mergedInfo? I'm confused why mergedInfo is created and then some fields are fetched from device instead.

This comment has been minimized.

@rfk

rfk Jun 20, 2018
Author Member

I don't think there's any particular reason, it's just that we know some of those keys are only on the device that we read from the db. I'll make them all mergedInfo for consistency, assuming that doesn't surprise me with any test bustage.

@rfk rfk force-pushed the feature.pushbox-ng branch 2 times, most recently from fae3465 to 5b455f7 Jun 20, 2018
@eoger
eoger approved these changes Jun 25, 2018
Copy link
Contributor

@eoger eoger left a comment

I read this a second time, and also worked with that code on my desktop patch. I'm pretty happy with what we have here, I think we should merge.
Awesome work by the way, the patch looks great :)

Copy link
Contributor

@philbooth philbooth left a comment

OFFICIAL r+

@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented Jun 26, 2018

@rfk - the api.md file looks like a trivial merge conflict, but I don't want to fix & merge in case you have additional changes you'd like to make. Can you merge when ready so we can cut the train?

@rfk
Copy link
Member Author

@rfk rfk commented Jun 26, 2018

Thanks @PB @shane-tomlinson, rebased on latest master and will merge when green.

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jun 26, 2018

@rfk seems like tests failed

@rfk
Copy link
Member Author

@rfk rfk commented Jun 26, 2018

Yeah, will dig in after meetings :-(

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jun 26, 2018

@rfk

    "hapi-hpkp": "git+https://github.com/vbudhram/hapi-hpkp.git#master",

^ This needs to use a v1.x version of the plugin, not the master branch

@vladikoff
Copy link
Contributor

@vladikoff vladikoff commented Jun 26, 2018

@rfk rfk force-pushed the feature.pushbox-ng branch from 512e806 to cba1aa9 Jun 26, 2018
@rfk
Copy link
Member Author

@rfk rfk commented Jun 26, 2018

Thanks @vladikoff, looks like that fixed it.

@rfk rfk merged commit f359006 into master Jun 27, 2018
3 checks passed
3 checks passed
ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants