buffet: Update configuration reading for new fields moved from privetd
Removed default_ prefix from default_name and default_description.
Added fields location, model_id, oem_name, model_name.
BUG=brillo:377,brillo:342
TEST=FEATURE=test emerge-gizmo buffet
CQ-DEPEND=CL:266085
Change-Id: I133ac5e41db0d7a7fc67fa0d9773dd1179a90032
Reviewed-on: https://chromium-review.googlesource.com/266028
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/buffet_config.cc b/buffet/buffet_config.cc
index 1ed7842..d8e0324 100644
--- a/buffet/buffet_config.cc
+++ b/buffet/buffet_config.cc
@@ -7,19 +7,56 @@
#include <base/logging.h>
#include <base/strings/string_number_conversions.h>
+namespace {
+
+// TODO(vitalybuka): Remove this when deviceKind is gone from server.
+std::string GetDeviceKind(const std::string& manifest_id) {
+ CHECK_EQ(5u, manifest_id.size());
+ std::string kind = manifest_id.substr(0, 2);
+ if (kind == "AC")
+ return "accessPoint";
+ if (kind == "AK")
+ return "aggregator";
+ if (kind == "AM")
+ return "camera";
+ if (kind == "AB")
+ return "developmentBoard";
+ if (kind == "AE")
+ return "printer";
+ if (kind == "AF")
+ return "scanner";
+ if (kind == "AD")
+ return "speaker";
+ if (kind == "AL")
+ return "storage";
+ if (kind == "AJ")
+ return "toy";
+ if (kind == "AA")
+ return "vendor";
+ if (kind == "AN")
+ return "video";
+ LOG(FATAL) << "Invalid model id: " << manifest_id;
+ return std::string();
+}
+
+} // namespace
+
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 kDefaultDescription[] = "default_description";
-const char kDefaultLocation[] = "default_location";
-const char kModelId[] = "model_id";
+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 kName[] = "name";
+const char kDescription[] = "description";
+const char kLocation[] = "location";
+const char kOemName[] = "oem_name";
+const char kModelName[] = "model_name";
+const char kModelId[] = "model_id";
+
const char kPollingPeriodMs[] = "polling_period_ms";
} // namespace config_keys
@@ -33,22 +70,43 @@
void BuffetConfig::Load(const chromeos::KeyValueStore& store) {
store.GetString(config_keys::kClientId, &client_id_);
+ CHECK(!client_id_.empty());
+
store.GetString(config_keys::kClientSecret, &client_secret_);
+ CHECK(!client_secret_.empty());
+
store.GetString(config_keys::kApiKey, &api_key_);
+ CHECK(!api_key_.empty());
+
store.GetString(config_keys::kOAuthURL, &oauth_url_);
+ CHECK(!oauth_url_.empty());
+
store.GetString(config_keys::kServiceURL, &service_url_);
- store.GetString(config_keys::kDeviceKind, &device_kind_);
- store.GetString(config_keys::kName, &name_);
- store.GetString(config_keys::kDefaultDescription, &default_description_);
- store.GetString(config_keys::kDefaultLocation, &default_location_);
+ CHECK(!service_url_.empty());
+
+ store.GetString(config_keys::kOemName, &oem_name_);
+ CHECK(!oem_name_.empty());
+
+ store.GetString(config_keys::kModelName, &model_name_);
+ CHECK(!model_name_.empty());
+
store.GetString(config_keys::kModelId, &model_id_);
+ device_kind_ = GetDeviceKind(model_id_);
+
std::string polling_period_str;
- if (store.GetString(config_keys::kPollingPeriodMs, &polling_period_str)) {
- CHECK(base::StringToUint64(polling_period_str, &polling_period_ms_))
- << "Failed to parse polling period in configuration file.";
- VLOG(1) << "Using a polling period of " << polling_period_ms_
- << " milliseconds.";
- }
+ if (store.GetString(config_keys::kPollingPeriodMs, &polling_period_str))
+ CHECK(base::StringToUint64(polling_period_str, &polling_period_ms_));
+
+ store.GetString(config_keys::kName, &name_);
+ CHECK(!name_.empty());
+
+ store.GetString(config_keys::kDescription, &description_);
+ store.GetString(config_keys::kLocation, &location_);
+}
+
+void BuffetConfig::set_name(const std::string& name) {
+ CHECK(!name.empty());
+ name_ = name;
}
} // namespace buffet