MCPcopy
hub / github.com/containerd/containerd / GenerateUserString

Function GenerateUserString

internal/cri/util/util.go:129–150  ·  view source on GitHub ↗

GenerateUserString generates valid user string based on OCI Image Spec v1.0.0. CRI defines that the following combinations are valid: (none) -> "" username -> username username, uid -> username username, uid, gid -> username:gid username, gid -> username:gid uid -> uid uid, gid -> uid:gid gid -> e

(username string, uid, gid *runtime.Int64Value)

Source from the content-addressed store, hash-verified

127//
128// TODO(random-liu): Add group name support in CRI.
129func GenerateUserString(username string, uid, gid *runtime.Int64Value) (string, error) {
130 var userstr, groupstr string
131 if uid != nil {
132 userstr = strconv.FormatInt(uid.GetValue(), 10)
133 }
134 if username != "" {
135 userstr = username
136 }
137 if gid != nil {
138 groupstr = strconv.FormatInt(gid.GetValue(), 10)
139 }
140 if userstr == "" {
141 if groupstr != "" {
142 return "", fmt.Errorf("user group %q is specified without user", groupstr)
143 }
144 return "", nil
145 }
146 if groupstr != "" {
147 userstr = userstr + ":" + groupstr
148 }
149 return userstr, nil
150}
151
152// IsShimTTRPCClosed returns true if the cause of error is ttrpc.ErrClosed from shim.
153func IsShimTTRPCClosed(err error) bool {

Callers 2

platformSpecOptsMethod · 0.92
TestGenerateUserStringFunction · 0.85

Calls 1

GetValueMethod · 0.80

Tested by 1

TestGenerateUserStringFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…