Browse code

Validate/sanitize swarmkit spec name.

Signed-off-by: Anshul Pundir <anshul.pundir@docker.com>

Anshul Pundir authored on 2017/12/07 04:29:58
Showing 1 changed files
... ...
@@ -228,6 +228,13 @@ func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlag
228 228
 			return err
229 229
 		}
230 230
 
231
+		// Validate spec name.
232
+		if spec.Annotations.Name == "" {
233
+			spec.Annotations.Name = "default"
234
+		} else if spec.Annotations.Name != "default" {
235
+			return validationError{errors.New(`swarm spec must be named "default"`)}
236
+		}
237
+
231 238
 		// In update, client should provide the complete spec of the swarm, including
232 239
 		// Name and Labels. If a field is specified with 0 or nil, then the default value
233 240
 		// will be used to swarmkit.