-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroles.go
More file actions
63 lines (52 loc) · 2.33 KB
/
Copy pathroles.go
File metadata and controls
63 lines (52 loc) · 2.33 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
56
57
58
59
60
61
62
63
package cinc
import "context"
// Role is a Chef role object.
type Role struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
RunList []string `json:"run_list"`
DefaultAttributes Attributes `json:"default_attributes,omitempty"`
OverrideAttributes Attributes `json:"override_attributes,omitempty"`
EnvRunLists map[string][]string `json:"env_run_lists,omitempty"`
}
// RolesService accesses the /roles endpoints.
type RolesService struct{ client *Client }
func (s *RolesService) res() crud[Role] {
return crud[Role]{client: s.client, path: "/roles"}
}
// Get retrieves a role by name.
func (s *RolesService) Get(ctx context.Context, name string) (*Role, *Response, error) {
r, resp, err := s.res().get(ctx, name)
return ptrOrNil(r, err), resp, err
}
// Create creates a new role.
func (s *RolesService) Create(ctx context.Context, r *Role) (*Role, *Response, error) {
created, resp, err := s.res().create(ctx, r.Name, r)
return ptrOrNil(created, err), resp, err
}
// Update replaces an existing role.
func (s *RolesService) Update(ctx context.Context, r *Role) (*Role, *Response, error) {
updated, resp, err := s.res().update(ctx, r.Name, r)
return ptrOrNil(updated, err), resp, err
}
// Delete removes a role by name.
func (s *RolesService) Delete(ctx context.Context, name string) (*Response, error) {
return s.res().remove(ctx, name)
}
// List returns the role name->URL index.
func (s *RolesService) List(ctx context.Context) (map[string]string, *Response, error) {
return s.res().list(ctx)
}
// Environments lists the environments for which the role has an
// environment-specific run list (always including "_default").
func (s *RolesService) Environments(ctx context.Context, role string) ([]string, *Response, error) {
return do[[]string](ctx, s.client, "GET",
s.client.orgPath("/roles/"+role+"/environments"), nil)
}
// EnvironmentRunList returns the role's run list for one environment
// (env_run_lists[env], or the default run_list when env is "_default").
func (s *RolesService) EnvironmentRunList(ctx context.Context, role, env string) ([]string, *Response, error) {
rl, resp, err := do[runListBody](ctx, s.client, "GET",
s.client.orgPath("/roles/"+role+"/environments/"+env), nil)
return rl.RunList, resp, err
}