buffet: Rework buffet configuration Manufacturer supplied fields will come from the buffet configuration file with good defaults provided by buffet itself. This includes a few default values for user supplied fields. User supplied and other per device instance state will be stored in a state file as before. Keeping these fields separate greatly simplifies reasoning about adding configuration settings to buffet. BUG=brillo:658 TEST=unittests, tendo_experimental passes CQ-DEPEND=CL:262292 Change-Id: Ib74721b9c99d11c189042aa78cc43a076072de32 Reviewed-on: https://chromium-review.googlesource.com/262296 Tested-by: Christopher Wiley <wiley@chromium.org> Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Reviewed-by: Anton Muhin <antonm@chromium.org> Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/buffet/buffet.gyp b/buffet/buffet.gyp index 51312e5..e67b6ea 100644 --- a/buffet/buffet.gyp +++ b/buffet/buffet.gyp
@@ -18,6 +18,7 @@ 'dbus_service_config': 'dbus_bindings/dbus-service-config.json', }, 'sources': [ + 'buffet_config.cc', 'commands/command_definition.cc', 'commands/command_dictionary.cc', 'commands/command_instance.cc',
diff --git a/buffet/buffet_config.cc b/buffet/buffet_config.cc new file mode 100644 index 0000000..36acee9 --- /dev/null +++ b/buffet/buffet_config.cc
@@ -0,0 +1,45 @@ +// Copyright 2015 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. + +#include "buffet/buffet_config.h" + +namespace buffet { +namespace config_keys { + +const char kClientId[] = "client_id"; +const char kClientSecret[] = "client_secret"; +const char kApiKey[] = "api_key"; +const char kOAuthURL[] = "oauth_url"; +const char kServiceURL[] = "service_url"; +const char kDeviceKind[] = "device_kind"; +const char kName[] = "name"; +const char kDefaultDisplayName[] = "default_display_name"; +const char kDefaultDescription[] = "default_description"; +const char kDefaultLocation[] = "default_location"; +const char kModelId[] = "model_id"; + +} // namespace config_keys + +void BuffetConfig::Load(const base::FilePath& config_path) { + chromeos::KeyValueStore store; + if (store.Load(config_path)) { + Load(store); + } +} + +void BuffetConfig::Load(const chromeos::KeyValueStore& store) { + store.GetString(config_keys::kClientId, &client_id_); + store.GetString(config_keys::kClientSecret, &client_secret_); + store.GetString(config_keys::kApiKey, &api_key_); + store.GetString(config_keys::kOAuthURL, &oauth_url_); + store.GetString(config_keys::kServiceURL, &service_url_); + store.GetString(config_keys::kDeviceKind, &device_kind_); + store.GetString(config_keys::kName, &name_); + store.GetString(config_keys::kDefaultDisplayName, &default_display_name_); + store.GetString(config_keys::kDefaultDescription, &default_description_); + store.GetString(config_keys::kDefaultLocation, &default_location_); + store.GetString(config_keys::kModelId, &model_id_); +} + +} // namespace buffet
diff --git a/buffet/buffet_config.h b/buffet/buffet_config.h new file mode 100644 index 0000000..539191e --- /dev/null +++ b/buffet/buffet_config.h
@@ -0,0 +1,52 @@ +// Copyright 2015 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_BUFFET_CONFIG_H_ +#define BUFFET_BUFFET_CONFIG_H_ + +#include <string> + +#include <base/files/file_path.h> +#include <chromeos/key_value_store.h> + +namespace buffet { + +class BuffetConfig { + public: + BuffetConfig() = default; + + void Load(const base::FilePath& config_path); + void Load(const chromeos::KeyValueStore& store); + + std::string client_id() const { return client_id_; } + std::string client_secret() const { return client_secret_; } + std::string api_key() const { return api_key_; } + std::string oauth_url() const { return oauth_url_; } + std::string service_url() const { return service_url_; } + std::string device_kind() const { return device_kind_; } + std::string name() const { return name_; } + std::string default_display_name() const { return default_display_name_; } + std::string default_description() const { return default_description_; } + std::string default_location() const { return default_location_; } + std::string model_id() const { return model_id_; } + + private: + std::string client_id_{"58855907228.apps.googleusercontent.com"}; + std::string client_secret_{"eHSAREAHrIqPsHBxCE9zPPBi"}; + std::string api_key_{"AIzaSyDSq46gG-AxUnC3zoqD9COIPrjolFsMfMA"}; + std::string oauth_url_{"https://accounts.google.com/o/oauth2/"}; + std::string service_url_{"https://www.googleapis.com/clouddevices/v1/"}; + std::string device_kind_{"vendor"}; + std::string name_{"developer_device"}; + std::string default_display_name_{"Developer device"}; + std::string default_description_{"A development device"}; + std::string default_location_{"my desk"}; + std::string model_id_{"AAA"}; + + DISALLOW_COPY_AND_ASSIGN(BuffetConfig); +}; + +} // namespace buffet + +#endif // BUFFET_BUFFET_CONFIG_H_
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc index 380d75a..3f7e17c 100644 --- a/buffet/device_registration_info.cc +++ b/buffet/device_registration_info.cc
@@ -36,22 +36,12 @@ namespace storage_keys { // Persistent keys -const char kClientId[] = "client_id"; -const char kClientSecret[] = "client_secret"; -const char kApiKey[] = "api_key"; const char kRefreshToken[] = "refresh_token"; const char kDeviceId[] = "device_id"; -const char kOAuthURL[] = "oauth_url"; -const char kServiceURL[] = "service_url"; const char kRobotAccount[] = "robot_account"; -// Transient keys -const char kDeviceKind[] = "device_kind"; -const char kName[] = "name"; const char kDisplayName[] = "display_name"; const char kDescription[] = "description"; const char kLocation[] = "location"; -const char kModelId[] = "model_id"; - } // namespace storage_keys } // namespace buffet @@ -133,7 +123,7 @@ DeviceRegistrationInfo::DeviceRegistrationInfo( const std::shared_ptr<CommandManager>& command_manager, const std::shared_ptr<StateManager>& state_manager, - std::unique_ptr<chromeos::KeyValueStore> config_store, + std::unique_ptr<const BuffetConfig> config, const std::shared_ptr<chromeos::http::Transport>& transport, const std::shared_ptr<StorageInterface>& state_store, const base::Closure& on_status_changed) @@ -141,7 +131,7 @@ storage_{state_store}, command_manager_{command_manager}, state_manager_{state_manager}, - config_store_{std::move(config_store)}, + config_{std::move(config)}, on_status_changed_{on_status_changed} { } @@ -155,20 +145,21 @@ std::string DeviceRegistrationInfo::GetServiceURL( const std::string& subpath, const chromeos::data_encoding::WebParamList& params) const { - return BuildURL(service_url_, {subpath}, params); + return BuildURL(config_->service_url(), {subpath}, params); } std::string DeviceRegistrationInfo::GetDeviceURL( const std::string& subpath, const chromeos::data_encoding::WebParamList& params) const { CHECK(!device_id_.empty()) << "Must have a valid device ID"; - return BuildURL(service_url_, {"devices", device_id_, subpath}, params); + return BuildURL(config_->service_url(), + {"devices", device_id_, subpath}, params); } std::string DeviceRegistrationInfo::GetOAuthURL( const std::string& subpath, const chromeos::data_encoding::WebParamList& params) const { - return BuildURL(oauth_url_, {subpath}, params); + return BuildURL(config_->oauth_url(), {subpath}, params); } const std::string& DeviceRegistrationInfo::GetDeviceId() const { @@ -187,60 +178,22 @@ // Get the values into temp variables first to make sure we can get // all the data correctly before changing the state of this object. - std::string client_id; - if (!dict->GetString(storage_keys::kClientId, &client_id)) - return false; - std::string client_secret; - if (!dict->GetString(storage_keys::kClientSecret, &client_secret)) - return false; - std::string api_key; - if (!dict->GetString(storage_keys::kApiKey, &api_key)) - return false; std::string refresh_token; - if (!dict->GetString(storage_keys::kRefreshToken, &refresh_token)) - return false; std::string device_id; - if (!dict->GetString(storage_keys::kDeviceId, &device_id)) - return false; - std::string oauth_url; - if (!dict->GetString(storage_keys::kOAuthURL, &oauth_url)) - return false; - std::string service_url; - if (!dict->GetString(storage_keys::kServiceURL, &service_url)) - return false; std::string device_robot_account; - if (!dict->GetString(storage_keys::kRobotAccount, &device_robot_account)) - return false; - std::string device_kind; - if (!dict->GetString(storage_keys::kDeviceKind, &device_kind)) - return false; - std::string name; - if (!dict->GetString(storage_keys::kName, &name)) - return false; std::string display_name; - if (!dict->GetString(storage_keys::kDisplayName, &display_name)) - return false; std::string description; - if (!dict->GetString(storage_keys::kDescription, &description)) - return false; std::string location; - if (!dict->GetString(storage_keys::kLocation, &location)) + if (!dict->GetString(storage_keys::kRefreshToken, &refresh_token) || + !dict->GetString(storage_keys::kDeviceId, &device_id) || + !dict->GetString(storage_keys::kRobotAccount, &device_robot_account) || + !dict->GetString(storage_keys::kDisplayName, &display_name) || + !dict->GetString(storage_keys::kDescription, &description) || + !dict->GetString(storage_keys::kLocation, &location)) { return false; - - // Temporarily tolerate missing modelId. Older registrations will not have a - // modelId in their state files. - // TODO(vitalybuka): Add result check back. Should be safe starting Mar 2015. - dict->GetString(storage_keys::kModelId, &model_id_); - - client_id_ = client_id; - client_secret_ = client_secret; - api_key_ = api_key; + } refresh_token_ = refresh_token; - oauth_url_ = oauth_url; - service_url_ = service_url; device_robot_account_ = device_robot_account; - device_kind_ = device_kind; - name_ = name; display_name_ = display_name; description_ = description; location_ = location; @@ -262,20 +215,12 @@ bool DeviceRegistrationInfo::Save() const { base::DictionaryValue dict; - dict.SetString(storage_keys::kClientId, client_id_); - dict.SetString(storage_keys::kClientSecret, client_secret_); - dict.SetString(storage_keys::kApiKey, api_key_); dict.SetString(storage_keys::kRefreshToken, refresh_token_); dict.SetString(storage_keys::kDeviceId, device_id_); - dict.SetString(storage_keys::kOAuthURL, oauth_url_); - dict.SetString(storage_keys::kServiceURL, service_url_); dict.SetString(storage_keys::kRobotAccount, device_robot_account_); - dict.SetString(storage_keys::kDeviceKind, device_kind_); - dict.SetString(storage_keys::kName, name_); dict.SetString(storage_keys::kDisplayName, display_name_); dict.SetString(storage_keys::kDescription, description_); dict.SetString(storage_keys::kLocation, location_); - dict.SetString(storage_keys::kModelId, model_id_); return storage_->Save(&dict); } @@ -362,8 +307,8 @@ LOG(INFO) << "Refreshing access token."; auto response = chromeos::http::PostFormDataAndBlock(GetOAuthURL("token"), { {"refresh_token", refresh_token_}, - {"client_id", client_id_}, - {"client_secret", client_secret_}, + {"client_id", config_->client_id()}, + {"client_secret", config_->client_secret()}, {"grant_type", "refresh_token"}, }, {}, transport_, error); if (!response) @@ -449,16 +394,16 @@ std::unique_ptr<base::DictionaryValue> resource{new base::DictionaryValue}; if (!device_id_.empty()) resource->SetString("id", device_id_); - resource->SetString("deviceKind", device_kind_); - resource->SetString("name", name_); + resource->SetString("deviceKind", config_->device_kind()); + resource->SetString("name", config_->name()); if (!display_name_.empty()) resource->SetString("displayName", display_name_); if (!description_.empty()) resource->SetString("description", description_); if (!location_.empty()) resource->SetString("location", location_); - if (!model_id_.empty()) - resource->SetString("modelManifestId", model_id_); + if (!config_->model_id().empty()) + resource->SetString("modelManifestId", config_->model_id()); resource->SetString("channel.supportedType", "xmpp"); resource->Set("commandDefs", commands.release()); resource->Set("state", state.release()); @@ -488,27 +433,41 @@ 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 (!GetParamValue(params, "ticket_id", &ticket_id, error) || - !GetParamValue(params, storage_keys::kClientId, &client_id_, error) || - !GetParamValue(params, storage_keys::kClientSecret, &client_secret_, - error) || - !GetParamValue(params, storage_keys::kApiKey, &api_key_, error) || - !GetParamValue(params, storage_keys::kDeviceKind, &device_kind_, error) || - !GetParamValue(params, storage_keys::kName, &name_, error) || - !GetParamValue(params, storage_keys::kDisplayName, &display_name_, - error) || - !GetParamValue(params, storage_keys::kDescription, &description_, - error) || - !GetParamValue(params, storage_keys::kLocation, &location_, error) || - !GetParamValue(params, storage_keys::kModelId, &model_id_, error) || - !GetParamValue(params, storage_keys::kOAuthURL, &oauth_url_, error) || - !GetParamValue(params, storage_keys::kServiceURL, &service_url_, error)) { + 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. + GetWithDefault(params, storage_keys::kDisplayName, + config_->default_display_name(), &display_name_); + GetWithDefault(params, storage_keys::kDescription, + config_->default_description(), &description_); + GetWithDefault(params, storage_keys::kLocation, + config_->default_location(), &location_); std::unique_ptr<base::DictionaryValue> device_draft = BuildDeviceResource(error); @@ -517,11 +476,11 @@ base::DictionaryValue req_json; req_json.SetString("id", ticket_id); - req_json.SetString("oauthClientId", client_id_); + req_json.SetString("oauthClientId", config_->client_id()); req_json.Set("deviceDraft", device_draft.release()); auto url = GetServiceURL("registrationTickets/" + ticket_id, - {{"key", api_key_}}); + {{"key", config_->api_key()}}); std::unique_ptr<chromeos::http::Response> response = chromeos::http::PatchJsonAndBlock(url, &req_json, {}, transport_, error); auto json_resp = chromeos::http::ParseJsonResponse(response.get(), nullptr, @@ -534,7 +493,7 @@ } url = GetServiceURL("registrationTickets/" + ticket_id + - "/finalize?key=" + api_key_); + "/finalize?key=" + config_->api_key()); response = chromeos::http::SendRequestWithNoDataAndBlock( chromeos::http::request_type::kPost, url, {}, transport_, error); if (!response) @@ -562,8 +521,8 @@ // Now get access_token and refresh_token response = chromeos::http::PostFormDataAndBlock(GetOAuthURL("token"), { {"code", auth_code}, - {"client_id", client_id_}, - {"client_secret", client_secret_}, + {"client_id", config_->client_id()}, + {"client_secret", config_->client_secret()}, {"redirect_uri", "oob"}, {"scope", "https://www.googleapis.com/auth/clouddevices"}, {"grant_type", "authorization_code"} @@ -971,28 +930,6 @@ base::Bind(&IgnoreCloudResult), base::Bind(&IgnoreCloudError)); } -bool DeviceRegistrationInfo::GetParamValue( - const std::map<std::string, std::string>& params, - const std::string& param_name, - std::string* param_value, - chromeos::ErrorPtr* error) { - auto p = params.find(param_name); - if (p != params.end()) { - *param_value = p->second; - return true; - } - - bool default_was_set = config_store_->GetString(param_name, param_value); - if (default_was_set) - return true; - - chromeos::Error::AddToPrintf(error, FROM_HERE, kErrorDomainBuffet, - "missing_parameter", - "Parameter %s not specified", - param_name.c_str()); - return false; -} - void DeviceRegistrationInfo::SetRegistrationStatus( RegistrationStatus new_status) { if (new_status == registration_status_)
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h index f985d42..0eec540 100644 --- a/buffet/device_registration_info.h +++ b/buffet/device_registration_info.h
@@ -19,6 +19,7 @@ #include <chromeos/errors/error.h> #include <chromeos/http/http_transport.h> +#include "buffet/buffet_config.h" #include "buffet/registration_status.h" #include "buffet/storage_interface.h" #include "buffet/xmpp/xmpp_client.h" @@ -49,7 +50,7 @@ DeviceRegistrationInfo( const std::shared_ptr<CommandManager>& command_manager, const std::shared_ptr<StateManager>& state_manager, - std::unique_ptr<chromeos::KeyValueStore> config_store, + std::unique_ptr<const BuffetConfig> config, const std::shared_ptr<chromeos::http::Transport>& transport, const std::shared_ptr<StorageInterface>& state_store, const base::Closure& on_status_changed); @@ -198,18 +199,6 @@ void PublishStateUpdates(); - // Looks up the value for parameter with name |param_name| in - // |params|, supplying a default value if one is available and - // |params| doesn't have a value for |param_name|. The value will be - // returned in |param_value|. Returns |true| if a value was set - // (either from |params| or a default), |false| otherwise and - // |error| will be set. - bool GetParamValue( - const std::map<std::string, std::string>& params, - const std::string& param_name, - std::string* param_value, - chromeos::ErrorPtr* error); - // Builds Cloud API devices collection REST resouce which matches // current state of the device including command definitions // for all supported commands and current device state. @@ -222,20 +211,15 @@ std::unique_ptr<XmppClient> xmpp_client_; base::MessageLoopForIO::FileDescriptorWatcher fd_watcher_; - std::string client_id_; - std::string client_secret_; - std::string api_key_; + // Data that is cached here, persisted in the state store. std::string refresh_token_; std::string device_id_; std::string device_robot_account_; - std::string oauth_url_; - std::string service_url_; - std::string device_kind_; - std::string name_; + + // These fields are user settable and stored in the state store. std::string display_name_; std::string description_; std::string location_; - std::string model_id_; // Transient data std::string access_token_; @@ -250,8 +234,7 @@ // Device state manager. std::shared_ptr<StateManager> state_manager_; - // Buffet configuration. - std::unique_ptr<chromeos::KeyValueStore> config_store_; + std::unique_ptr<const BuffetConfig> config_; // Tracks our current registration status. RegistrationStatus registration_status_{RegistrationStatus::kUnconfigured};
diff --git a/buffet/device_registration_info_unittest.cc b/buffet/device_registration_info_unittest.cc index 0823e77..dfb61cc 100644 --- a/buffet/device_registration_info_unittest.cc +++ b/buffet/device_registration_info_unittest.cc
@@ -59,20 +59,12 @@ // Fill in the storage with default environment information (URLs, etc). void InitDefaultStorage(base::DictionaryValue* data) { - data->SetString(storage_keys::kClientId, test_data::kClientId); - data->SetString(storage_keys::kClientSecret, test_data::kClientSecret); - data->SetString(storage_keys::kApiKey, test_data::kApiKey); data->SetString(storage_keys::kRefreshToken, ""); data->SetString(storage_keys::kDeviceId, ""); - data->SetString(storage_keys::kOAuthURL, test_data::kOAuthURL); - data->SetString(storage_keys::kServiceURL, test_data::kServiceURL); data->SetString(storage_keys::kRobotAccount, ""); - data->SetString(storage_keys::kDeviceKind, ""); - data->SetString(storage_keys::kName, ""); data->SetString(storage_keys::kDisplayName, ""); data->SetString(storage_keys::kDescription, ""); data->SetString(storage_keys::kLocation, ""); - data->SetString(storage_keys::kModelId, ""); } // Add the test device registration information. @@ -198,25 +190,26 @@ transport_ = std::make_shared<chromeos::http::fake::Transport>(); command_manager_ = std::make_shared<CommandManager>(); state_manager_ = std::make_shared<StateManager>(&mock_state_change_queue_); - std::unique_ptr<chromeos::KeyValueStore> config_store{ - new chromeos::KeyValueStore}; - config_store->SetString("client_id", test_data::kClientId); - config_store->SetString("client_secret", test_data::kClientSecret); - config_store->SetString("api_key", test_data::kApiKey); - config_store->SetString("device_kind", "vendor"); - config_store->SetString("name", "coffee_pot"); - config_store->SetString("display_name", "Coffee Pot"); - config_store->SetString("description", "Easy to clean"); - config_store->SetString("location", "Kitchen"); - config_store->SetString("model_id", "AAA"); - config_store->SetString("oauth_url", test_data::kOAuthURL); - config_store->SetString("service_url", test_data::kServiceURL); + chromeos::KeyValueStore config_store; + config_store.SetString("client_id", test_data::kClientId); + config_store.SetString("client_secret", test_data::kClientSecret); + config_store.SetString("api_key", test_data::kApiKey); + config_store.SetString("device_kind", "vendor"); + config_store.SetString("name", "coffee_pot"); + config_store.SetString("default_display_name", "Coffee Pot"); + config_store.SetString("default_description", "Easy to clean"); + config_store.SetString("default_location", "Kitchen"); + config_store.SetString("model_id", "AAA"); + config_store.SetString("oauth_url", test_data::kOAuthURL); + config_store.SetString("service_url", test_data::kServiceURL); + std::unique_ptr<BuffetConfig> config{new BuffetConfig}; + config->Load(config_store); auto mock_callback = base::Bind( &DeviceRegistrationInfoTest::OnRegistrationStatusChange, base::Unretained(this)); dev_reg_ = std::unique_ptr<DeviceRegistrationInfo>( new DeviceRegistrationInfo(command_manager_, state_manager_, - std::move(config_store), + std::move(config), transport_, storage_, mock_callback)); } @@ -253,20 +246,12 @@ TEST_F(DeviceRegistrationInfoTest, VerifySave) { base::DictionaryValue data; - data.SetString(storage_keys::kClientId, "a"); - data.SetString(storage_keys::kClientSecret, "b"); - data.SetString(storage_keys::kApiKey, "c"); data.SetString(storage_keys::kRefreshToken, "d"); data.SetString(storage_keys::kDeviceId, "e"); - data.SetString(storage_keys::kOAuthURL, "f"); - data.SetString(storage_keys::kServiceURL, "g"); data.SetString(storage_keys::kRobotAccount, "h"); - data.SetString(storage_keys::kDeviceKind, "i"); - data.SetString(storage_keys::kName, "j"); data.SetString(storage_keys::kDisplayName, "k"); data.SetString(storage_keys::kDescription, "l"); data.SetString(storage_keys::kLocation, "m"); - data.SetString(storage_keys::kModelId, "n"); storage_->Save(&data); @@ -496,22 +481,12 @@ base::DictionaryValue* dict = nullptr; EXPECT_TRUE(storage_data->GetAsDictionary(&dict)); std::string value; - EXPECT_TRUE(dict->GetString(storage_keys::kApiKey, &value)); - EXPECT_EQ(test_data::kApiKey, value); - EXPECT_TRUE(dict->GetString(storage_keys::kClientId, &value)); - EXPECT_EQ(test_data::kClientId, value); - EXPECT_TRUE(dict->GetString(storage_keys::kClientSecret, &value)); - EXPECT_EQ(test_data::kClientSecret, value); EXPECT_TRUE(dict->GetString(storage_keys::kDeviceId, &value)); EXPECT_EQ(test_data::kDeviceId, value); - EXPECT_TRUE(dict->GetString(storage_keys::kOAuthURL, &value)); - EXPECT_EQ(test_data::kOAuthURL, value); EXPECT_TRUE(dict->GetString(storage_keys::kRefreshToken, &value)); EXPECT_EQ(test_data::kRefreshToken, value); EXPECT_TRUE(dict->GetString(storage_keys::kRobotAccount, &value)); EXPECT_EQ(test_data::kRobotAccountEmail, value); - EXPECT_TRUE(dict->GetString(storage_keys::kServiceURL, &value)); - EXPECT_EQ(test_data::kServiceURL, value); } TEST_F(DeviceRegistrationInfoTest, OOBRegistrationStatus) {
diff --git a/buffet/device_registration_storage_keys.h b/buffet/device_registration_storage_keys.h index 40a88f9..73ddec1 100644 --- a/buffet/device_registration_storage_keys.h +++ b/buffet/device_registration_storage_keys.h
@@ -11,22 +11,12 @@ namespace buffet { namespace storage_keys { -// Persistent keys -extern const char kClientId[]; -extern const char kClientSecret[]; -extern const char kApiKey[]; extern const char kRefreshToken[]; extern const char kDeviceId[]; -extern const char kOAuthURL[]; -extern const char kServiceURL[]; extern const char kRobotAccount[]; -// Transient keys -extern const char kDeviceKind[]; -extern const char kName[]; extern const char kDisplayName[]; extern const char kDescription[]; extern const char kLocation[]; -extern const char kModelId[]; } // namespace storage_keys } // namespace buffet
diff --git a/buffet/etc/buffet/buffet.conf b/buffet/etc/buffet/buffet.conf deleted file mode 100644 index a5d9b5e..0000000 --- a/buffet/etc/buffet/buffet.conf +++ /dev/null
@@ -1,13 +0,0 @@ -client_id=58855907228.apps.googleusercontent.com -client_secret=eHSAREAHrIqPsHBxCE9zPPBi -api_key=AIzaSyDSq46gG-AxUnC3zoqD9COIPrjolFsMfMA - -oauth_url=https://accounts.google.com/o/oauth2/ -service_url=https://www.googleapis.com/clouddevices/v1/ - -device_kind=vendor -name=coffee_pot -display_name=Coffee Pot -description=Easy to clean -location=Kitchen -model_id=AAA
diff --git a/buffet/main.cc b/buffet/main.cc index 6893723..58d70d3 100644 --- a/buffet/main.cc +++ b/buffet/main.cc
@@ -42,6 +42,7 @@ } private: + BuffetConfig config_; std::unique_ptr<buffet::Manager> manager_; const base::FilePath config_path_; const base::FilePath state_path_;
diff --git a/buffet/manager.cc b/buffet/manager.cc index f7bef10..6097b09 100644 --- a/buffet/manager.cc +++ b/buffet/manager.cc
@@ -59,17 +59,16 @@ new StateChangeQueue(kMaxStateChangeQueueSize)); state_manager_ = std::make_shared<StateManager>(state_change_queue_.get()); state_manager_->Startup(); - std::unique_ptr<chromeos::KeyValueStore> config_store{ - new chromeos::KeyValueStore}; + std::unique_ptr<BuffetConfig> config{new BuffetConfig}; + config->Load(config_path); std::unique_ptr<FileStorage> state_store{new FileStorage{state_path}}; - config_store->Load(config_path); // TODO(avakulenko): Figure out security implications of storing // device info state data unencrypted. device_info_ = std::unique_ptr<DeviceRegistrationInfo>( new DeviceRegistrationInfo( command_manager_, state_manager_, - std::move(config_store), + std::move(config), chromeos::http::Transport::CreateDefault(), std::move(state_store), base::Bind(&Manager::OnRegistrationStatusChanged,