Skip to content

Commit

Permalink
Merge pull request #431 from juju/v12
Browse files Browse the repository at this point in the history
Merge v12 to v13
  • Loading branch information
hpidcock authored May 24, 2024
2 parents 8920fe1 + 064bbf9 commit 8512f21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}

Expand Down
8 changes: 6 additions & 2 deletions meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8512f21

Please sign in to comment.