-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.go
95 lines (77 loc) · 2.38 KB
/
permissions.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gosatellite
import (
"context"
"fmt"
"net/http"
)
const permissionsPath = basePath + "/permissions"
// Permission defines the model of a single permission
type Permission struct {
ID *int `json:"id"`
Name *string `json:"name"`
ResourceType *string `json:"resource_type"`
}
// PermissionsList defines model for a list of permissions.
type PermissionsList struct {
searchResults
Results *[]Permission `json:"results"`
}
// PermissionsListOptions specifies the optional parameters to various List methods that
// support pagination.
type PermissionsListOptions struct {
ListOptions
// Scope by locations
LocationID int `url:"location_id,omitempty"`
// Scope by organizations
OrganizationID int `url:"organization_id,omitempty"`
}
// ResourceTypes defines model for a list of resource types.
type ResourceTypes struct {
searchResults
Results *[]struct {
Name *string `json:"name"`
} `json:"results"`
}
// Permissions is an interface for interacting with
// Red Hat Satellite permissions
type Permissions interface {
Get(ctx context.Context, permissionID int) (*Permission, *http.Response, error)
List(ctx context.Context, opt PermissionsListOptions) (*PermissionsList, *http.Response, error)
}
// PermissionsOp handles communication with the Permissions related methods of the
// Red Hat Satellite REST API
type PermissionsOp struct {
client *Client
}
// Get a single permission by its ID
func (s *PermissionsOp) Get(ctx context.Context, permissionID int) (*Permission, *http.Response, error) {
path := fmt.Sprintf("%s/%d", permissionsPath, permissionID)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
permission := new(Permission)
resp, err := s.client.Do(ctx, req, permission)
if err != nil {
return nil, resp, err
}
return permission, resp, err
}
// List all permissions or a filtered list of permissions
func (s *PermissionsOp) List(ctx context.Context, opt PermissionsListOptions) (*PermissionsList, *http.Response, error) {
path := permissionsPath
path, err := addOptions(path, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
permissions := new(PermissionsList)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}
return permissions, resp, err
}