MCPcopy Index your code
hub / github.com/coder/coder / convertToUserIDs

Function convertToUserIDs

enterprise/cli/groupedit.go:128–150  ·  view source on GitHub ↗

convertToUserIDs accepts a list of users in the form of IDs or email addresses and translates any emails to the matching user ID.

(userList []string, users []codersdk.User)

Source from the content-addressed store, hash-verified

126// convertToUserIDs accepts a list of users in the form of IDs or email addresses
127// and translates any emails to the matching user ID.
128func convertToUserIDs(userList []string, users []codersdk.User) ([]string, error) {
129 converted := make([]string, 0, len(userList))
130
131 for _, user := range userList {
132 if _, err := uuid.Parse(user); err == nil {
133 converted = append(converted, user)
134 continue
135 }
136 if _, err := mail.ParseAddress(user); err == nil {
137 for _, u := range users {
138 if u.Email == user {
139 converted = append(converted, u.ID.String())
140 break
141 }
142 }
143 continue
144 }
145
146 return nil, xerrors.Errorf("%q must be a valid UUID or email address", user)
147 }
148
149 return converted, nil
150}

Callers 1

groupEditMethod · 0.85

Calls 3

ParseMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected