-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathmonitor_log_streams.go
More file actions
148 lines (123 loc) · 5.21 KB
/
Copy pathmonitor_log_streams.go
File metadata and controls
148 lines (123 loc) · 5.21 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/v2/internal/parseabletime"
)
// StreamType represents the type of ACLP logs stream.
type StreamType string
const (
// StreamTypeAuditLogs configures a stream for ACLP audit logs.
StreamTypeAuditLogs StreamType = "audit_logs"
// StreamTypeLKEAuditLogs configures a stream for LKE enterprise cluster audit logs.
StreamTypeLKEAuditLogs StreamType = "lke_audit_logs"
)
// StreamStatus represents the availability state of an ACLP logs stream.
type StreamStatus string
const (
// StreamStatusActive means the stream is actively delivering logs.
StreamStatusActive StreamStatus = "active"
// StreamStatusInactive means the stream is paused.
StreamStatusInactive StreamStatus = "inactive"
// StreamStatusProvisioning means the stream is being set up.
StreamStatusProvisioning StreamStatus = "provisioning"
// StreamStatusDeactivating means the stream is being deactivated.
StreamStatusDeactivating StreamStatus = "deactivating"
)
// StreamDestinationType represents the destination type for ACLP logs streams.
type StreamDestinationType string
const (
// StreamDestinationTypeAkamaiObjectStorage sends logs to Akamai Object Storage.
StreamDestinationTypeAkamaiObjectStorage StreamDestinationType = "akamai_object_storage"
// StreamDestinationTypeCustomHTTPS sends logs to a custom HTTPS endpoint.
StreamDestinationTypeCustomHTTPS StreamDestinationType = "custom_https"
)
// StreamDetails contains additional details for a logs stream.
// This only applies to streams with a Type of StreamTypeLKEAuditLogs.
type StreamDetails struct {
ClusterIDs []int `json:"cluster_ids,omitzero"`
IsAutoAddAllClustersEnabled bool `json:"is_auto_add_all_clusters_enabled"`
}
// StreamDestination is a destination configured on an ACLP logs stream.
type StreamDestination struct {
ID int `json:"id"`
Label string `json:"label"`
Type StreamDestinationType `json:"type"`
Details LogsDestinationDetails `json:"details"`
}
// Stream represents an ACLP logs stream.
type Stream struct {
ID int `json:"id"`
Label string `json:"label"`
Type StreamType `json:"type"`
Status StreamStatus `json:"status"`
Version int `json:"version"`
Destinations []StreamDestination `json:"destinations"`
Details *StreamDetails `json:"details,omitzero"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
CreatedBy string `json:"created_by"`
UpdatedBy string `json:"updated_by"`
}
// StreamCreateOptions are the fields used to create an ACLP logs stream.
type StreamCreateOptions struct {
Destinations []int `json:"destinations"`
Label string `json:"label"`
Type StreamType `json:"type"`
Status *StreamStatus `json:"status,omitzero"`
Details *StreamDetails `json:"details,omitzero"`
}
// StreamUpdateOptions are the fields used to update an ACLP logs stream.
type StreamUpdateOptions struct {
Destinations []int `json:"destinations,omitzero"`
Label *string `json:"label,omitzero"`
Status *StreamStatus `json:"status,omitzero"`
Details *StreamDetails `json:"details,omitzero"`
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *Stream) UnmarshalJSON(b []byte) error {
type mask Stream
p := struct {
*mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
}{
mask: (*mask)(s),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
s.Created = (*time.Time)(p.Created)
s.Updated = (*time.Time)(p.Updated)
return nil
}
// ListLogStreams returns all ACLP logs streams under the account.
func (c *Client) ListLogStreams(ctx context.Context, opts *ListOptions) ([]Stream, error) {
return getPaginatedResults[Stream](ctx, c, "monitor/streams", opts)
}
// GetLogStream returns a single ACLP logs stream by ID.
func (c *Client) GetLogStream(ctx context.Context, streamID int) (*Stream, error) {
e := formatAPIPath("monitor/streams/%d", streamID)
return doGETRequest[Stream](ctx, c, e)
}
// CreateLogStream creates a new ACLP logs stream.
func (c *Client) CreateLogStream(ctx context.Context, opts StreamCreateOptions) (*Stream, error) {
e := formatAPIPath("monitor/streams")
return doPOSTRequest[Stream](ctx, c, e, opts)
}
// UpdateLogStream updates an ACLP logs stream by ID.
func (c *Client) UpdateLogStream(ctx context.Context, streamID int, opts StreamUpdateOptions) (*Stream, error) {
e := formatAPIPath("monitor/streams/%d", streamID)
return doPUTRequest[Stream](ctx, c, e, opts)
}
// ListLogStreamHistory returns all versions of an ACLP logs stream.
func (c *Client) ListLogStreamHistory(ctx context.Context, streamID int, opts *ListOptions) ([]Stream, error) {
e := formatAPIPath("monitor/streams/%d/history", streamID)
return getPaginatedResults[Stream](ctx, c, e, opts)
}
// DeleteLogStream deletes an ACLP logs stream by ID.
func (c *Client) DeleteLogStream(ctx context.Context, streamID int) error {
e := formatAPIPath("monitor/streams/%d", streamID)
return doDELETERequest(ctx, c, e)
}