github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/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 func (client *Client) GetEvents(query ...Query) ([]Event, Warnings, error) { 44 var events []Event 45 46 _, warnings, err := client.MakeListRequest(RequestParams{ 47 RequestName: internal.GetEventsRequest, 48 Query: query, 49 ResponseBody: Event{}, 50 AppendToList: func(item interface{}) error { 51 events = append(events, item.(Event)) 52 return nil 53 }, 54 }) 55 56 return events, warnings, err 57 }