mirror of https://github.com/coder/coder.git
Add cohort queries
This commit is contained in:
parent
875bdf5c9b
commit
02b808ea6c
|
@ -222,5 +222,6 @@
|
|||
"go.testFlags": ["-short", "-coverpkg=./..."],
|
||||
// We often use a version of TypeScript that's ahead of the version shipped
|
||||
// with VS Code.
|
||||
"typescript.tsdk": "./site/node_modules/typescript/lib"
|
||||
"typescript.tsdk": "./site/node_modules/typescript/lib",
|
||||
"codeQL.githubDatabase.download": "never"
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
func main() {
|
||||
runtime.LockOSThread()
|
||||
runtime.GOMAXPROCS(1)
|
||||
|
||||
err := run(context.Background())
|
||||
if err != nil && os.Getenv("CODER_INTEL_INVOKE_DEBUG") != "" {
|
||||
_, _ = fmt.Printf("error: %v\n", err)
|
||||
|
|
|
@ -791,6 +791,10 @@ func (q *querier) DeleteGroupMemberFromGroup(ctx context.Context, arg database.D
|
|||
return update(q.log, q.auth, fetch, q.db.DeleteGroupMemberFromGroup)(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) DeleteIntelCohortsByIDs(ctx context.Context, dollar_1 []uuid.UUID) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (q *querier) DeleteLicense(ctx context.Context, id int32) (int32, error) {
|
||||
err := deleteQ(q.log, q.auth, q.db.GetLicenseByID, func(ctx context.Context, id int32) error {
|
||||
_, err := q.db.DeleteLicense(ctx, id)
|
||||
|
@ -1163,6 +1167,10 @@ func (q *querier) GetHungProvisionerJobs(ctx context.Context, hungSince time.Tim
|
|||
return q.db.GetHungProvisionerJobs(ctx, hungSince)
|
||||
}
|
||||
|
||||
func (q *querier) GetIntelCohortsByOrganizationID(ctx context.Context, organizationID uuid.UUID) ([]database.IntelCohort, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (q *querier) GetIntelCohortsMatchedByMachineIDs(ctx context.Context, ids []uuid.UUID) ([]database.GetIntelCohortsMatchedByMachineIDsRow, error) {
|
||||
// No authz checks - it'd be too slow to check the
|
||||
// authorization for each user and each machine.
|
||||
|
@ -2339,10 +2347,6 @@ func (q *querier) InsertGroupMember(ctx context.Context, arg database.InsertGrou
|
|||
return update(q.log, q.auth, fetch, q.db.InsertGroupMember)(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) InsertIntelCohort(ctx context.Context, arg database.InsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
return insert(q.log, q.auth, rbac.ResourceGroup.InOrg(arg.OrganizationID), q.db.InsertIntelCohort)(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) InsertIntelInvocations(ctx context.Context, arg database.InsertIntelInvocationsParams) error {
|
||||
// No authz checks - it'd be too slow to check the
|
||||
// authorization for each user and each machine.
|
||||
|
@ -3345,6 +3349,10 @@ func (q *querier) UpsertHealthSettings(ctx context.Context, value string) error
|
|||
return q.db.UpsertHealthSettings(ctx, value)
|
||||
}
|
||||
|
||||
func (q *querier) UpsertIntelCohort(ctx context.Context, arg database.UpsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
return insert(q.log, q.auth, rbac.ResourceGroup.InOrg(arg.OrganizationID), q.db.UpsertIntelCohort)(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) UpsertIntelMachine(ctx context.Context, arg database.UpsertIntelMachineParams) (database.IntelMachine, error) {
|
||||
// No authz
|
||||
return q.db.UpsertIntelMachine(ctx, arg)
|
||||
|
|
|
@ -1302,6 +1302,10 @@ func (q *FakeQuerier) DeleteGroupMemberFromGroup(_ context.Context, arg database
|
|||
return nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) DeleteIntelCohortsByIDs(ctx context.Context, dollar_1 []uuid.UUID) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) DeleteLicense(_ context.Context, id int32) (int32, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
@ -2371,6 +2375,10 @@ func (q *FakeQuerier) GetHungProvisionerJobs(_ context.Context, hungSince time.T
|
|||
return hungJobs, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetIntelCohortsByOrganizationID(ctx context.Context, organizationID uuid.UUID) ([]database.IntelCohort, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetIntelCohortsMatchedByMachineIDs(_ context.Context, ids []uuid.UUID) ([]database.GetIntelCohortsMatchedByMachineIDsRow, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
@ -5905,33 +5913,6 @@ func (q *FakeQuerier) InsertGroupMember(_ context.Context, arg database.InsertGr
|
|||
return nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) InsertIntelCohort(_ context.Context, arg database.InsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
err := validateDatabaseType(arg)
|
||||
if err != nil {
|
||||
return database.IntelCohort{}, err
|
||||
}
|
||||
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
cohort := database.IntelCohort{
|
||||
ID: arg.ID,
|
||||
OrganizationID: arg.OrganizationID,
|
||||
CreatedBy: arg.CreatedBy,
|
||||
CreatedAt: arg.CreatedAt,
|
||||
UpdatedAt: arg.UpdatedAt,
|
||||
DisplayName: arg.DisplayName,
|
||||
Description: arg.Description,
|
||||
FilterRegexOperatingSystem: arg.FilterRegexOperatingSystem,
|
||||
FilterRegexOperatingSystemVersion: arg.FilterRegexOperatingSystemVersion,
|
||||
FilterRegexArchitecture: arg.FilterRegexArchitecture,
|
||||
FilterRegexInstanceID: arg.FilterRegexInstanceID,
|
||||
TrackedExecutables: arg.TrackedExecutables,
|
||||
}
|
||||
q.intelCohorts = append(q.intelCohorts, cohort)
|
||||
return cohort, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) InsertIntelInvocations(_ context.Context, arg database.InsertIntelInvocationsParams) error {
|
||||
err := validateDatabaseType(arg)
|
||||
if err != nil {
|
||||
|
@ -8308,6 +8289,33 @@ func (q *FakeQuerier) UpsertHealthSettings(_ context.Context, data string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) UpsertIntelCohort(_ context.Context, arg database.UpsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
err := validateDatabaseType(arg)
|
||||
if err != nil {
|
||||
return database.IntelCohort{}, err
|
||||
}
|
||||
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
cohort := database.IntelCohort{
|
||||
ID: arg.ID,
|
||||
OrganizationID: arg.OrganizationID,
|
||||
CreatedBy: arg.CreatedBy,
|
||||
CreatedAt: arg.CreatedAt,
|
||||
UpdatedAt: arg.UpdatedAt,
|
||||
DisplayName: arg.DisplayName,
|
||||
Description: arg.Description,
|
||||
FilterRegexOperatingSystem: arg.FilterRegexOperatingSystem,
|
||||
FilterRegexOperatingSystemVersion: arg.FilterRegexOperatingSystemVersion,
|
||||
FilterRegexArchitecture: arg.FilterRegexArchitecture,
|
||||
FilterRegexInstanceID: arg.FilterRegexInstanceID,
|
||||
TrackedExecutables: arg.TrackedExecutables,
|
||||
}
|
||||
q.intelCohorts = append(q.intelCohorts, cohort)
|
||||
return cohort, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) UpsertIntelMachine(ctx context.Context, arg database.UpsertIntelMachineParams) (database.IntelMachine, error) {
|
||||
err := validateDatabaseType(arg)
|
||||
if err != nil {
|
||||
|
|
|
@ -212,6 +212,13 @@ func (m metricsStore) DeleteGroupMemberFromGroup(ctx context.Context, arg databa
|
|||
return err
|
||||
}
|
||||
|
||||
func (m metricsStore) DeleteIntelCohortsByIDs(ctx context.Context, dollar_1 []uuid.UUID) error {
|
||||
start := time.Now()
|
||||
r0 := m.s.DeleteIntelCohortsByIDs(ctx, dollar_1)
|
||||
m.queryLatencies.WithLabelValues("DeleteIntelCohortsByIDs").Observe(time.Since(start).Seconds())
|
||||
return r0
|
||||
}
|
||||
|
||||
func (m metricsStore) DeleteLicense(ctx context.Context, id int32) (int32, error) {
|
||||
start := time.Now()
|
||||
licenseID, err := m.s.DeleteLicense(ctx, id)
|
||||
|
@ -590,6 +597,13 @@ func (m metricsStore) GetHungProvisionerJobs(ctx context.Context, hungSince time
|
|||
return jobs, err
|
||||
}
|
||||
|
||||
func (m metricsStore) GetIntelCohortsByOrganizationID(ctx context.Context, organizationID uuid.UUID) ([]database.IntelCohort, error) {
|
||||
start := time.Now()
|
||||
r0, r1 := m.s.GetIntelCohortsByOrganizationID(ctx, organizationID)
|
||||
m.queryLatencies.WithLabelValues("GetIntelCohortsByOrganizationID").Observe(time.Since(start).Seconds())
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
func (m metricsStore) GetIntelCohortsMatchedByMachineIDs(ctx context.Context, ids []uuid.UUID) ([]database.GetIntelCohortsMatchedByMachineIDsRow, error) {
|
||||
start := time.Now()
|
||||
r0, r1 := m.s.GetIntelCohortsMatchedByMachineIDs(ctx, ids)
|
||||
|
@ -1493,13 +1507,6 @@ func (m metricsStore) InsertGroupMember(ctx context.Context, arg database.Insert
|
|||
return err
|
||||
}
|
||||
|
||||
func (m metricsStore) InsertIntelCohort(ctx context.Context, arg database.InsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
start := time.Now()
|
||||
r0, r1 := m.s.InsertIntelCohort(ctx, arg)
|
||||
m.queryLatencies.WithLabelValues("InsertIntelCohort").Observe(time.Since(start).Seconds())
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
func (m metricsStore) InsertIntelInvocations(ctx context.Context, arg database.InsertIntelInvocationsParams) error {
|
||||
start := time.Now()
|
||||
r0 := m.s.InsertIntelInvocations(ctx, arg)
|
||||
|
@ -2186,6 +2193,13 @@ func (m metricsStore) UpsertHealthSettings(ctx context.Context, value string) er
|
|||
return r0
|
||||
}
|
||||
|
||||
func (m metricsStore) UpsertIntelCohort(ctx context.Context, arg database.UpsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
start := time.Now()
|
||||
r0, r1 := m.s.UpsertIntelCohort(ctx, arg)
|
||||
m.queryLatencies.WithLabelValues("UpsertIntelCohort").Observe(time.Since(start).Seconds())
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
func (m metricsStore) UpsertIntelMachine(ctx context.Context, arg database.UpsertIntelMachineParams) (database.IntelMachine, error) {
|
||||
start := time.Now()
|
||||
r0, r1 := m.s.UpsertIntelMachine(ctx, arg)
|
||||
|
|
|
@ -3130,19 +3130,19 @@ func (mr *MockStoreMockRecorder) InsertGroupMember(arg0, arg1 any) *gomock.Call
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InsertGroupMember", reflect.TypeOf((*MockStore)(nil).InsertGroupMember), arg0, arg1)
|
||||
}
|
||||
|
||||
// InsertIntelCohort mocks base method.
|
||||
func (m *MockStore) InsertIntelCohort(arg0 context.Context, arg1 database.InsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
// UpsertIntelCohort mocks base method.
|
||||
func (m *MockStore) UpsertIntelCohort(arg0 context.Context, arg1 database.UpsertIntelCohortParams) (database.IntelCohort, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "InsertIntelCohort", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "UpsertIntelCohort", arg0, arg1)
|
||||
ret0, _ := ret[0].(database.IntelCohort)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// InsertIntelCohort indicates an expected call of InsertIntelCohort.
|
||||
func (mr *MockStoreMockRecorder) InsertIntelCohort(arg0, arg1 any) *gomock.Call {
|
||||
// UpsertIntelCohort indicates an expected call of UpsertIntelCohort.
|
||||
func (mr *MockStoreMockRecorder) UpsertIntelCohort(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InsertIntelCohort", reflect.TypeOf((*MockStore)(nil).InsertIntelCohort), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsertIntelCohort", reflect.TypeOf((*MockStore)(nil).UpsertIntelCohort), arg0, arg1)
|
||||
}
|
||||
|
||||
// InsertIntelInvocations mocks base method.
|
||||
|
|
|
@ -487,6 +487,7 @@ CREATE TABLE intel_cohorts (
|
|||
created_at timestamp with time zone NOT NULL,
|
||||
updated_at timestamp with time zone NOT NULL,
|
||||
display_name text NOT NULL,
|
||||
icon character varying(256) DEFAULT ''::character varying NOT NULL,
|
||||
description text NOT NULL,
|
||||
filter_regex_operating_system character varying(255) DEFAULT '.*'::character varying NOT NULL,
|
||||
filter_regex_operating_system_version character varying(255) DEFAULT '.*'::character varying NOT NULL,
|
||||
|
|
|
@ -5,6 +5,7 @@ CREATE TABLE intel_cohorts (
|
|||
created_at TIMESTAMPTZ NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL,
|
||||
display_name TEXT NOT NULL,
|
||||
icon character varying(256) DEFAULT ''::character varying NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
|
||||
filter_regex_operating_system VARCHAR(255) NOT NULL DEFAULT '.*',
|
||||
|
|
|
@ -1853,6 +1853,7 @@ type IntelCohort struct {
|
|||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
Description string `db:"description" json:"description"`
|
||||
FilterRegexOperatingSystem string `db:"filter_regex_operating_system" json:"filter_regex_operating_system"`
|
||||
FilterRegexOperatingSystemVersion string `db:"filter_regex_operating_system_version" json:"filter_regex_operating_system_version"`
|
||||
|
|
|
@ -58,6 +58,7 @@ type sqlcQuerier interface {
|
|||
DeleteGitSSHKey(ctx context.Context, userID uuid.UUID) error
|
||||
DeleteGroupByID(ctx context.Context, id uuid.UUID) error
|
||||
DeleteGroupMemberFromGroup(ctx context.Context, arg DeleteGroupMemberFromGroupParams) error
|
||||
DeleteIntelCohortsByIDs(ctx context.Context, dollar_1 []uuid.UUID) error
|
||||
DeleteLicense(ctx context.Context, id int32) (int32, error)
|
||||
DeleteOAuth2ProviderAppByID(ctx context.Context, id uuid.UUID) error
|
||||
DeleteOAuth2ProviderAppCodeByID(ctx context.Context, id uuid.UUID) error
|
||||
|
@ -127,6 +128,7 @@ type sqlcQuerier interface {
|
|||
GetGroupsByOrganizationID(ctx context.Context, organizationID uuid.UUID) ([]Group, error)
|
||||
GetHealthSettings(ctx context.Context) (string, error)
|
||||
GetHungProvisionerJobs(ctx context.Context, updatedAt time.Time) ([]ProvisionerJob, error)
|
||||
GetIntelCohortsByOrganizationID(ctx context.Context, organizationID uuid.UUID) ([]IntelCohort, error)
|
||||
// Obtains a list of cohorts that a user can track invocations for.
|
||||
GetIntelCohortsMatchedByMachineIDs(ctx context.Context, ids []uuid.UUID) ([]GetIntelCohortsMatchedByMachineIDsRow, error)
|
||||
GetJFrogXrayScanByWorkspaceAndAgentID(ctx context.Context, arg GetJFrogXrayScanByWorkspaceAndAgentIDParams) (JfrogXrayScan, error)
|
||||
|
@ -309,7 +311,6 @@ type sqlcQuerier interface {
|
|||
InsertGitSSHKey(ctx context.Context, arg InsertGitSSHKeyParams) (GitSSHKey, error)
|
||||
InsertGroup(ctx context.Context, arg InsertGroupParams) (Group, error)
|
||||
InsertGroupMember(ctx context.Context, arg InsertGroupMemberParams) error
|
||||
InsertIntelCohort(ctx context.Context, arg InsertIntelCohortParams) (IntelCohort, error)
|
||||
// Insert many invocations using unnest
|
||||
InsertIntelInvocations(ctx context.Context, arg InsertIntelInvocationsParams) error
|
||||
InsertLicense(ctx context.Context, arg InsertLicenseParams) (License, error)
|
||||
|
@ -423,6 +424,7 @@ type sqlcQuerier interface {
|
|||
// The functional values are immutable and controlled implicitly.
|
||||
UpsertDefaultProxy(ctx context.Context, arg UpsertDefaultProxyParams) error
|
||||
UpsertHealthSettings(ctx context.Context, value string) error
|
||||
UpsertIntelCohort(ctx context.Context, arg UpsertIntelCohortParams) (IntelCohort, error)
|
||||
UpsertIntelMachine(ctx context.Context, arg UpsertIntelMachineParams) (IntelMachine, error)
|
||||
UpsertJFrogXrayScanByWorkspaceAndAgentID(ctx context.Context, arg UpsertJFrogXrayScanByWorkspaceAndAgentIDParams) error
|
||||
UpsertLastUpdateCheck(ctx context.Context, value string) error
|
||||
|
|
|
@ -2916,6 +2916,57 @@ func (q *sqlQuerier) UpsertTemplateUsageStats(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
const deleteIntelCohortsByIDs = `-- name: DeleteIntelCohortsByIDs :exec
|
||||
DELETE FROM intel_cohorts WHERE id = ANY($1::uuid[])
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) DeleteIntelCohortsByIDs(ctx context.Context, dollar_1 []uuid.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteIntelCohortsByIDs, pq.Array(dollar_1))
|
||||
return err
|
||||
}
|
||||
|
||||
const getIntelCohortsByOrganizationID = `-- name: GetIntelCohortsByOrganizationID :many
|
||||
SELECT id, organization_id, created_by, created_at, updated_at, display_name, icon, description, filter_regex_operating_system, filter_regex_operating_system_version, filter_regex_architecture, filter_regex_git_remote_url, filter_regex_instance_id, tracked_executables FROM intel_cohorts WHERE organization_id = $1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetIntelCohortsByOrganizationID(ctx context.Context, organizationID uuid.UUID) ([]IntelCohort, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getIntelCohortsByOrganizationID, organizationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []IntelCohort
|
||||
for rows.Next() {
|
||||
var i IntelCohort
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OrganizationID,
|
||||
&i.CreatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
&i.Description,
|
||||
&i.FilterRegexOperatingSystem,
|
||||
&i.FilterRegexOperatingSystemVersion,
|
||||
&i.FilterRegexArchitecture,
|
||||
&i.FilterRegexGitRemoteUrl,
|
||||
&i.FilterRegexInstanceID,
|
||||
pq.Array(&i.TrackedExecutables),
|
||||
); 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 getIntelCohortsMatchedByMachineIDs = `-- name: GetIntelCohortsMatchedByMachineIDs :many
|
||||
WITH machines AS (
|
||||
SELECT id, created_at, updated_at, instance_id, organization_id, user_id, ip_address, hostname, operating_system, operating_system_version, cpu_cores, memory_mb_total, architecture, daemon_version, git_config_email, git_config_name FROM intel_machines WHERE id = ANY($1::uuid [])
|
||||
|
@ -2984,60 +3035,6 @@ func (q *sqlQuerier) GetIntelCohortsMatchedByMachineIDs(ctx context.Context, ids
|
|||
return items, nil
|
||||
}
|
||||
|
||||
const insertIntelCohort = `-- name: InsertIntelCohort :one
|
||||
INSERT INTO intel_cohorts (id, organization_id, created_by, created_at, updated_at, display_name, description, filter_regex_operating_system, filter_regex_operating_system_version, filter_regex_architecture, filter_regex_instance_id, tracked_executables)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING id, organization_id, created_by, created_at, updated_at, display_name, description, filter_regex_operating_system, filter_regex_operating_system_version, filter_regex_architecture, filter_regex_git_remote_url, filter_regex_instance_id, tracked_executables
|
||||
`
|
||||
|
||||
type InsertIntelCohortParams struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
CreatedBy uuid.UUID `db:"created_by" json:"created_by"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
FilterRegexOperatingSystem string `db:"filter_regex_operating_system" json:"filter_regex_operating_system"`
|
||||
FilterRegexOperatingSystemVersion string `db:"filter_regex_operating_system_version" json:"filter_regex_operating_system_version"`
|
||||
FilterRegexArchitecture string `db:"filter_regex_architecture" json:"filter_regex_architecture"`
|
||||
FilterRegexInstanceID string `db:"filter_regex_instance_id" json:"filter_regex_instance_id"`
|
||||
TrackedExecutables []string `db:"tracked_executables" json:"tracked_executables"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertIntelCohort(ctx context.Context, arg InsertIntelCohortParams) (IntelCohort, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertIntelCohort,
|
||||
arg.ID,
|
||||
arg.OrganizationID,
|
||||
arg.CreatedBy,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
arg.DisplayName,
|
||||
arg.Description,
|
||||
arg.FilterRegexOperatingSystem,
|
||||
arg.FilterRegexOperatingSystemVersion,
|
||||
arg.FilterRegexArchitecture,
|
||||
arg.FilterRegexInstanceID,
|
||||
pq.Array(arg.TrackedExecutables),
|
||||
)
|
||||
var i IntelCohort
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrganizationID,
|
||||
&i.CreatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DisplayName,
|
||||
&i.Description,
|
||||
&i.FilterRegexOperatingSystem,
|
||||
&i.FilterRegexOperatingSystemVersion,
|
||||
&i.FilterRegexArchitecture,
|
||||
&i.FilterRegexGitRemoteUrl,
|
||||
&i.FilterRegexInstanceID,
|
||||
pq.Array(&i.TrackedExecutables),
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertIntelInvocations = `-- name: InsertIntelInvocations :exec
|
||||
INSERT INTO intel_invocations (
|
||||
created_at, machine_id, user_id, id, binary_hash, binary_path, binary_args,
|
||||
|
@ -3093,6 +3090,74 @@ func (q *sqlQuerier) InsertIntelInvocations(ctx context.Context, arg InsertIntel
|
|||
return err
|
||||
}
|
||||
|
||||
const upsertIntelCohort = `-- name: UpsertIntelCohort :one
|
||||
INSERT INTO intel_cohorts (id, organization_id, created_by, created_at, updated_at, display_name, icon, description, filter_regex_operating_system, filter_regex_operating_system_version, filter_regex_architecture, filter_regex_instance_id, tracked_executables)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
updated_at = $5,
|
||||
display_name = $6,
|
||||
icon = $7,
|
||||
description = $8,
|
||||
filter_regex_operating_system = $9,
|
||||
filter_regex_operating_system_version = $10,
|
||||
filter_regex_architecture = $11,
|
||||
filter_regex_instance_id = $12,
|
||||
tracked_executables = $13
|
||||
RETURNING id, organization_id, created_by, created_at, updated_at, display_name, icon, description, filter_regex_operating_system, filter_regex_operating_system_version, filter_regex_architecture, filter_regex_git_remote_url, filter_regex_instance_id, tracked_executables
|
||||
`
|
||||
|
||||
type UpsertIntelCohortParams struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
CreatedBy uuid.UUID `db:"created_by" json:"created_by"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
Description string `db:"description" json:"description"`
|
||||
FilterRegexOperatingSystem string `db:"filter_regex_operating_system" json:"filter_regex_operating_system"`
|
||||
FilterRegexOperatingSystemVersion string `db:"filter_regex_operating_system_version" json:"filter_regex_operating_system_version"`
|
||||
FilterRegexArchitecture string `db:"filter_regex_architecture" json:"filter_regex_architecture"`
|
||||
FilterRegexInstanceID string `db:"filter_regex_instance_id" json:"filter_regex_instance_id"`
|
||||
TrackedExecutables []string `db:"tracked_executables" json:"tracked_executables"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) UpsertIntelCohort(ctx context.Context, arg UpsertIntelCohortParams) (IntelCohort, error) {
|
||||
row := q.db.QueryRowContext(ctx, upsertIntelCohort,
|
||||
arg.ID,
|
||||
arg.OrganizationID,
|
||||
arg.CreatedBy,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
arg.DisplayName,
|
||||
arg.Icon,
|
||||
arg.Description,
|
||||
arg.FilterRegexOperatingSystem,
|
||||
arg.FilterRegexOperatingSystemVersion,
|
||||
arg.FilterRegexArchitecture,
|
||||
arg.FilterRegexInstanceID,
|
||||
pq.Array(arg.TrackedExecutables),
|
||||
)
|
||||
var i IntelCohort
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrganizationID,
|
||||
&i.CreatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DisplayName,
|
||||
&i.Icon,
|
||||
&i.Description,
|
||||
&i.FilterRegexOperatingSystem,
|
||||
&i.FilterRegexOperatingSystemVersion,
|
||||
&i.FilterRegexArchitecture,
|
||||
&i.FilterRegexGitRemoteUrl,
|
||||
&i.FilterRegexInstanceID,
|
||||
pq.Array(&i.TrackedExecutables),
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const upsertIntelMachine = `-- name: UpsertIntelMachine :one
|
||||
INSERT INTO intel_machines (id, created_at, updated_at, instance_id, organization_id, user_id, ip_address, hostname, operating_system, operating_system_version, cpu_cores, memory_mb_total, architecture, daemon_version)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
-- name: InsertIntelCohort :one
|
||||
INSERT INTO intel_cohorts (id, organization_id, created_by, created_at, updated_at, display_name, description, filter_regex_operating_system, filter_regex_operating_system_version, filter_regex_architecture, filter_regex_instance_id, tracked_executables)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
|
||||
-- name: UpsertIntelCohort :one
|
||||
INSERT INTO intel_cohorts (id, organization_id, created_by, created_at, updated_at, display_name, icon, description, filter_regex_operating_system, filter_regex_operating_system_version, filter_regex_architecture, filter_regex_instance_id, tracked_executables)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
updated_at = $5,
|
||||
display_name = $6,
|
||||
icon = $7,
|
||||
description = $8,
|
||||
filter_regex_operating_system = $9,
|
||||
filter_regex_operating_system_version = $10,
|
||||
filter_regex_architecture = $11,
|
||||
filter_regex_instance_id = $12,
|
||||
tracked_executables = $13
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetIntelCohortsByOrganizationID :many
|
||||
SELECT * FROM intel_cohorts WHERE organization_id = $1;
|
||||
|
||||
-- name: DeleteIntelCohortsByIDs :exec
|
||||
DELETE FROM intel_cohorts WHERE id = ANY($1::uuid[]);
|
||||
|
||||
-- name: UpsertIntelMachine :one
|
||||
INSERT INTO intel_machines (id, created_at, updated_at, instance_id, organization_id, user_id, ip_address, hostname, operating_system, operating_system_version, cpu_cores, memory_mb_total, architecture, daemon_version)
|
||||
|
@ -63,3 +80,15 @@ WHERE
|
|||
operating_system_version_match AND
|
||||
architecture_match AND
|
||||
instance_id_match;
|
||||
|
||||
-- name: GetConsistencyByIntelCohort :many
|
||||
SELECT
|
||||
binary_path,
|
||||
binary_args,
|
||||
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY duration_ms) AS median_duration
|
||||
FROM
|
||||
intel_invocations
|
||||
GROUP BY
|
||||
binary_path, binary_args
|
||||
ORDER BY
|
||||
median_duration DESC;
|
||||
|
|
Loading…
Reference in New Issue