Skip to content

Commit

Permalink
Add query job tests
Browse files Browse the repository at this point in the history
  • Loading branch information
myoung34 committed May 22, 2023
1 parent ba8108c commit 86cc9bc
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 27 deletions.
59 changes: 59 additions & 0 deletions uptycs/fixtures/query_job.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"links": [
{
"rel": "self",
"title": "Query job information",
"href": "/api/customers/fda3f46b-c262-439c-bc93-5de6ee6993b6/queryJobs/b6885999-3bb0-4d8e-84b3-46883f4d7506"
},
{
"rel": "parent",
"title": "Query jobs information",
"href": "/api/customers/fda3f46b-c262-439c-bc93-5de6ee6993b6/queryJobs"
}
],
"id": "b6885999-3bb0-4d8e-84b3-46883f4d7506",
"customerId": "fda3f46b-c262-439c-bc93-5de6ee6993b6",
"type": "global",
"name": "b86c2befb58987cb5d4f14210784c9df",
"query": "test",
"parameters": [
{
"key": "from",
"dataType": "DATE",
"multiple": false,
"optional": false,
"defaultValue": "2023-05-22T17:22:36.323Z"
},
{
"key": "to",
"dataType": "DATE",
"multiple": false,
"optional": false,
"defaultValue": "2023-05-22T19:27:08.322Z"
}
],
"parameterValues": {
"to": "2023-05-22T19:27:08.322Z",
"from": "2023-05-22T17:22:36.323Z"
},
"filters": null,
"queryId": "4934a4b8-0625-452f-b5ec-0d6be1da2d85",
"status": "QUEUED",
"rowCount": 0,
"startTime": null,
"endTime": null,
"error": null,
"purged": false,
"incompleteResults": false,
"alertId": null,
"createdBy": "f48f4c40-9c4a-47bb-9e3f-797d4deca92a",
"updatedBy": null,
"createdAt": "2023-05-22T19:27:08.334Z",
"updatedAt": "2023-05-22T19:27:08.334Z",
"source": "SCHEDULED",
"resultStore": null,
"agentType": "asset",
"resourceType": "asset",
"queryStats": null,
"sessionProperties": null
}
65 changes: 38 additions & 27 deletions uptycs/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,42 @@ type QueryJobParameter struct {
DefaultValue string `json:"defaultValue"`
}

