-
Notifications
You must be signed in to change notification settings - Fork 32
/
claimtree.go
63 lines (52 loc) · 1.62 KB
/
claimtree.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package registry
import (
"context"
"log"
"net/url"
"github.com/arigatomachine/cli/envelope"
"github.com/arigatomachine/cli/identity"
)
// ClaimTreeClient represents the `/claimtree` registry endpoint, used for
// retrieving the public keys and their associated claims for an organization.
type ClaimTreeClient struct {
client *Client
}
// ClaimTree represents an organizations claim tree which contains public
// signing and encryption keys for every member.
type ClaimTree struct {
Org *envelope.Unsigned `json:"org"`
PublicKeys []PublicKeySegment `json:"public_keys"`
}
// PublicKeySegment represents a sub section of a claimtree targeting a
// specific public key and it's claims.
type PublicKeySegment struct {
Key *envelope.Signed `json:"public_key"`
Claims []envelope.Signed `json:"claims"`
}
// List returns a list of all claimtrees for a given orgID. If no orgID is
// provided then it returns all claimtrees for every organization the user
// belongs too.
//
// If an ownerID is provided then only public keys and claims related to that
// user or machine will be returned.
func (c *ClaimTreeClient) List(ctx context.Context, orgID *identity.ID,
ownerID *identity.ID) ([]ClaimTree, error) {
query := &url.Values{}
if orgID != nil {
query.Set("org_id", orgID.String())
}
if ownerID != nil {
query.Set("owner_id", ownerID.String())
}
req, err := c.client.NewRequest("GET", "/claimtree", query, nil)
if err != nil {
log.Printf("Error building http request: %s", err)
return nil, err
}
resp := []ClaimTree{}
_, err = c.client.Do(ctx, req, &resp)
if err != nil {
return nil, err
}
return resp, nil
}