From 1ebd6402fd1c57897ea4ae21f1fe2a97313e8b16 Mon Sep 17 00:00:00 2001 From: Ivan Bogdanov Date: Tue, 25 Apr 2017 00:39:50 +0300 Subject: [PATCH 1/3] API: Add ACLReplication --- api/acl.go | 35 +++++++++++++++++++++++++++++++++++ api/acl_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/api/acl.go b/api/acl.go index c3fb0d53aa..3bf7cc8de0 100644 --- a/api/acl.go +++ b/api/acl.go @@ -1,5 +1,9 @@ package api +import ( + "time" +) + const ( // ACLCLientType is the client type token ACLClientType = "client" @@ -18,6 +22,16 @@ type ACLEntry struct { Rules string } +// ACLReplicationEntry is used to represent an ACLReplication entry +type ACLReplicationEntry struct { + Enabled bool + Running bool + SourceDatacenter string + ReplicatedIndex uint64 + LastSuccess time.Time + LastError time.Time +} + // ACL can be used to query the ACL endpoints type ACL struct { c *Client @@ -138,3 +152,24 @@ func (a *ACL) List(q *QueryOptions) ([]*ACLEntry, *QueryMeta, error) { } return entries, qm, nil } + +// Replication returns the status of the ACL replication process in the datacenter +func (a *ACL) Replication(q *QueryOptions) (*ACLReplicationEntry, *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 *ACLReplicationEntry + if err := decodeBody(resp, &entries); err != nil { + return nil, nil, err + } + return entries, qm, nil +} diff --git a/api/acl_test.go b/api/acl_test.go index 2a5207a6ee..e8a3e6d87d 100644 --- a/api/acl_test.go +++ b/api/acl_test.go @@ -126,3 +126,32 @@ func TestACL_List(t *testing.T) { 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) + } +} From 138abeb5f76fcf265529d815dcf11aad32f00d7e Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 25 Apr 2017 16:31:20 -0700 Subject: [PATCH 2/3] Tweaks ACL replication status struct name. --- api/acl.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/acl.go b/api/acl.go index 3bf7cc8de0..ee6d196669 100644 --- a/api/acl.go +++ b/api/acl.go @@ -22,7 +22,7 @@ type ACLEntry struct { Rules string } -// ACLReplicationEntry is used to represent an ACLReplication entry +// ACLReplicationStatus is used to represent the status of ACL replication. type ACLReplicationEntry struct { Enabled bool Running bool @@ -154,7 +154,7 @@ func (a *ACL) List(q *QueryOptions) ([]*ACLEntry, *QueryMeta, error) { } // Replication returns the status of the ACL replication process in the datacenter -func (a *ACL) Replication(q *QueryOptions) (*ACLReplicationEntry, *QueryMeta, error) { +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)) @@ -167,7 +167,7 @@ func (a *ACL) Replication(q *QueryOptions) (*ACLReplicationEntry, *QueryMeta, er parseQueryMeta(resp, qm) qm.RequestTime = rtt - var entries *ACLReplicationEntry + var entries *ACLReplicationStatus if err := decodeBody(resp, &entries); err != nil { return nil, nil, err } From 36725cef116a20dd53fdc951a4e0b63366125492 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 25 Apr 2017 16:32:09 -0700 Subject: [PATCH 3/3] Tweaks ACL replication struct name. --- api/acl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/acl.go b/api/acl.go index ee6d196669..15d1f9f5aa 100644 --- a/api/acl.go +++ b/api/acl.go @@ -23,7 +23,7 @@ type ACLEntry struct { } // ACLReplicationStatus is used to represent the status of ACL replication. -type ACLReplicationEntry struct { +type ACLReplicationStatus struct { Enabled bool Running bool SourceDatacenter string