type QueryJobs struct {
Links []LinkItem `json:"links"`
Items []QueryJob `json:"items"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}

type QueryJob struct {
ID string `json:"id"`
Name string `json:"name"`
Query string `json:"query" validate:"required"`
Type string `json:"type" validate:"required,oneof=global"`
Parameters []QueryJobParameter `json:"parameters"`
ParameterValues string `json:"parameterValues"`
QueryID string `json:"queryId"`
Status string `json:"status"`
RowCount int `json:"rowCount"`
Columns []QueryJobColumn `json:"columns"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
Error QueryError `json:"error"`
Purged bool `json:"purged"`
IncompleteResults bool `json:"incompleteResults"`
AlertID string `json:"alertId"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
Source string `json:"source"`
ResultStore string `json:"resultStore"`
AgentType string `json:"agentType"`
ResourceType string `json:"resourceType"`
Links []LinkItem `json:"links"`
ID string `json:"id"`
Name string `json:"name"`
Query string `json:"query" validate:"required"`
Type string `json:"type" validate:"required,oneof=global"`
Parameters []QueryJobParameter `json:"parameters"`
ParameterValues struct {
From string `json:"from"`
To string `json:"to"`
} `json:"parameterValues"`
QueryID string `json:"queryId"`
Status string `json:"status"`
RowCount int `json:"rowCount"`
Columns []QueryJobColumn `json:"columns"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
Error QueryError `json:"error"`
Purged bool `json:"purged"`
IncompleteResults bool `json:"incompleteResults"`
AlertID string `json:"alertId"`
CreatedBy string `json:"createdBy"`
UpdatedBy string `json:"updatedBy"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
Source string `json:"source"`
ResultStore string `json:"resultStore"`
AgentType string `json:"agentType"`
ResourceType string `json:"resourceType"`
Links []LinkItem `json:"links"`
//SessionProperties interface{} `json:"sessionProperties"` # TODO: cant find any examples of this
//Filters interface{} `json:"filters"` # TODO: cant find any examples of this
//QueryStats interface{} `json:"queryStats"` # TODO: cant find any examples of this
Expand All @@ -67,6 +77,7 @@ type QueryJobResultColumn struct {
OriginalName string `json:"originalName"`
Link string `json:"link"`
}

type QueryJobResultsStats struct {
CPUTimeMillis int `json:"cpuTimeMillis"`
ProcessedRows int `json:"processedRows"`
Expand Down Expand Up @@ -1238,12 +1249,12 @@ type AssetTag struct {
}

type iAPIType interface {
AlertRule | Destination | EventExcludeProfile | EventRule | User | Role | ObjectGroup | TagConfiguration | TagRule | Tag | FilePathGroup | YaraGroupRule | RegistryPath | Querypack | AuditConfiguration | ComplianceProfile | AlertRuleCategory | AssetGroupRule | AtcQuery | Carve | CustomProfile | FlagProfile | BlockRule | WindowsDefenderPreference | Exception | AssetTag | Asset | LookupTable
AlertRule | Destination | EventExcludeProfile | EventRule | User | Role | ObjectGroup | TagConfiguration | TagRule | Tag | FilePathGroup | YaraGroupRule | RegistryPath | Querypack | AuditConfiguration | ComplianceProfile | AlertRuleCategory | AssetGroupRule | AtcQuery | Carve | CustomProfile | FlagProfile | BlockRule | WindowsDefenderPreference | Exception | AssetTag | Asset | LookupTable | QueryJob | QueryJobResult
GetID() string
GetName() string
KeysToDelete() []string
}

type iAPITypes interface {
AlertRules | Destinations | EventExcludeProfiles | EventRules | Users | Roles | ObjectGroups | TagConfigurations | TagRules | Tags | FilePathGroups | YaraGroupRules | RegistryPaths | Querypacks | AuditConfigurations | ComplianceProfiles | AlertRuleCategories | AssetGroupRules | AtcQueries | Carves | CustomProfiles | FlagProfiles | BlockRules | WindowsDefenderPreferences | Exceptions | AssetTags | Assets | LookupTables
AlertRules | Destinations | EventExcludeProfiles | EventRules | Users | Roles | ObjectGroups | TagConfigurations | TagRules | Tags | FilePathGroups | YaraGroupRules | RegistryPaths | Querypacks | AuditConfigurations | ComplianceProfiles | AlertRuleCategories | AssetGroupRules | AtcQueries | Carves | CustomProfiles | FlagProfiles | BlockRules | WindowsDefenderPreferences | Exceptions | AssetTags | Assets | LookupTables | QueryJobResults | QueryJobs
}
47 changes: 47 additions & 0 deletions uptycs/query_job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package uptycs

import "errors"

func (T QueryJob) GetID() string {
return T.ID
}

func (T QueryJob) GetName() string {
return T.Name
}

func (T QueryJob) KeysToDelete() []string {
return []string{
"enabled",
}
}

func (c *Client) CreateQueryJob(queryJob QueryJob) (QueryJob, error) {
return doCreate(c, queryJob, "queryJobs", []string{})
}

func (c *Client) UpdateQueryJob(queryJob QueryJob) (QueryJob, error) {
return QueryJob{}, errors.New("UPDATE is not supported for query jobs")
}

func (c *Client) GetQueryJobs() (QueryJobs, error) {
return doGetMany(c, QueryJobs{}, "queryTables")
}

func (c *Client) GetQueryJob(queryJob QueryJob) (QueryJob, error) {
if len(queryJob.ID) == 0 {
all, _ := c.GetQueryJobs()
for _, _item := range all.Items {
if _item.Name == queryJob.Name {
return _item, nil
}
}
} else {
return doGet(c, queryJob, "queryJobs")
}
return queryJob, errors.New("queryJob was not found")
}

func (c *Client) DeleteQueryJob(queryJob QueryJob) (QueryJob, error) {
return doDelete(c, queryJob, "queryJobs")
}
Loading

0 comments on commit 86cc9bc

Please sign in to comment.