Fix fake-gcd-server to include device resource timestamp
Buffet now requires lastUpdateTimeMs timestamp on device resource,
so changed the test fake GCD server to include the timestamp.
Also, fixed GET request for '/devices/<id>' to retrieve the api_key
from the authorization header via access token, when this call
originates from buffet process (which does not include "?key=..."
query parameters on the URL).
BUG=brillo:1261
TEST=`test_that -b link <ip> "e:buffet_.*"`
Change-Id: I9e0a6bef538ba94ca6a57ca4b6fb873d79bc3eeb
Reviewed-on: https://chromium-review.googlesource.com/288219
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Aaron Kemp <kemp@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/client/common_lib/cros/fake_device_server/devices.py b/client/common_lib/cros/fake_device_server/devices.py
old mode 100755
new mode 100644
index 63c52c2..6e843a2
--- a/client/common_lib/cros/fake_device_server/devices.py
+++ b/client/common_lib/cros/fake_device_server/devices.py
@@ -6,6 +6,7 @@
from cherrypy import tools
import logging
+import time
import common
from fake_device_server import common_util
@@ -71,6 +72,10 @@
# Add server fields.
resource['kind'] = 'clouddevices#device'
+ current_time_ms = str(int(round(time.time() * 1000)))
+ resource['creationTimeMs'] = current_time_ms
+ resource['lastUpdateTimeMs'] = current_time_ms
+ resource['lastSeenTimeMs'] = current_time_ms
def create_device(self, api_key, device_config):
@@ -102,6 +107,9 @@
"""
self._fail_control_handler.ensure_not_in_failure_mode()
id, api_key, _ = common_util.parse_common_args(args, kwargs)
+ if not api_key:
+ access_token = common_util.get_access_token()
+ api_key = self._oauth.get_api_key_from_access_token(access_token)
if id:
return self.resource.get_data_val(id, api_key)
else:
@@ -175,7 +183,7 @@
device_id, data)
new_device = self.resource.update_data_val(device_id, api_key,
data_in=data)
- return {} # TODO(wiley) No idea what GCD returns here, leave it blank.
+ return data
def DELETE(self, *args, **kwargs):