-
Notifications
You must be signed in to change notification settings - Fork 18
/
types.go
290 lines (247 loc) · 11.4 KB
/
types.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// Copyright 2020 Red Hat, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package types contains all user-defined data types used in Smart Proxy REST
// API service. Some types are the same as in other services (especially in
// Insights Results Aggregator, Content Service) and thus they are imported
// (based on) the common package insights-operator-utils/types.
package types
import (
"time"
types "github.com/RedHatInsights/insights-results-types"
)
// UserID represents type for user id
type UserID = types.UserID
// ReportResponseMeta contains metadata about the report
type ReportResponseMeta = types.ReportResponseMeta
// Timestamp represents any timestamp in a form gathered from database
type Timestamp = types.Timestamp
// RuleContent is a rename for types.RuleContent
type RuleContent = types.RuleContent
// RuleID is a rename for types.RuleID
type RuleID = types.RuleID
// ClusterName is a rename for types.ClusterName
type ClusterName = types.ClusterName
// OrgID is a rename for types.OrgID
type OrgID = types.OrgID
// ImpactingFlag controls the behaviour of 'impacting' param on GET /rule/
type ImpactingFlag int
// RequestID is used to store the request ID supplied in input Kafka records as
// a unique identifier of payloads. Empty string represents a missing request ID.
type RequestID types.RequestID
// RuleWithContentResponse represents a single rule in the response of /report endpoint
type RuleWithContentResponse struct {
RuleID types.RuleID `json:"rule_id"`
ErrorKey types.ErrorKey `json:"-"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
Generic string `json:"details"`
Reason string `json:"reason"`
Resolution string `json:"resolution"`
MoreInfo string `json:"more_info"`
TotalRisk int `json:"total_risk"`
Disabled bool `json:"disabled"`
DisableFeedback string `json:"disable_feedback"`
DisabledAt types.Timestamp `json:"disabled_at"`
Internal bool `json:"internal"`
UserVote types.UserVote `json:"user_vote"`
TemplateData interface{} `json:"extra_data"`
Tags []string `json:"tags"`
Impacted Timestamp `json:"impacted,omitempty"`
}
// RecommendationContent is a rule content struct used for Insights Advisor,
type RecommendationContent struct {
// RuleSelector = rule.module|ERROR_KEY format
RuleSelector types.RuleSelector `json:"rule_id"`
Description string `json:"description"`
Generic string `json:"generic"`
Reason string `json:"reason"`
Resolution string `json:"resolution"`
MoreInfo string `json:"more_info"`
TotalRisk uint8 `json:"total_risk"`
Impact uint8 `json:"impact"`
Likelihood uint8 `json:"likelihood"`
PublishDate time.Time `json:"publish_date"`
Tags []string `json:"tags"`
}
// RecommendationContentUserData is a rule content struct with additional Insights Advisor
// related user data, such as rule acknowledging or rating, which requires access to DB/aggregator
type RecommendationContentUserData struct {
// RuleSelector = rule.module|ERROR_KEY format
RuleSelector types.RuleSelector `json:"rule_id"`
Description string `json:"description"`
Generic string `json:"generic"`
Reason string `json:"reason"`
Resolution string `json:"resolution"`
MoreInfo string `json:"more_info"`
TotalRisk uint8 `json:"total_risk"`
Impact uint8 `json:"impact"`
Likelihood uint8 `json:"likelihood"`
PublishDate time.Time `json:"publish_date"`
Tags []string `json:"tags"`
Rating types.UserVote `json:"rating"`
AckedCount uint32 `json:"hosts_acked_count"`
Disabled bool `json:"disabled"`
ResolutionRisk uint8 `json:"resolution_risk"`
}
// ReportResponseMetaV1 contains metadata for /report endpoint in v1
type ReportResponseMetaV1 struct {
Count int `json:"count"`
LastCheckedAt Timestamp `json:"last_checked_at"`
}
// ReportResponseMetaV2 contains metadata for /report endpoint in v2
type ReportResponseMetaV2 struct {
DisplayName string `json:"cluster_name"`
Managed bool `json:"managed"`
Count int `json:"count"`
LastCheckedAt Timestamp `json:"last_checked_at,omitempty"`
GatheredAt Timestamp `json:"gathered_at,omitempty"`
}
// SmartProxyReportV1 represents the response of /report (V1) endpoint for smart proxy
// This structure exists to make sure we comply with the previous API used by some clients
type SmartProxyReportV1 struct {
Meta ReportResponseMetaV1 `json:"meta"`
Data []RuleWithContentResponse `json:"data"`
}
// SmartProxyReportV2 represents the response of /report (V2) endpoint for smart proxy
// This structure exists to make sure we comply with the previous API used by some clients
type SmartProxyReportV2 struct {
Meta ReportResponseMetaV2 `json:"meta"`
Data []RuleWithContentResponse `json:"data"`
}
// SmartProxyReport represents the response of /report (V2) endpoint for smart proxy
type SmartProxyReport struct {
Meta types.ReportResponseMeta `json:"meta"`
Data []RuleWithContentResponse `json:"data"`
}
// UserVote is a type for user's vote
type UserVote = types.UserVote
// ClusterOverview type for handling the overview result for each cluster
type ClusterOverview struct {
TotalRisksHit []int
TagsHit []string
}
// OrgOverviewResponse serves as a the API response for /org_overview endpoint
type OrgOverviewResponse struct {
ClustersHit int `json:"clusters_hit"`
ClustersHitByTotalRisk map[int]int `json:"hit_by_risk"`
ClustersHitByTag map[string]int `json:"hit_by_tag"`
}
const (
// UserVoteDislike shows user's dislike
UserVoteDislike = types.UserVoteDislike
// UserVoteNone shows no vote from user
UserVoteNone = types.UserVoteNone
// UserVoteLike shows user's like
UserVoteLike = types.UserVoteLike
)
// RuleWithContent structure with rule and rule content
type RuleWithContent struct {
Module types.RuleID `json:"module"`
Name string `json:"name"`
Summary string `json:"summary"`
Reason string `json:"reason"`
Resolution string `json:"resolution"`
MoreInfo string `json:"more_info"`
ErrorKey types.ErrorKey `json:"error_key"`
Description string `json:"description"`
TotalRisk int `json:"total_risk"`
ResolutionRisk int `json:"resolution_risk"`
Impact int `json:"impact"`
Likelihood int `json:"likelihood"`
PublishDate time.Time `json:"publish_date"`
Active bool `json:"active"`
Internal bool `json:"internal"`
Generic string `json:"generic"`
Tags []string `json:"tags"`
OSDCustomer bool `json:"osd_customer"`
}
// RecommendationListView represents the API response for Advisor /rule/ related endpoints
// RuleStatus is based on acknowledgment table (enabled/disabled)
type RecommendationListView struct {
// RuleID is in "|" format
RuleID types.RuleID `json:"rule_id"`
Description string `json:"description"`
Generic string `json:"generic"`
PublishDate time.Time `json:"publish_date"`
TotalRisk uint8 `json:"total_risk"`
ResolutionRisk uint8 `json:"resolution_risk"`
Impact uint8 `json:"impact"`
Likelihood uint8 `json:"likelihood"`
Tags []string `json:"tags"`
Disabled bool `json:"disabled"`
ImpactedClustersCnt uint32 `json:"impacted_clusters_count"`
}
// ClusterListView represents a single item in the response for Clusters List view
type ClusterListView struct {
ClusterID types.ClusterName `json:"cluster_id"`
ClusterName string `json:"cluster_name"`
Managed bool `json:"managed"`
LastCheckedAt Timestamp `json:"last_checked_at,omitempty"`
TotalHitCount uint32 `json:"total_hit_count"`
HitsByTotalRisk map[int]int `json:"hits_by_total_risk"`
Version types.Version `json:"cluster_version,omitempty"`
}
// RuleRating structure with the rule identifier and the rating
type RuleRating = types.RuleRating
// RuleContentV1 version 1 of RuleConted provided by smart proxy
type RuleContentV1 = types.RuleContentV1
// RuleErrorKeyContentV1 is in RuleContentV1
type RuleErrorKeyContentV1 = types.RuleErrorKeyContentV1
// ErrorKeyMetadataV1 is in RuleErrorKeyContentV1
type ErrorKeyMetadataV1 = types.ErrorKeyMetadataV1
// RuleContentV2 version 2 of RuleContent provided by smart proxy
type RuleContentV2 = types.RuleContentV2
// RuleErrorKeyContentV2 is in RuleContentV2
type RuleErrorKeyContentV2 = types.RuleErrorKeyContentV2
// ErrorKeyMetadataV2 is in RuleErrorKeyContentV2
type ErrorKeyMetadataV2 = types.ErrorKeyMetadataV2
// InfoResponse is a data structure returned by /info REST API endpoint
type InfoResponse struct {
SmartProxy map[string]string `json:"SmartProxy"`
Aggregator map[string]string `json:"Aggregator"`
ContentService map[string]string `json:"ContentService"`
}
// ClusterInfo is a data structure containing some relevant cluster information
type ClusterInfo struct {
ID ClusterName `json:"cluster_id"`
DisplayName string `json:"display_name"`
Managed bool `json:"managed"`
Status string `json:"status"`
}
// ClustersDetailData is the inner data structure for /clusters_detail
type ClustersDetailData struct {
EnabledClusters []types.HittingClustersData `json:"enabled"`
DisabledClusters []types.DisabledClusterInfo `json:"disabled"`
}
// ClustersDetailResponse is a data structure used as the response for /clusters_detail
type ClustersDetailResponse struct {
Data ClustersDetailData `json:"data"`
Status string `json:"status"`
}
// SimplifiedReport structure is used to handle single Request data hashes in Redis
type SimplifiedReport types.SimplifiedReport
// RequestStatus contains description about one request ID returned by the sercice to IO
type RequestStatus struct {
RequestID string `json:"requestID" redis:"request_id"`
Valid bool `json:"valid" redis:"-"`
Received string `json:"received" redis:"received_timestamp"`
Processed string `json:"processed" redis:"processed_timestamp"`
}
// SimplifiedRuleHit structure represents one simplified rule hit for On Demand Data Gathering
type SimplifiedRuleHit struct {
RuleFQDN string `json:"rule_fqdn"`
ErrorKey string `json:"error_key"`
Description string `json:"description"`
TotalRisk int `json:"total_risk"`
}