This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
policy.go
52 lines (43 loc) · 1.48 KB
/
policy.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
package conjurapi
import (
"io"
"github.com/infamousjoeg/authn-jwt-gitlab/internal/conjurapi/response"
)
// PolicyMode defines the server-sized behavior when loading a policy.
type PolicyMode uint
const (
// PolicyModePost appends new data to the policy.
PolicyModePost PolicyMode = 1
// PolicyModePut completely replaces the policy, implicitly deleting data which is not present in the new policy.
PolicyModePut PolicyMode = 2
// PolicyModePatch adds policy data and explicitly deletes policy data.
PolicyModePatch PolicyMode = 3
)
// CreatedRole contains the full role ID and API key of a role which was created
// by the server when loading a policy.
type CreatedRole struct {
ID string `json:"id"`
APIKey string `json:"api_key"`
}
// PolicyResponse contains information about the policy update.
type PolicyResponse struct {
// Newly created roles.
CreatedRoles map[string]CreatedRole `json:"created_roles"`
// The version number of the policy.
Version uint32 `json:"version"`
}
// LoadPolicy submits new policy data or polciy changes to the server.
//
// The required permission depends on the mode.
func (c *Client) LoadPolicy(mode PolicyMode, policyID string, policy io.Reader) (*PolicyResponse, error) {
req, err := c.LoadPolicyRequest(mode, policyID, policy)
if err != nil {
return nil, err
}
resp, err := c.SubmitRequest(req)
if err != nil {
return nil, err
}
policyResponse := PolicyResponse{}
return &policyResponse, response.JSONResponse(resp, &policyResponse)
}