github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/api/cloudcontroller/ccv3/event.go (about) 1 package ccv3 2 3 import ( 4 "time" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 8 ) 9 10 type Event struct { 11 GUID string 12 CreatedAt time.Time 13 Type string 14 ActorName string 15 Data map[string]interface{} 16 } 17 18 func (e *Event) UnmarshalJSON(data []byte) error { 19 var ccEvent struct { 20 GUID string `json:"guid"` 21 CreatedAt time.Time `json:"created_at"` 22 Type string `json:"type"` 23 Actor struct { 24 Name string `json:"name"` 25 } `json:"actor"` 26 Data map[string]interface{} `json:"data"` 27 } 28 err := cloudcontroller.DecodeJSON(data, &ccEvent) 29 if err != nil { 30 return err 31 } 32 33 e.GUID = ccEvent.GUID 34 e.CreatedAt = ccEvent.CreatedAt 35 e.Type = ccEvent.Type 36 e.ActorName = ccEvent.Actor.Name 37 e.Data = ccEvent.Data 38 39 return nil 40 } 41 42 // GetEvents uses the /v3/audit_events endpoint to retrieve a list of audit events. 43 // NOTE: This only returns the first page of results. We are intentionally not using the paginate helper to fetch all 44 // pages here because we only needed the first page for the `cf events` output. If we need to, we can refactor this 45 // later to fetch all pages and make `cf events` only filter down to the first page. 46 func (client *Client) GetEvents(query ...Query) ([]Event, Warnings, error) { 47 var responseBody struct { 48 Resources []Event `json:"resources"` 49 } 50 51 _, warnings, err := client.MakeRequest(RequestParams{ 52 RequestName: internal.GetEventsRequest, 53 ResponseBody: &responseBody, 54 Query: query, 55 }) 56 57 return responseBody.Resources, warnings, err 58 }