-
Notifications
You must be signed in to change notification settings - Fork 32
/
memberships.go
48 lines (40 loc) · 1.15 KB
/
memberships.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package registry
import (
"context"
"log"
"net/url"
"github.com/manifoldco/torus-cli/envelope"
"github.com/manifoldco/torus-cli/identity"
)
// MembershipsClient represents the `/memberships` registry
// endpoint, used for accessing the relationship between users,
// organization, and teams.
type MembershipsClient struct {
client *Client
}
// List returns all memberships for a given organization, team, or user/machine
func (m *MembershipsClient) List(ctx context.Context, orgID *identity.ID,
teamID *identity.ID, ownerID *identity.ID) ([]envelope.Unsigned, error) {
query := &url.Values{}
if orgID != nil {
query.Set("org_id", orgID.String())
}
if teamID != nil {
query.Set("team_id", teamID.String())
}
if ownerID != nil {
query.Set("owner_id", ownerID.String())
}
req, err := m.client.NewRequest("GET", "/memberships", query, nil)
if err != nil {
log.Printf("could not build GET /memberships request: %s", err)
return nil, err
}
memberships := []envelope.Unsigned{}
_, err = m.client.Do(ctx, req, &memberships)
if err != nil {
log.Printf("could not perform GET /memberships: %s", err)
return nil, err
}
return memberships, nil
}