Skip to content

Commit

Permalink
use typed eventTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Barheine committed Dec 22, 2017
1 parent 7ffd17c commit 70d1a77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pkg/hermes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/sapcc/hermes/pkg/identity"
"github.com/sapcc/hermes/pkg/storage"
"github.com/sapcc/hermes/pkg/util"
"time"
)

//ResourceRef is an embedded struct for ListEvents (eg. Initiator, Target, Observer)
Expand All @@ -37,7 +38,7 @@ type ResourceRef struct {
// The JSON annotations here are for the JSON to be returned by the API
type ListEvent struct {
ID string `json:"id"`
Time string `json:"eventTime"`
Time time.Time `json:"eventTime"`
Action string `json:"action"`
Outcome string `json:"outcome"`
Initiator ResourceRef `json:"initiator"`
Expand Down
24 changes: 13 additions & 11 deletions pkg/storage/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package storage

import "time"

// Status contains Prometheus status strings
// TODO: Determine if we want a similar setup for Elasticsearch.
type Status string
Expand Down Expand Up @@ -104,10 +106,10 @@ type eventListWithTotal struct {

// Resource contains attributes describing a (OpenStack-) Resource
type Resource struct {
TypeURI string `json:"typeURI"`
Name string `json:"name,omitempty"`
Domain string `json:"domain,omitempty"`
ID string `json:"id"`
TypeURI string `json:"typeURI"`
Name string `json:"name,omitempty"`
Domain string `json:"domain,omitempty"`
ID string `json:"id"`
Addresses []struct {
URL string `json:"url"`
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -142,13 +144,13 @@ type Attachment struct {
// Omissions: everything that we do not use or not expose to API users
// The JSON annotations are for parsing the result from ElasticSearch AND for generating the Hermes API response
type EventDetail struct {
TypeURI string `json:"typeURI"`
ID string `json:"id"`
EventTime string `json:"eventTime"`
Action string `json:"action"`
EventType string `json:"eventType"`
Outcome string `json:"outcome"`
Reason struct {
TypeURI string `json:"typeURI"`
ID string `json:"id"`
EventTime time.Time `json:"eventTime"`
Action string `json:"action"`
EventType string `json:"eventType"`
Outcome string `json:"outcome"`
Reason struct {
ReasonType string `json:"reasonType"`
ReasonCode string `json:"reasonCode"`
} `json:"reason,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func Test_MockStorage_EventDetail(t *testing.T) {
Expand All @@ -16,7 +17,7 @@ func Test_MockStorage_EventDetail(t *testing.T) {
}{
{"eventDetail.ID", eventDetail.ID, "7be6c4ff-b761-5f1f-b234-f5d41616c2cd"},
{"eventDetail.Action", eventDetail.Action, "create/role_assignment"},
{"eventDetail.EventTime", eventDetail.EventTime, "2017-11-17T08:53:32.667973+00:00"},
{"eventDetail.EventTime", eventDetail.EventTime.UTC().String(), "2017-11-17T08:53:32.667973+00:00"},
{"eventDetail.Outcome", eventDetail.Outcome, "success"},
{"eventDetail.EventType", eventDetail.EventType, "activity"},
{"eventDetail.Attachments[0].Name", eventDetail.Attachments[0].Name, "role_id"},
Expand Down

0 comments on commit 70d1a77

Please sign in to comment.