| 73 | } |
| 74 | |
| 75 | func collaboratorUserIDs(ctx context.Context, c *scalingo.Client, app string, usernames []string) ([]string, error) { |
| 76 | ids := make([]string, 0, len(usernames)) |
| 77 | |
| 78 | collaborators, err := c.CollaboratorsList(ctx, app) |
| 79 | if err != nil { |
| 80 | return nil, errors.Wrapf(ctx, err, "fail to list collaborators") |
| 81 | } |
| 82 | |
| 83 | scapp, err := c.AppsShow(ctx, app) |
| 84 | if err != nil { |
| 85 | return nil, errors.Wrapf(ctx, err, "fail to get application information") |
| 86 | } |
| 87 | |
| 88 | var id string |
| 89 | for _, u := range usernames { |
| 90 | id = "" |
| 91 | if u == scapp.Owner.Username { |
| 92 | id = scapp.Owner.ID |
| 93 | } else { |
| 94 | for _, c := range collaborators { |
| 95 | if c.Username == u && c.Status == "pending" { |
| 96 | return nil, errors.Newf(ctx, "%v is a collaborator but their invitation is still pending", c.Username) |
| 97 | } else if c.Username == u { |
| 98 | id = c.UserID |
| 99 | break |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | if id == "" { |
| 104 | return nil, errors.Newf(ctx, "no such collaborator: %v", u) |
| 105 | } |
| 106 | |
| 107 | ids = append(ids, id) |
| 108 | } |
| 109 | |
| 110 | return ids, nil |
| 111 | } |