From 6f33b2d0703d92dc465a6257fe946c72b3b64117 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 6 Mar 2018 09:04:44 -0800 Subject: [PATCH] agent: use UTC time for intention times, move empty list check to agent/consul --- agent/consul/intention_endpoint.go | 8 ++++++-- agent/consul/intention_endpoint_test.go | 3 +++ agent/intentions_endpoint.go | 4 ---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/agent/consul/intention_endpoint.go b/agent/consul/intention_endpoint.go index 825c89c59..6653d5502 100644 --- a/agent/consul/intention_endpoint.go +++ b/agent/consul/intention_endpoint.go @@ -67,7 +67,7 @@ func (s *Intention) Apply( } // Set the created at - args.Intention.CreatedAt = time.Now() + args.Intention.CreatedAt = time.Now().UTC() } *reply = args.Intention.ID @@ -84,7 +84,7 @@ func (s *Intention) Apply( } // We always update the updatedat field. This has no effect for deletion. - args.Intention.UpdatedAt = time.Now() + args.Intention.UpdatedAt = time.Now().UTC() // Default source type if args.Intention.SourceType == "" { @@ -169,6 +169,10 @@ func (s *Intention) List( } reply.Index, reply.Intentions = index, ixns + if reply.Intentions == nil { + reply.Intentions = make(structs.Intentions, 0) + } + // filterACL return nil }, diff --git a/agent/consul/intention_endpoint_test.go b/agent/consul/intention_endpoint_test.go index 3c38e695a..751b7894c 100644 --- a/agent/consul/intention_endpoint_test.go +++ b/agent/consul/intention_endpoint_test.go @@ -384,6 +384,9 @@ func TestIntentionList(t *testing.T) { if err := msgpackrpc.CallWithCodec(codec, "Intention.List", req, &resp); err != nil { t.Fatalf("err: %v", err) } + if resp.Intentions == nil { + t.Fatal("should not be nil") + } if len(resp.Intentions) != 0 { t.Fatalf("bad: %v", resp) diff --git a/agent/intentions_endpoint.go b/agent/intentions_endpoint.go index 72a1cba67..5196f06c5 100644 --- a/agent/intentions_endpoint.go +++ b/agent/intentions_endpoint.go @@ -37,10 +37,6 @@ func (s *HTTPServer) IntentionList(resp http.ResponseWriter, req *http.Request) return nil, err } - // Use empty list instead of nil. - if reply.Intentions == nil { - reply.Intentions = make(structs.Intentions, 0) - } return reply.Intentions, nil }