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)
| 127 | // |
| 128 | // TODO(random-liu): Add group name support in CRI. |
| 129 | func 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. |
| 153 | func IsShimTTRPCClosed(err error) bool { |
searching dependent graphs…