Skip to content

Commit

Permalink
Fix logging output of user.GID (#1466)
Browse files Browse the repository at this point in the history
Follow up to comment here:
#1449 (comment)

cc @pnasrat

Signed-off-by: Josh Dolitsky <[email protected]>
  • Loading branch information
jdolitsky authored Jan 7, 2025
1 parent 1ef4f50 commit d418457
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/build/types/image_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (ic *ImageConfiguration) Summarize(ctx context.Context) {
log.Infof(" runas: %s", ic.Accounts.RunAs)
log.Infof(" users:")
for _, u := range ic.Accounts.Users {
log.Infof(" - uid=%d(%s) gid=%d", u.UID, u.UserName, u.GID)
log.Infof(" - uid=%d(%s) gid=%d", u.UID, u.UserName, gidToInt(u.GID))
}
log.Infof(" groups:")
for _, g := range ic.Accounts.Groups {
Expand All @@ -272,3 +272,10 @@ func (ic *ImageConfiguration) Summarize(ctx context.Context) {
}
}
}

func gidToInt(gid GID) uint32 {
if gid == nil {
return 0
}
return *gid
}
3 changes: 3 additions & 0 deletions pkg/build/types/image_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func TestUserContents(t *testing.T) {

require.Equal(t, "/not/home", ic.Accounts.Users[0].HomeDir)
require.Equal(t, "/home/user", ic.Accounts.Users[1].HomeDir)

// Ensure this does not cause panic when users[1].gid is empty (defaulting to 0)
ic.Summarize(ctx)
}

func TestMergeInto(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/build/types/testdata/users.apko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ accounts:
uid: 2
homedir: "/not/home"
username: "something-else"
- gid: 2
uid: 3
- uid: 3
username: "user"

0 comments on commit d418457

Please sign in to comment.