mirror of https://github.com/status-im/consul.git
Merge pull request #2947 from bogdanov1609/added_ACLReplication
API: Add ACLReplication
This commit is contained in:
commit
05b1cabba9
35
api/acl.go
35
api/acl.go
|
@ -1,5 +1,9 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ACLCLientType is the client type token
|
// ACLCLientType is the client type token
|
||||||
ACLClientType = "client"
|
ACLClientType = "client"
|
||||||
|
@ -18,6 +22,16 @@ type ACLEntry struct {
|
||||||
Rules string
|
Rules string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ACLReplicationStatus is used to represent the status of ACL replication.
|
||||||
|
type ACLReplicationStatus struct {
|
||||||
|
Enabled bool
|
||||||
|
Running bool
|
||||||
|
SourceDatacenter string
|
||||||
|
ReplicatedIndex uint64
|
||||||
|
LastSuccess time.Time
|
||||||
|
LastError time.Time
|
||||||
|
}
|
||||||
|
|
||||||
// ACL can be used to query the ACL endpoints
|
// ACL can be used to query the ACL endpoints
|
||||||
type ACL struct {
|
type ACL struct {
|
||||||
c *Client
|
c *Client
|
||||||
|
@ -138,3 +152,24 @@ func (a *ACL) List(q *QueryOptions) ([]*ACLEntry, *QueryMeta, error) {
|
||||||
}
|
}
|
||||||
return entries, qm, nil
|
return entries, qm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replication returns the status of the ACL replication process in the datacenter
|
||||||
|
func (a *ACL) Replication(q *QueryOptions) (*ACLReplicationStatus, *QueryMeta, error) {
|
||||||
|
r := a.c.newRequest("GET", "/v1/acl/replication")
|
||||||
|
r.setQueryOptions(q)
|
||||||
|
rtt, resp, err := requireOK(a.c.doRequest(r))
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
qm := &QueryMeta{}
|
||||||
|
parseQueryMeta(resp, qm)
|
||||||
|
qm.RequestTime = rtt
|
||||||
|
|
||||||
|
var entries *ACLReplicationStatus
|
||||||
|
if err := decodeBody(resp, &entries); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
return entries, qm, nil
|
||||||
|
}
|
||||||
|
|
|
@ -126,3 +126,32 @@ func TestACL_List(t *testing.T) {
|
||||||
t.Fatalf("bad: %v", qm)
|
t.Fatalf("bad: %v", qm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestACL_Replication(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
c, s := makeACLClient(t)
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
acl := c.ACL()
|
||||||
|
|
||||||
|
repl, qm, err := acl.Replication(nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if repl == nil {
|
||||||
|
t.Fatalf("bad: %v", repl)
|
||||||
|
}
|
||||||
|
|
||||||
|
if repl.Running {
|
||||||
|
t.Fatal("bad: repl should not be running")
|
||||||
|
}
|
||||||
|
|
||||||
|
if repl.Enabled {
|
||||||
|
t.Fatal("bad: repl should not be enabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
if qm.RequestTime == 0 {
|
||||||
|
t.Fatalf("bad: %v", qm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue