2017-09-19 14:47:10 +00:00
|
|
|
package api
|
|
|
|
|
2022-08-05 15:05:47 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
// SentinelPolicies is used to query the Sentinel Policy endpoints.
|
|
|
|
type SentinelPolicies struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// SentinelPolicies returns a new handle on the Sentinel policies.
|
|
|
|
func (c *Client) SentinelPolicies() *SentinelPolicies {
|
|
|
|
return &SentinelPolicies{client: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List is used to dump all of the policies.
|
|
|
|
func (a *SentinelPolicies) List(q *QueryOptions) ([]*SentinelPolicyListStub, *QueryMeta, error) {
|
|
|
|
var resp []*SentinelPolicyListStub
|
|
|
|
qm, err := a.client.query("/v1/sentinel/policies", &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return resp, qm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Upsert is used to create or update a policy
|
|
|
|
func (a *SentinelPolicies) Upsert(policy *SentinelPolicy, q *WriteOptions) (*WriteMeta, error) {
|
|
|
|
if policy == nil || policy.Name == "" {
|
2022-08-05 15:05:47 +00:00
|
|
|
return nil, errors.New("missing policy name")
|
2017-09-19 14:47:10 +00:00
|
|
|
}
|
2023-02-07 22:42:25 +00:00
|
|
|
wm, err := a.client.put("/v1/sentinel/policy/"+policy.Name, policy, nil, q)
|
2017-09-19 14:47:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return wm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete is used to delete a policy
|
|
|
|
func (a *SentinelPolicies) Delete(policyName string, q *WriteOptions) (*WriteMeta, error) {
|
|
|
|
if policyName == "" {
|
2022-08-05 15:05:47 +00:00
|
|
|
return nil, errors.New("missing policy name")
|
2017-09-19 14:47:10 +00:00
|
|
|
}
|
2022-07-06 14:30:11 +00:00
|
|
|
wm, err := a.client.delete("/v1/sentinel/policy/"+policyName, nil, nil, q)
|
2017-09-19 14:47:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return wm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Info is used to query a specific policy
|
|
|
|
func (a *SentinelPolicies) Info(policyName string, q *QueryOptions) (*SentinelPolicy, *QueryMeta, error) {
|
|
|
|
if policyName == "" {
|
2022-08-05 15:05:47 +00:00
|
|
|
return nil, nil, errors.New("missing policy name")
|
2017-09-19 14:47:10 +00:00
|
|
|
}
|
|
|
|
var resp SentinelPolicy
|
|
|
|
wm, err := a.client.query("/v1/sentinel/policy/"+policyName, &resp, q)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return &resp, wm, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type SentinelPolicy struct {
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Scope string
|
|
|
|
EnforcementLevel string
|
|
|
|
Policy string
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type SentinelPolicyListStub struct {
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Scope string
|
|
|
|
EnforcementLevel string
|
|
|
|
CreateIndex uint64
|
|
|
|
ModifyIndex uint64
|
|
|
|
}
|