extractEmailFromUserIdentifier extracts email from user identifier. Supported formats: users/{email}, serviceAccounts/{email}, workloadIdentities/{email}
(identifier string)
| 210 | // extractEmailFromUserIdentifier extracts email from user identifier. |
| 211 | // Supported formats: users/{email}, serviceAccounts/{email}, workloadIdentities/{email} |
| 212 | func extractEmailFromUserIdentifier(identifier string) (string, error) { |
| 213 | if strings.HasPrefix(identifier, common.UserNamePrefix) { |
| 214 | email := strings.TrimPrefix(identifier, common.UserNamePrefix) |
| 215 | if email == "" { |
| 216 | return "", errors.New("invalid empty user identifier") |
| 217 | } |
| 218 | return email, nil |
| 219 | } |
| 220 | if strings.HasPrefix(identifier, common.ServiceAccountNamePrefix) { |
| 221 | email := strings.TrimPrefix(identifier, common.ServiceAccountNamePrefix) |
| 222 | if email == "" { |
| 223 | return "", errors.New("invalid empty service account identifier") |
| 224 | } |
| 225 | return email, nil |
| 226 | } |
| 227 | if strings.HasPrefix(identifier, common.WorkloadIdentityNamePrefix) { |
| 228 | email := strings.TrimPrefix(identifier, common.WorkloadIdentityNamePrefix) |
| 229 | if email == "" { |
| 230 | return "", errors.New("invalid empty workload identity identifier") |
| 231 | } |
| 232 | return email, nil |
| 233 | } |
| 234 | return "", errors.Errorf("invalid user identifier format: %s", identifier) |
| 235 | } |
| 236 | |
| 237 | // formatMemberNameByType returns the appropriate member name format based on user type. |
| 238 | // For regular users: users/{email} |
no test coverage detected