Commit 0ffae327 authored by jrw's avatar jrw Committed by Commit bot

Added (incomplete) implementation of HostListApi using GCD.

The new implementation is activated when USE_GCD=1 at build time.

BUG=471928

Review URL: https://codereview.chromium.org/1094133003

Cr-Commit-Position: refs/heads/master@{#327111}
parent c4363d1c
......@@ -70,6 +70,11 @@ def GetAPIKey():
return _GetToken('GOOGLE_API_KEY')
def GetAPIKeyRemoting():
"""Returns the simple API key."""
return _GetToken('GOOGLE_API_KEY_REMOTING')
def GetClientID(client_name):
"""Returns the OAuth 2.0 client ID for the client of the given name."""
return _GetToken('GOOGLE_CLIENT_ID_%s' % client_name)
......@@ -82,6 +87,7 @@ def GetClientSecret(client_name):
if __name__ == "__main__":
print 'GOOGLE_API_KEY=%s' % GetAPIKey()
print 'GOOGLE_API_KEY_REMOTING=%s' % GetAPIKeyRemoting()
print 'GOOGLE_CLIENT_ID_MAIN=%s' % GetClientID('MAIN')
print 'GOOGLE_CLIENT_SECRET_MAIN=%s' % GetClientSecret('MAIN')
print 'GOOGLE_CLIENT_ID_CLOUD_PRINT=%s' % GetClientID('CLOUD_PRINT')
......
......@@ -216,6 +216,7 @@
'remoting_webapp_js_host_display_files': [
'webapp/crd/js/host_list.js',
'webapp/crd/js/host_list_api.js',
'webapp/crd/js/host_list_api_gcd_impl.js',
'webapp/crd/js/host_list_api_impl.js',
'webapp/crd/js/host_table_entry.js',
'webapp/crd/js/local_host_section.js',
......
......@@ -362,6 +362,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
# For overriding the client ID/secret via env vars, see google_api_keys.py.
apiClientId = google_api_keys.GetClientID('REMOTING')
apiClientSecret = google_api_keys.GetClientSecret('REMOTING')
apiKey = google_api_keys.GetAPIKeyRemoting()
if is_app_remoting_webapp and buildtype != 'Dev':
if not app_client_id:
......@@ -373,6 +374,7 @@ def buildWebApp(buildtype, version, destination, zip_path,
replaceString(destination, 'API_CLIENT_ID', apiClientId)
replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret)
replaceString(destination, 'API_KEY', apiKey)
# Write the application capabilities.
appCapabilities = ','.join(
......
......@@ -182,21 +182,21 @@ remoting.HostController.prototype.start = function(hostPin, consent) {
var hostName = /** @type {string} */ (a[1]);
var keyPair = /** @type {remoting.KeyPair} */ (a[2]);
return remoting.hostListApi.register(
return remoting.HostListApi.getInstance().register(
newHostId, hostName, keyPair.publicKey, hostClientId);
}).then(function(/** string */ authCode) {
}).then(function(/** string */ result) {
hostRegistered = true;
return authCode;
return result;
});
// Get XMPP creditials.
var xmppCredsPromise = authCodePromise.then(function(authCode) {
if (authCode) {
// Use auth code supplied by registry.
// Use auth code supplied by Chromoting registry.
return that.hostDaemonFacade_.getCredentialsFromAuthCode(authCode);
} else {
// No authorization code returned, use regular Chrome
// identitial credential flow.
// identity credential flow.
return remoting.identity.getEmail().then(function(/** string */ email) {
return {
userEmail: email,
......
......@@ -82,7 +82,7 @@ QUnit.module('host_controller', {
remoting.identity = new remoting.Identity();
mockHostListApi = new remoting.MockHostListApi;
mockHostListApi.registerResult = FAKE_AUTH_CODE;
remoting.hostListApi = mockHostListApi;
remoting.HostListApi.setInstance(mockHostListApi);
base.debug.assert(remoting.oauth2 === null);
remoting.oauth2 = new remoting.OAuth2();
base.debug.assert(remoting.hostList === null);
......@@ -173,7 +173,7 @@ QUnit.module('host_controller', {
remoting.hostList = null;
remoting.oauth2 = null;
chromeMocks.restore();
remoting.hostListApi = null;
remoting.HostListApi.setInstance(null);
remoting.identity = null;
}
});
......
......@@ -152,7 +152,7 @@ remoting.HostList.prototype.refresh = function(onDone) {
that.lastError_ = error;
onDone(false);
};
remoting.hostListApi.get().then(function(hosts) {
remoting.HostListApi.getInstance().get().then(function(hosts) {
onDone(that.onHostListResponse_(hosts));
}).catch(
remoting.Error.handler(onError)
......@@ -306,7 +306,7 @@ remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) {
if (index != -1) {
this.hostTableEntries_.splice(index, 1);
}
remoting.hostListApi.remove(hostTableEntry.host.hostId).
remoting.HostListApi.getInstance().remove(hostTableEntry.host.hostId).
catch(this.onError_);
};
......@@ -324,7 +324,8 @@ remoting.HostList.prototype.renameHost = function(hostTableEntry) {
}
this.save_();
remoting.hostListApi.put(hostTableEntry.host.hostId,
var hostListApi = remoting.HostListApi.getInstance();
hostListApi.put(hostTableEntry.host.hostId,
hostTableEntry.host.hostName,
hostTableEntry.host.publicKey).
catch(this.onError_);
......@@ -348,7 +349,7 @@ remoting.HostList.prototype.unregisterHostById = function(hostId, opt_onDone) {
return;
}
remoting.hostListApi.remove(hostId).
remoting.HostListApi.getInstance().remove(hostId).
then(function() {
that.refresh(function() {
that.display();
......
......@@ -7,23 +7,30 @@
* API for host-list management.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
(function() {
'use strict';
/** @interface */
remoting.HostListApi = function() {
};
/**
* @param {string} newHostId
* @param {string} hostName
* @param {string} publicKey
* @param {?string} hostClientId
* Registers a new host with the host registry service (either the
* Chromoting registry or GCD).
*
* @param {string} newHostId The ID of the new host to register.
* @param {string} hostName The user-visible name of the new host.
* @param {string} publicKey The public half of the host's key pair.
* @param {string} hostClientId The OAuth2 client ID of the host.
* @return {!Promise<string>} An OAuth2 auth code or the empty string.
*/
remoting.HostListApi.prototype.register;
remoting.HostListApi.prototype.register = function(
newHostId, hostName, publicKey, hostClientId) {
};
/**
* Fetch the list of hosts for a user.
......@@ -53,3 +60,30 @@ remoting.HostListApi.prototype.put =
*/
remoting.HostListApi.prototype.remove = function(hostId) {
};
/**
* @private {remoting.HostListApi}
*/
var instance = null;
/**
* @return {!remoting.HostListApi}
*/
remoting.HostListApi.getInstance = function() {
if (instance == null) {
instance = remoting.settings.USE_GCD ?
new remoting.HostListApiGcdImpl() :
new remoting.HostListApiImpl();
}
return instance;
};
/**
* For testing.
* @param {remoting.HostListApi} newInstance
*/
remoting.HostListApi.setInstance = function(newInstance) {
instance = newInstance;
};
})();
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* REST API for host-list management.
*/
/** @suppress {duplicate} */
var remoting = remoting || {};
(function() {
'use strict';
/**
* @constructor
* @implements {remoting.HostListApi}
*/
remoting.HostListApiGcdImpl = function() {
this.gcd_ = new remoting.gcd.Client({
apiKey: remoting.settings.GOOGLE_API_KEY
});
};
/** @override */
remoting.HostListApiGcdImpl.prototype.register = function(
newHostId, hostName, publicKey, hostClientId) {
var self = this;
var deviceDraft = {
channel: {
supportedType: 'xmpp'
},
deviceKind: 'vendor',
name: newHostId,
displayName: hostName,
state: {
'publicKey': publicKey
}
};
return /** @type {!Promise<string>} */ (
this.gcd_.insertRegistrationTicket().
then(function(ticket) {
return self.gcd_.patchRegistrationTicket(
ticket.id, deviceDraft, hostClientId);
}).
then(function(/**remoting.gcd.RegistrationTicket*/ ticket) {
return self.gcd_.finalizeRegistrationTicket(ticket.id);
}).
then(function(/**remoting.gcd.RegistrationTicket*/ ticket) {
return ticket.robotAccountAuthorizationCode;
}).
catch(function(error) {
console.error('Error registering device with GCD: ' + error);
throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED);
}));
};
/** @override */
remoting.HostListApiGcdImpl.prototype.get = function() {
// TODO(jrw)
this.gcd_.listDevices();
return Promise.resolve([]);
};
/** @override */
remoting.HostListApiGcdImpl.prototype.put =
function(hostId, hostName, hostPublicKey) {
// TODO(jrw)
throw new Error('Not implemented');
};
/** @override */
remoting.HostListApiGcdImpl.prototype.remove = function(hostId) {
// TODO(jrw)
throw new Error('Not implemented');
};
})();
......@@ -159,7 +159,4 @@ remoting.HostListApiImpl.defaultResponse_ = function(opt_ignoreErrors) {
return result;
};
/** @type {remoting.HostListApi} */
remoting.hostListApi = new remoting.HostListApiImpl();
})();
......@@ -52,7 +52,9 @@ remoting.MockHostListApi.prototype.register = function(
newHostId, hostName, publicKey, hostClientId) {
if (this.registerResult === null) {
return Promise.reject(
new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED));
new remoting.Error(
remoting.Error.Tag.REGISTRATION_FAILED,
'MockHostListApi.register'));
} else {
return Promise.resolve(this.registerResult);
}
......@@ -61,13 +63,18 @@ remoting.MockHostListApi.prototype.register = function(
/** @override */
remoting.MockHostListApi.prototype.get = function() {
var that = this;
new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
remoting.mockIdentity.validateTokenAndCall(
resolve, remoting.Error.handler(reject), [that.hosts]);
});
};
/** @override */
/**
* @override
* @param {string} hostId
* @param {string} hostName
* @param {string} hostPublicKey
*/
remoting.MockHostListApi.prototype.put =
function(hostId, hostName, hostPublicKey) {
/** @type {remoting.MockHostListApi} */
......@@ -91,7 +98,10 @@ remoting.MockHostListApi.prototype.put =
});
};
/** @override */
/**
* @override
* @param {string} hostId
*/
remoting.MockHostListApi.prototype.remove = function(hostId) {
/** @type {remoting.MockHostListApi} */
var that = this;
......@@ -116,6 +126,6 @@ remoting.MockHostListApi.prototype.remove = function(hostId) {
* @param {boolean} active
*/
remoting.MockHostListApi.setActive = function(active) {
remoting.hostListApi = active ? new remoting.MockHostListApi()
: new remoting.HostListApiImpl();
remoting.HostListApi.setInstance(
active ? new remoting.MockHostListApi() : null);
};
......@@ -23,6 +23,8 @@ remoting.Settings = function() {};
remoting.Settings.prototype.OAUTH2_CLIENT_ID = 'API_CLIENT_ID';
/** @type {string} API client secret.*/
remoting.Settings.prototype.OAUTH2_CLIENT_SECRET = 'API_CLIENT_SECRET';
/** @type {string} Google API Key.*/
remoting.Settings.prototype.GOOGLE_API_KEY = 'API_KEY';
/** @type {string} Base URL for OAuth2 authentication. */
remoting.Settings.prototype.OAUTH2_BASE_URL = 'OAUTH2_BASE_URL';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment