-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorgs.go
More file actions
55 lines (46 loc) · 2.18 KB
/
Copy pathorgs.go
File metadata and controls
55 lines (46 loc) · 2.18 KB
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
package cinc
import "context"
// Org is the top-level Chef Server organization. These endpoints live at
// /organizations (not under any one org) and are typically reserved for the
// pivotal superuser identity.
type Org struct {
Name string `json:"name,omitempty"`
FullName string `json:"full_name,omitempty"`
GUID string `json:"guid,omitempty"`
}
// OrgCreateResult is the response from POST /organizations. The PrivateKey
// is the generated validator client's RSA key and is returned **only** at
// creation time — store it before the response is dropped.
type OrgCreateResult struct {
URI string `json:"uri,omitempty"`
ClientName string `json:"clientname,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
}
// OrgsService accesses the top-level /organizations endpoints.
type OrgsService struct{ client *Client }
// List returns the name -> URL index of every organization.
func (s *OrgsService) List(ctx context.Context) (map[string]string, *Response, error) {
return do[map[string]string](ctx, s.client, "GET", "/organizations", nil)
}
// Get retrieves one organization's metadata.
func (s *OrgsService) Get(ctx context.Context, name string) (*Org, *Response, error) {
o, resp, err := do[Org](ctx, s.client, "GET", "/organizations/"+name, nil)
return ptrOrNil(o, err), resp, err
}
// Create creates a new organization. The response contains the generated
// validator client name and its private key — capture the key, it is not
// retrievable later.
func (s *OrgsService) Create(ctx context.Context, o *Org) (*OrgCreateResult, *Response, error) {
r, resp, err := do[OrgCreateResult](ctx, s.client, "POST", "/organizations", o)
return ptrOrNil(r, err), resp, err
}
// Update replaces an organization's metadata (typically FullName).
func (s *OrgsService) Update(ctx context.Context, o *Org) (*Org, *Response, error) {
updated, resp, err := do[Org](ctx, s.client, "PUT", "/organizations/"+o.Name, o)
return ptrOrNil(updated, err), resp, err
}
// Delete removes an organization.
func (s *OrgsService) Delete(ctx context.Context, name string) (*Response, error) {
_, resp, err := do[map[string]any](ctx, s.client, "DELETE", "/organizations/"+name, nil)
return resp, err
}