-
Notifications
You must be signed in to change notification settings - Fork 7
/
event.go
76 lines (61 loc) · 1.98 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package gsclient
import (
"context"
"net/http"
)
// EventOperator provides an interface for operations on events.
type EventOperator interface {
GetEventList(ctx context.Context) ([]Event, error)
}
// EventList holds a list of events.
type EventList struct {
// Array of events.
List []EventProperties `json:"events"`
}
// Event represent a single event.
type Event struct {
// Properties of an event.
Properties EventProperties `json:"event"`
}
// EventProperties holds the properties of an event.
type EventProperties struct {
// Type of object (server, storage, IP) etc.
ObjectType string `json:"object_type"`
// The UUID of the event.
RequestUUID string `json:"request_uuid"`
// The UUID of the objects the event was executed on.
ObjectUUID string `json:"object_uuid"`
// The type of change.
Activity string `json:"activity"`
// The type of request.
RequestType string `json:"request_type"`
// True or false, whether the request was successful or not.
RequestStatus string `json:"request_status"`
// A detailed description of the change.
Change string `json:"change"`
// Time the event was triggered.
Timestamp GSTime `json:"timestamp"`
// The UUID of the user that triggered the event.
UserUUID string `json:"user_uuid"`
// The user that triggered the event.
// Usually the user's email if the event was triggered by request of a user,
// otherwise a short descriptive name of the system component responsible.
Initiator string `json:"initiator"`
}
// GetEventList gets a list of events.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/EventGetAll
func (c *Client) GetEventList(ctx context.Context) ([]Event, error) {
r := gsRequest{
uri: apiEventBase,
method: http.MethodGet,
skipCheckingRequest: true,
}
var response EventList
var events []Event
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
events = append(events, Event{Properties: properties})
}
return events, err
}