buffet: Make RegisterDevice accept only ticket ID
Changing name, description and location is possible using
UpdateDeviceInfo.
BUG=none
TEST='FEATURES=test emerge-gizmo buffet'
CQ-DEPEND=CL:*216413,CL:271616
Change-Id: Ieed8b8537184e0dada9c36551ee7502bd50259f4
Reviewed-on: https://chromium-review.googlesource.com/271377
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/buffet_client.cc b/buffet/buffet_client.cc
index a874ec0..ef4bf03 100644
--- a/buffet/buffet_client.cc
+++ b/buffet/buffet_client.cc
@@ -313,17 +313,18 @@
void CallRegisterDevice(const std::string& args,
ManagerProxy* manager_proxy) {
- chromeos::VariantDictionary params;
+ std::string ticket_id;
if (!args.empty()) {
auto key_values = chromeos::data_encoding::WebParamsDecode(args);
for (const auto& pair : key_values) {
- params.insert(std::make_pair(pair.first, chromeos::Any(pair.second)));
+ if (pair.first == "ticket_id")
+ ticket_id = pair.second;
}
}
ErrorPtr error;
std::string device_id;
- if (!manager_proxy->RegisterDevice(params, &device_id, &error)) {
+ if (!manager_proxy->RegisterDevice(ticket_id, &device_id, &error)) {
return ReportError(error.get());
}
@@ -380,8 +381,8 @@
}
void CallSetCommandVisibility(const std::string& command_list,
- const std::string& visibility,
- ManagerProxy* manager_proxy) {
+ const std::string& visibility,
+ ManagerProxy* manager_proxy) {
ErrorPtr error;
std::vector<std::string> commands =
chromeos::string_utils::Split(command_list, ",", true, true);
diff --git a/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
index 67c265d..73d3547 100644
--- a/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
+++ b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
@@ -17,7 +17,7 @@
<annotation name="org.chromium.DBus.Method.Kind" value="async"/>
</method>
<method name="RegisterDevice">
- <arg name="params" type="a{sv}" direction="in"/>
+ <arg name="ticket_id" type="s" direction="in"/>
<arg name="device_id" type="s" direction="out"/>
<annotation name="org.chromium.DBus.Method.Kind" value="async"/>
</method>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 7d8c608..454853b 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -26,7 +26,6 @@
#include "buffet/commands/command_definition.h"
#include "buffet/commands/command_manager.h"
#include "buffet/commands/schema_constants.h"
-#include "buffet/device_registration_storage_keys.h"
#include "buffet/notification/xmpp_channel.h"
#include "buffet/states/state_manager.h"
#include "buffet/utils.h"
@@ -35,23 +34,6 @@
const char buffet::kErrorDomainGCD[] = "gcd";
const char buffet::kErrorDomainGCDServer[] = "gcd_server";
-namespace buffet {
-namespace storage_keys {
-
-// Persistent keys
-const char kRefreshToken[] = "refresh_token";
-const char kDeviceId[] = "device_id";
-const char kRobotAccount[] = "robot_account";
-const char kName[] = "name";
-const char kDescription[] = "description";
-const char kLocation[] = "location";
-const char kLocalAnonymousAccessRole[] = "local_anonymous_access_role";
-const char kLocalDiscoveryEnabled[] = "local_discovery_enabled";
-const char kLocalPairingEnabled[] = "local_pairing_enabled";
-
-} // namespace storage_keys
-} // namespace buffet
-
namespace {
const int kMaxStartDeviceRetryDelayMinutes{1};
@@ -390,47 +372,8 @@
return json;
}
-namespace {
-
-bool GetWithDefault(const std::map<std::string, std::string>& source,
- const std::string& key,
- const std::string& default_value,
- std::string* output) {
- auto it = source.find(key);
- if (it == source.end()) {
- *output = default_value;
- return false;
- }
- *output = it->second;
- return true;
-}
-
-} // namespace
-
-std::string DeviceRegistrationInfo::RegisterDevice(
- const std::map<std::string, std::string>& params,
- chromeos::ErrorPtr* error) {
- std::string ticket_id;
- if (!GetWithDefault(params, "ticket_id", "", &ticket_id)) {
- chromeos::Error::AddTo(error, FROM_HERE, kErrorDomainBuffet,
- "missing_parameter",
- "Need ticket_id parameter for RegisterDevice()");
- return std::string();
- }
-
- // These fields are optional, and will default to values from the manufacturer
- // supplied config.
- std::string name;
- GetWithDefault(params, storage_keys::kName, config_->name(), &name);
- std::string description;
- GetWithDefault(params, storage_keys::kDescription, config_->description(),
- &description);
- std::string location;
- GetWithDefault(params, storage_keys::kLocation, config_->location(),
- &location);
- if (!UpdateDeviceInfo(name, description, location, error))
- return std::string();
-
+std::string DeviceRegistrationInfo::RegisterDevice(const std::string& ticket_id,
+ chromeos::ErrorPtr* error) {
std::unique_ptr<base::DictionaryValue> device_draft =
BuildDeviceResource(error);
if (!device_draft)
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h
index c9ca7b4..5a9a1a3 100644
--- a/buffet/device_registration_info.h
+++ b/buffet/device_registration_info.h
@@ -105,13 +105,8 @@
chromeos::ErrorPtr* error);
// Registers the device.
- //
- // |params| are a list of key-value pairs of device information,
- // such as client_id, client_secret, and so on. If a particular key-value pair
- // is omitted, a default value is used when possible.
// Returns a device ID on success.
- // The values are all strings for now.
- std::string RegisterDevice(const std::map<std::string, std::string>& params,
+ std::string RegisterDevice(const std::string& ticket_id,
chromeos::ErrorPtr* error);
// Updates a command.
diff --git a/buffet/device_registration_info_unittest.cc b/buffet/device_registration_info_unittest.cc
index f41d408..e3e9d22 100644
--- a/buffet/device_registration_info_unittest.cc
+++ b/buffet/device_registration_info_unittest.cc
@@ -16,7 +16,6 @@
#include "buffet/commands/command_manager.h"
#include "buffet/commands/unittest_utils.h"
-#include "buffet/device_registration_storage_keys.h"
#include "buffet/states/mock_state_change_queue_interface.h"
#include "buffet/states/state_manager.h"
#include "buffet/storage_impls.h"
@@ -55,14 +54,13 @@
"VZDei530-w0yE2urpQ";
const char kUserRefreshToken[] = "1/zQLKjlKJlkLkLKjLkjLKjLkjLjLkjl0ftc6"
"cp1nI-GQ";
-
} // namespace test_data
// Add the test device registration information.
void SetDefaultDeviceRegistration(base::DictionaryValue* data) {
- data->SetString(storage_keys::kRefreshToken, test_data::kRefreshToken);
- data->SetString(storage_keys::kDeviceId, test_data::kDeviceId);
- data->SetString(storage_keys::kRobotAccount, test_data::kRobotAccountEmail);
+ data->SetString("refresh_token", test_data::kRefreshToken);
+ data->SetString("device_id", test_data::kDeviceId);
+ data->SetString("robot_account", test_data::kRobotAccountEmail);
}
void OAuth2Handler(const ServerRequest& request, ServerResponse* response) {
@@ -447,9 +445,8 @@
transport_->AddHandler(dev_reg_->GetOAuthURL("token"),
chromeos::http::request_type::kPost,
base::Bind(OAuth2Handler));
- std::map<std::string, std::string> params;
- params["ticket_id"] = test_data::kClaimTicketId;
- std::string device_id = dev_reg_->RegisterDevice(params, nullptr);
+ std::string device_id =
+ dev_reg_->RegisterDevice(test_data::kClaimTicketId, nullptr);
EXPECT_EQ(test_data::kDeviceId, device_id);
EXPECT_EQ(3, transport_->GetRequestCount());
@@ -460,11 +457,11 @@
base::DictionaryValue* dict = nullptr;
EXPECT_TRUE(storage_data->GetAsDictionary(&dict));
std::string value;
- EXPECT_TRUE(dict->GetString(storage_keys::kDeviceId, &value));
+ EXPECT_TRUE(dict->GetString("device_id", &value));
EXPECT_EQ(test_data::kDeviceId, value);
- EXPECT_TRUE(dict->GetString(storage_keys::kRefreshToken, &value));
+ EXPECT_TRUE(dict->GetString("refresh_token", &value));
EXPECT_EQ(test_data::kRefreshToken, value);
- EXPECT_TRUE(dict->GetString(storage_keys::kRobotAccount, &value));
+ EXPECT_TRUE(dict->GetString("robot_account", &value));
EXPECT_EQ(test_data::kRobotAccountEmail, value);
}
diff --git a/buffet/device_registration_storage_keys.h b/buffet/device_registration_storage_keys.h
deleted file mode 100644
index 5ce8083..0000000
--- a/buffet/device_registration_storage_keys.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2014 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BUFFET_DEVICE_REGISTRATION_STORAGE_KEYS_H_
-#define BUFFET_DEVICE_REGISTRATION_STORAGE_KEYS_H_
-
-// These are the keys used to identify specific device registration information
-// being saved to a storage. Used mostly internally by DeviceRegistrationInfo
-// but also exposed so that tests can access them.
-namespace buffet {
-namespace storage_keys {
-
-extern const char kRefreshToken[];
-extern const char kDeviceId[];
-extern const char kRobotAccount[];
-extern const char kName[];
-extern const char kDescription[];
-extern const char kLocation[];
-extern const char kLocalAnonymousAccessRole[];
-extern const char kLocalDiscoveryEnabled[];
-extern const char kLocalPairingEnabled[];
-
-} // namespace storage_keys
-} // namespace buffet
-
-#endif // BUFFET_DEVICE_REGISTRATION_STORAGE_KEYS_H_
diff --git a/buffet/manager.cc b/buffet/manager.cc
index d21ec8b..78a0a8c 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -116,22 +116,11 @@
}
void Manager::RegisterDevice(DBusMethodResponse<std::string> response,
- const chromeos::VariantDictionary& params) {
+ const std::string& ticket_id) {
LOG(INFO) << "Received call to Manager.RegisterDevice()";
chromeos::ErrorPtr error;
- std::map<std::string, std::string> str_params;
- for (const auto& pair : params) {
- if (!pair.second.IsTypeCompatible<std::string>()) {
- response->ReplyWithError(FROM_HERE, chromeos::errors::dbus::kDomain,
- DBUS_ERROR_INVALID_ARGS,
- "String value expected");
- return;
- }
- str_params.emplace_hint(str_params.end(), pair.first,
- pair.second.Get<std::string>());
- }
- std::string device_id = device_info_->RegisterDevice(str_params, &error);
+ std::string device_id = device_info_->RegisterDevice(ticket_id, &error);
if (!device_id.empty()) {
response->Return(device_id);
return;
diff --git a/buffet/manager.h b/buffet/manager.h
index 479ac9b..b15d7b0 100644
--- a/buffet/manager.h
+++ b/buffet/manager.h
@@ -62,7 +62,7 @@
void CheckDeviceRegistered(DBusMethodResponse<std::string> response) override;
void GetDeviceInfo(DBusMethodResponse<std::string> response) override;
void RegisterDevice(DBusMethodResponse<std::string> response,
- const chromeos::VariantDictionary& params) override;
+ const std::string& ticket_id) override;
bool UpdateDeviceInfo(chromeos::ErrorPtr* error,
const std::string& in_name,
const std::string& in_description,