github.com/emate/nomad@v0.8.2-wo-binpacking/api/sentinel.go (about) 1 package api 2 3 import "fmt" 4 5 // SentinelPolicies is used to query the Sentinel Policy endpoints. 6 type SentinelPolicies struct { 7 client *Client 8 } 9 10 // SentinelPolicies returns a new handle on the Sentinel policies. 11 func (c *Client) SentinelPolicies() *SentinelPolicies { 12 return &SentinelPolicies{client: c} 13 } 14 15 // List is used to dump all of the policies. 16 func (a *SentinelPolicies) List(q *QueryOptions) ([]*SentinelPolicyListStub, *QueryMeta, error) { 17 var resp []*SentinelPolicyListStub 18 qm, err := a.client.query("/v1/sentinel/policies", &resp, q) 19 if err != nil { 20 return nil, nil, err 21 } 22 return resp, qm, nil 23 } 24 25 // Upsert is used to create or update a policy 26 func (a *SentinelPolicies) Upsert(policy *SentinelPolicy, q *WriteOptions) (*WriteMeta, error) { 27 if policy == nil || policy.Name == "" { 28 return nil, fmt.Errorf("missing policy name") 29 } 30 wm, err := a.client.write("/v1/sentinel/policy/"+policy.Name, policy, nil, q) 31 if err != nil { 32 return nil, err 33 } 34 return wm, nil 35 } 36 37 // Delete is used to delete a policy 38 func (a *SentinelPolicies) Delete(policyName string, q *WriteOptions) (*WriteMeta, error) { 39 if policyName == "" { 40 return nil, fmt.Errorf("missing policy name") 41 } 42 wm, err := a.client.delete("/v1/sentinel/policy/"+policyName, nil, q) 43 if err != nil { 44 return nil, err 45 } 46 return wm, nil 47 } 48 49 // Info is used to query a specific policy 50 func (a *SentinelPolicies) Info(policyName string, q *QueryOptions) (*SentinelPolicy, *QueryMeta, error) { 51 if policyName == "" { 52 return nil, nil, fmt.Errorf("missing policy name") 53 } 54 var resp SentinelPolicy 55 wm, err := a.client.query("/v1/sentinel/policy/"+policyName, &resp, q) 56 if err != nil { 57 return nil, nil, err 58 } 59 return &resp, wm, nil 60 } 61 62 type SentinelPolicy struct { 63 Name string 64 Description string 65 Scope string 66 EnforcementLevel string 67 Policy string 68 CreateIndex uint64 69 ModifyIndex uint64 70 } 71 72 type SentinelPolicyListStub struct { 73 Name string 74 Description string 75 Scope string 76 EnforcementLevel string 77 CreateIndex uint64 78 ModifyIndex uint64 79 }