-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathprofile_status.sql.go
More file actions
365 lines (338 loc) · 12.2 KB
/
Copy pathprofile_status.sql.go
File metadata and controls
365 lines (338 loc) · 12.2 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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: profile_status.sql
package db
import (
"context"
"database/sql"
"encoding/json"
"time"
"github.com/google/uuid"
"github.com/lib/pq"
"github.com/sqlc-dev/pqtype"
)
const getProfileStatusByIdAndProject = `-- name: GetProfileStatusByIdAndProject :one
SELECT p.id, p.name, ps.profile_status, ps.last_updated FROM profile_status ps
INNER JOIN profiles p ON p.id = ps.profile_id
WHERE p.id = $1 AND p.project_id = $2
`
type GetProfileStatusByIdAndProjectParams struct {
ID uuid.UUID `json:"id"`
ProjectID uuid.UUID `json:"project_id"`
}
type GetProfileStatusByIdAndProjectRow struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
ProfileStatus EvalStatusTypes `json:"profile_status"`
LastUpdated time.Time `json:"last_updated"`
}
func (q *Queries) GetProfileStatusByIdAndProject(ctx context.Context, arg GetProfileStatusByIdAndProjectParams) (GetProfileStatusByIdAndProjectRow, error) {
row := q.db.QueryRowContext(ctx, getProfileStatusByIdAndProject, arg.ID, arg.ProjectID)
var i GetProfileStatusByIdAndProjectRow
err := row.Scan(
&i.ID,
&i.Name,
&i.ProfileStatus,
&i.LastUpdated,
)
return i, err
}
const getProfileStatusByNameAndProject = `-- name: GetProfileStatusByNameAndProject :one
SELECT p.id, p.name, ps.profile_status, ps.last_updated FROM profile_status ps
INNER JOIN profiles p ON p.id = ps.profile_id
WHERE lower(p.name) = lower($2) AND p.project_id = $1
`
type GetProfileStatusByNameAndProjectParams struct {
ProjectID uuid.UUID `json:"project_id"`
Name string `json:"name"`
}
type GetProfileStatusByNameAndProjectRow struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
ProfileStatus EvalStatusTypes `json:"profile_status"`
LastUpdated time.Time `json:"last_updated"`
}
func (q *Queries) GetProfileStatusByNameAndProject(ctx context.Context, arg GetProfileStatusByNameAndProjectParams) (GetProfileStatusByNameAndProjectRow, error) {
row := q.db.QueryRowContext(ctx, getProfileStatusByNameAndProject, arg.ProjectID, arg.Name)
var i GetProfileStatusByNameAndProjectRow
err := row.Scan(
&i.ID,
&i.Name,
&i.ProfileStatus,
&i.LastUpdated,
)
return i, err
}
const getProfileStatusByProject = `-- name: GetProfileStatusByProject :many
SELECT p.id, p.name, ps.profile_status, ps.last_updated FROM profile_status ps
INNER JOIN profiles p ON p.id = ps.profile_id
WHERE p.project_id = $1
`
type GetProfileStatusByProjectRow struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
ProfileStatus EvalStatusTypes `json:"profile_status"`
LastUpdated time.Time `json:"last_updated"`
}
func (q *Queries) GetProfileStatusByProject(ctx context.Context, projectID uuid.UUID) ([]GetProfileStatusByProjectRow, error) {
rows, err := q.db.QueryContext(ctx, getProfileStatusByProject, projectID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []GetProfileStatusByProjectRow{}
for rows.Next() {
var i GetProfileStatusByProjectRow
if err := rows.Scan(
&i.ID,
&i.Name,
&i.ProfileStatus,
&i.LastUpdated,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listOldestRuleEvaluationsByEntityID = `-- name: ListOldestRuleEvaluationsByEntityID :many
SELECT ere.entity_instance_id, MIN(es.evaluation_time)::timestamp AS oldest_last_updated
FROM evaluation_rule_entities AS ere
INNER JOIN latest_evaluation_statuses AS les ON ere.id = les.rule_entity_id
INNER JOIN evaluation_statuses AS es ON les.evaluation_history_id = es.id
WHERE ere.entity_instance_id = ANY ($1::uuid[])
GROUP BY ere.entity_instance_id
`
type ListOldestRuleEvaluationsByEntityIDRow struct {
EntityInstanceID uuid.UUID `json:"entity_instance_id"`
OldestLastUpdated time.Time `json:"oldest_last_updated"`
}
// ListOldestRuleEvaluationsByEntityID returns the oldest evaluation time for each entity.
// cast after MIN is required due to a known bug in sqlc: https://github.com/sqlc-dev/sqlc/issues/1965
func (q *Queries) ListOldestRuleEvaluationsByEntityID(ctx context.Context, entityIds []uuid.UUID) ([]ListOldestRuleEvaluationsByEntityIDRow, error) {
rows, err := q.db.QueryContext(ctx, listOldestRuleEvaluationsByEntityID, pq.Array(entityIds))
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListOldestRuleEvaluationsByEntityIDRow{}
for rows.Next() {
var i ListOldestRuleEvaluationsByEntityIDRow
if err := rows.Scan(&i.EntityInstanceID, &i.OldestLastUpdated); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listOldestRuleEvaluationsByRepositoryId = `-- name: ListOldestRuleEvaluationsByRepositoryId :many
SELECT ere.entity_instance_id::uuid AS repository_id, MIN(es.evaluation_time)::timestamp AS oldest_last_updated
FROM evaluation_rule_entities AS ere
INNER JOIN latest_evaluation_statuses AS les ON ere.id = les.rule_entity_id
INNER JOIN evaluation_statuses AS es ON les.evaluation_history_id = es.id
WHERE ere.entity_instance_id = ANY ($1::uuid[])
AND ere.entity_type = 'repository'
GROUP BY ere.entity_instance_id
`
type ListOldestRuleEvaluationsByRepositoryIdRow struct {
RepositoryID uuid.UUID `json:"repository_id"`
OldestLastUpdated time.Time `json:"oldest_last_updated"`
}
// ListOldestRuleEvaluationsByRepositoryId has casts in select statement as sqlc generates incorrect types.
// cast after MIN is required due to a known bug in sqlc: https://github.com/sqlc-dev/sqlc/issues/1965
// DEPRECATED: Use ListOldestRuleEvaluationsByEntityID instead
func (q *Queries) ListOldestRuleEvaluationsByRepositoryId(ctx context.Context, repositoryIds []uuid.UUID) ([]ListOldestRuleEvaluationsByRepositoryIdRow, error) {
rows, err := q.db.QueryContext(ctx, listOldestRuleEvaluationsByRepositoryId, pq.Array(repositoryIds))
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListOldestRuleEvaluationsByRepositoryIdRow{}
for rows.Next() {
var i ListOldestRuleEvaluationsByRepositoryIdRow
if err := rows.Scan(&i.RepositoryID, &i.OldestLastUpdated); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listRuleEvaluationsByProfileId = `-- name: ListRuleEvaluationsByProfileId :many
WITH
eval_details AS (
SELECT
id,
status AS eval_status,
details AS eval_details,
evaluation_time AS eval_last_updated
FROM evaluation_statuses
),
remediation_details AS (
SELECT
evaluation_id,
status AS rem_status,
details AS rem_details,
metadata AS rem_metadata,
created_at AS rem_last_updated
FROM remediation_events
),
alert_details AS (
SELECT
evaluation_id,
status AS alert_status,
details AS alert_details,
metadata AS alert_metadata,
created_at AS alert_last_updated
FROM alert_events
)
SELECT
ed.eval_status,
ed.eval_last_updated,
ed.eval_details,
rd.rem_status,
rd.rem_details,
rd.rem_metadata,
rd.rem_last_updated,
ad.alert_status,
ad.alert_details,
ad.alert_metadata,
ad.alert_last_updated,
ed.id AS rule_evaluation_id,
ere.entity_type,
ri.name AS rule_name,
prov.name AS provider,
rt.name AS rule_type_name,
rt.severity_value as rule_type_severity_value,
rt.id AS rule_type_id,
rt.guidance as rule_type_guidance,
rt.display_name as rule_type_display_name,
ere.entity_instance_id as entity_id,
ei.name as entity_name,
ei.project_id as project_id,
rt.release_phase as rule_type_release_phase,
eo.output AS eval_output
FROM latest_evaluation_statuses les
INNER JOIN evaluation_rule_entities ere ON ere.id = les.rule_entity_id
INNER JOIN eval_details ed ON ed.id = les.evaluation_history_id
INNER JOIN remediation_details rd ON rd.evaluation_id = les.evaluation_history_id
INNER JOIN alert_details ad ON ad.evaluation_id = les.evaluation_history_id
INNER JOIN rule_instances AS ri ON ri.id = ere.rule_id
INNER JOIN rule_type rt ON rt.id = ri.rule_type_id
INNER JOIN entity_instances ei ON ei.id = ere.entity_instance_id
INNER JOIN providers prov ON prov.id = ei.provider_id
LEFT JOIN evaluation_outputs eo ON eo.id = les.evaluation_history_id AND $2::boolean
WHERE les.profile_id = $1
AND (ere.entity_instance_id = $3::UUID OR $3::UUID IS NULL)
AND (ei.name = $4 OR $4 IS NULL)
AND (rt.name = $5 OR $5 IS NULL)
AND (lower(ri.name) = lower($6) OR $6 IS NULL)
`
type ListRuleEvaluationsByProfileIdParams struct {
ProfileID uuid.UUID `json:"profile_id"`
IncludeOutputs bool `json:"include_outputs"`
EntityID uuid.NullUUID `json:"entity_id"`
EntityName sql.NullString `json:"entity_name"`
RuleTypeName sql.NullString `json:"rule_type_name"`
RuleName sql.NullString `json:"rule_name"`
}
type ListRuleEvaluationsByProfileIdRow struct {
EvalStatus EvalStatusTypes `json:"eval_status"`
EvalLastUpdated time.Time `json:"eval_last_updated"`
EvalDetails string `json:"eval_details"`
RemStatus RemediationStatusTypes `json:"rem_status"`
RemDetails string `json:"rem_details"`
RemMetadata json.RawMessage `json:"rem_metadata"`
RemLastUpdated time.Time `json:"rem_last_updated"`
AlertStatus AlertStatusTypes `json:"alert_status"`
AlertDetails string `json:"alert_details"`
AlertMetadata json.RawMessage `json:"alert_metadata"`
AlertLastUpdated time.Time `json:"alert_last_updated"`
RuleEvaluationID uuid.UUID `json:"rule_evaluation_id"`
EntityType Entities `json:"entity_type"`
RuleName string `json:"rule_name"`
Provider string `json:"provider"`
RuleTypeName string `json:"rule_type_name"`
RuleTypeSeverityValue Severity `json:"rule_type_severity_value"`
RuleTypeID uuid.UUID `json:"rule_type_id"`
RuleTypeGuidance string `json:"rule_type_guidance"`
RuleTypeDisplayName string `json:"rule_type_display_name"`
EntityID uuid.UUID `json:"entity_id"`
EntityName string `json:"entity_name"`
ProjectID uuid.UUID `json:"project_id"`
RuleTypeReleasePhase ReleaseStatus `json:"rule_type_release_phase"`
EvalOutput pqtype.NullRawMessage `json:"eval_output"`
}
func (q *Queries) ListRuleEvaluationsByProfileId(ctx context.Context, arg ListRuleEvaluationsByProfileIdParams) ([]ListRuleEvaluationsByProfileIdRow, error) {
rows, err := q.db.QueryContext(ctx, listRuleEvaluationsByProfileId,
arg.ProfileID,
arg.IncludeOutputs,
arg.EntityID,
arg.EntityName,
arg.RuleTypeName,
arg.RuleName,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListRuleEvaluationsByProfileIdRow{}
for rows.Next() {
var i ListRuleEvaluationsByProfileIdRow
if err := rows.Scan(
&i.EvalStatus,
&i.EvalLastUpdated,
&i.EvalDetails,
&i.RemStatus,
&i.RemDetails,
&i.RemMetadata,
&i.RemLastUpdated,
&i.AlertStatus,
&i.AlertDetails,
&i.AlertMetadata,
&i.AlertLastUpdated,
&i.RuleEvaluationID,
&i.EntityType,
&i.RuleName,
&i.Provider,
&i.RuleTypeName,
&i.RuleTypeSeverityValue,
&i.RuleTypeID,
&i.RuleTypeGuidance,
&i.RuleTypeDisplayName,
&i.EntityID,
&i.EntityName,
&i.ProjectID,
&i.RuleTypeReleasePhase,
&i.EvalOutput,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}