buffet: Add D-Bus API to change GCD service settings

Added function UpdateServiceConfig that can be used to switch servers
for testing. Function modifies client_id, client_secret, api_key,
oauth_url and service_url.

BUG=brillo:1058
TEST='FEATURES=test emerge-gizmo buffet'

Change-Id: Ia8f8ba3ad57372ecedbff2819ce1991ba391a41d
Reviewed-on: https://chromium-review.googlesource.com/271387
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 3b176c3..7d8c608 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -716,6 +716,7 @@
   }
   change.set_description(description);
   change.set_location(location);
+  change.Commit();
 
   if (HaveRegistrationCredentials(nullptr)) {
     UpdateDeviceResource(base::Bind(&base::DoNothing),
@@ -725,6 +726,28 @@
   return true;
 }
 
+bool DeviceRegistrationInfo::UpdateServiceConfig(
+    const std::string& client_id,
+    const std::string& client_secret,
+    const std::string& api_key,
+    const std::string& oauth_url,
+    const std::string& service_url,
+    chromeos::ErrorPtr* error) {
+  if (HaveRegistrationCredentials(nullptr)) {
+    chromeos::Error::AddTo(error, FROM_HERE, kErrorDomainBuffet,
+                           "already_registered",
+                           "Unable to change config for registered device");
+    return false;
+  }
+  BuffetConfig::Transaction change{config_.get()};
+  change.set_client_id(client_id);
+  change.set_client_secret(client_secret);
+  change.set_api_key(api_key);
+  change.set_oauth_url(oauth_url);
+  change.set_service_url(service_url);
+  return true;
+}
+
 void DeviceRegistrationInfo::UpdateCommand(
     const std::string& command_id,
     const base::DictionaryValue& command_patch,