cmd/upspin-ui: update snapshot user on specifying endpoints

Through upspin-ui, users sign up with no endpoints provided to the key
server. Once they specify them, upspin-ui updates the record in the key
server. This change also does this for +snapshot users, which are
created automatically by the keyserver on signup.

Fix upspin/upspin#540

Change-Id: I0cd962e0a6a67260bf3bdf4af9de7a2b6c3fbecc
Reviewed-on: https://upspin-review.googlesource.com/17640
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/cmd/upspin-ui/startup.go b/cmd/upspin-ui/startup.go
index 9a3814f..57c6148 100644
--- a/cmd/upspin-ui/startup.go
+++ b/cmd/upspin-ui/startup.go
@@ -273,6 +273,11 @@
 			return nil, nil, err
 		}
 
+		// Put the updated snapshot user config to the key server.
+		if err := putSnapshotUser(cfg); err != nil {
+			return nil, nil, errors.Errorf("error updating key server for snapshot user:\n%v", err)
+		}
+
 	case "specifyNoEndpoints":
 		cfg = config.SetDirEndpoint(cfg, noneEndpoint)
 		cfg = config.SetStoreEndpoint(cfg, noneEndpoint)
@@ -414,6 +419,9 @@
 		if err := putUser(cfg, nil); err != nil {
 			return nil, nil, err
 		}
+		if err := putSnapshotUser(cfg); err != nil {
+			return nil, nil, err
+		}
 
 		// Update the server user config and key server record.
 		serverCfg, serverCfgFile, err := serverConfig(st.Server.UserName)
@@ -776,6 +784,16 @@
 	return key.Put(&newU)
 }
 
+// putSnapshotUser updates the key server record for the given user's snapshot user.
+func putSnapshotUser(cfg upspin.Config) error {
+	user, _, domain, err := user.Parse(cfg.UserName())
+	if err != nil {
+		return err
+	}
+	snapCfg := config.SetUserName(cfg, upspin.UserName(user+"+snapshot@"+domain))
+	return putUser(cfg, snapCfg)
+}
+
 // serviceHostName registers an upspin.services host name with host@upspin.io
 // for the given config's user and configures it to resolve to the given IP
 // address.