diff --git a/meta.go b/meta.go index 0b7e8f0..42badbd 100644 --- a/meta.go +++ b/meta.go @@ -297,8 +297,8 @@ type Meta struct { type Container struct { Resource string `bson:"resource,omitempty" json:"resource,omitempty" yaml:"resource,omitempty"` Mounts []Mount `bson:"mounts,omitempty" json:"mounts,omitempty" yaml:"mounts,omitempty"` - Uid int `bson:"uid,omitempty" json:"uid,omitempty" yaml:"uid,omitempty"` - Gid int `bson:"gid,omitempty" json:"gid,omitempty" yaml:"gid,omitempty"` + Uid *int `bson:"uid,omitempty" json:"uid,omitempty" yaml:"uid,omitempty"` + Gid *int `bson:"gid,omitempty" json:"gid,omitempty" yaml:"gid,omitempty"` } // Mount allows a container to mount a storage filesystem from the storage top-level directive. @@ -1185,17 +1185,19 @@ func parseContainers(input interface{}, resources map[string]resource.Meta, stor } if value, ok := containerMap["uid"]; ok { - container.Uid = int(value.(int64)) - if container.Uid >= 1000 && container.Uid < 10000 { + uid := int(value.(int64)) + container.Uid = &uid + if uid >= 1000 && uid < 10000 { return nil, errors.Errorf("container %q has invalid uid %d: uid cannot be in reserved range 1000-9999", - name, container.Uid) + name, uid) } } if value, ok := containerMap["gid"]; ok { - container.Gid = int(value.(int64)) - if container.Gid >= 1000 && container.Gid < 10000 { + gid := int(value.(int64)) + container.Gid = &gid + if gid >= 1000 && gid < 10000 { return nil, errors.Errorf("container %q has invalid gid %d: gid cannot be in reserved range 1000-9999", - name, container.Gid) + name, gid) } } diff --git a/meta_test.go b/meta_test.go index c68d2ea..db9f6c1 100644 --- a/meta_test.go +++ b/meta_test.go @@ -1748,12 +1748,16 @@ storage: Storage: "a", Location: "/b/", }}, - Uid: 10, - Gid: 10, + Uid: intPtr(10), + Gid: intPtr(10), }, }) } +func intPtr(i int) *int { + return &i +} + func (s *MetaSuite) TestInvalidUid(c *gc.C) { _, err := charm.ReadMeta(strings.NewReader(` name: a