buffet: Send modelManifestId with device registration modelManifestId is ID of manifest with useful information that can be used by device clients. modelManifestId is the same value as modelId from /privet/info. CQ-DEPEND=CL:251381 BUG=brillo:295 TEST=unittests Change-Id: Ic847c30badd9aa8b97f3deb7939813cc95195f02 Reviewed-on: https://chromium-review.googlesource.com/251141 Reviewed-by: Christopher Wiley <wiley@chromium.org> Tested-by: Vitaly Buka <vitalybuka@chromium.org> Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc index 01ff4fc..5851f04 100644 --- a/buffet/device_registration_info.cc +++ b/buffet/device_registration_info.cc
@@ -50,6 +50,8 @@ const char kDisplayName[] = "display_name"; const char kDescription[] = "description"; const char kLocation[] = "location"; +const char kModelId[] = "model_id"; + } // namespace storage_keys } // namespace buffet @@ -230,6 +232,11 @@ if (!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; @@ -243,6 +250,7 @@ display_name_ = display_name; description_ = description; location_ = location; + return true; } @@ -261,6 +269,7 @@ 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); } @@ -387,6 +396,8 @@ resource->SetString("description", description_); if (!location_.empty()) resource->SetString("location", location_); + if (!model_id_.empty()) + resource->SetString("modelManifestId", model_id_); resource->SetString("channel.supportedType", "xmpp"); resource->Set("commandDefs", commands.release()); resource->Set("state", state.release()); @@ -425,17 +436,18 @@ !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::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)) + !GetParamValue(params, storage_keys::kServiceURL, &service_url_, error)) { return std::string(); + } std::unique_ptr<base::DictionaryValue> device_draft = BuildDeviceResource(error);
diff --git a/buffet/device_registration_info.h b/buffet/device_registration_info.h index 7046718..780aeb3 100644 --- a/buffet/device_registration_info.h +++ b/buffet/device_registration_info.h
@@ -211,6 +211,7 @@ std::string display_name_; std::string description_; std::string location_; + std::string model_id_; // Transient data std::string access_token_;
diff --git a/buffet/device_registration_info_unittest.cc b/buffet/device_registration_info_unittest.cc index 2b274e0..ee49b0a 100644 --- a/buffet/device_registration_info_unittest.cc +++ b/buffet/device_registration_info_unittest.cc
@@ -72,6 +72,7 @@ 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. @@ -185,6 +186,7 @@ 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); dev_reg_ = std::unique_ptr<DeviceRegistrationInfo>( @@ -236,6 +238,7 @@ 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); @@ -342,6 +345,8 @@ EXPECT_EQ("Easy to clean", value); EXPECT_TRUE(json->GetString("deviceDraft.location", &value)); EXPECT_EQ("Kitchen", value); + EXPECT_TRUE(json->GetString("deviceDraft.modelManifestId", &value)); + EXPECT_EQ("AAA", value); EXPECT_TRUE(json->GetString("deviceDraft.displayName", &value)); EXPECT_EQ("Coffee Pot", value); base::DictionaryValue* commandDefs = nullptr;
diff --git a/buffet/device_registration_storage_keys.h b/buffet/device_registration_storage_keys.h index d7946bc..40a88f9 100644 --- a/buffet/device_registration_storage_keys.h +++ b/buffet/device_registration_storage_keys.h
@@ -26,6 +26,7 @@ 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 index a9b3d31..a5d9b5e 100644 --- a/buffet/etc/buffet/buffet.conf +++ b/buffet/etc/buffet/buffet.conf
@@ -10,3 +10,4 @@ display_name=Coffee Pot description=Easy to clean location=Kitchen +model_id=AAA