Skip to content

Commit 2b906aa

Browse files
authored
feat(RAIN-95114): include new request params in query endpoints (#1774)
* feat(RAIN-95114): include new request params in query endpoints * style:refotmat * feat(RAIN-95114): add test case
1 parent 6460506 commit 2b906aa

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

api/lql.go

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,42 @@ import (
2828
"gopkg.in/yaml.v3"
2929
)
3030

31+
type providerType int
32+
type providerTypes map[providerType]string
33+
34+
const (
35+
Agent providerType = iota
36+
APA
37+
AWS
38+
Azure
39+
CIEM
40+
GCP
41+
K8s
42+
OCI
43+
)
44+
45+
var ValidProviderTypes = providerTypes{
46+
Agent: "Agent",
47+
APA: "APA",
48+
AWS: "AWS",
49+
Azure: "Azure",
50+
CIEM: "CIEM",
51+
GCP: "GCP",
52+
K8s: "K8s",
53+
OCI: "OCI",
54+
}
55+
56+
type UsageContext struct {
57+
Providers []string `json:"providers,omitempty" yaml:"providers,omitempty"`
58+
Policies []string `json:"policies,omitempty" yaml:"policies,omitempty"`
59+
}
60+
3161
type NewQuery struct {
32-
QueryID string `json:"queryId" yaml:"queryId"`
33-
QueryText string `json:"queryText" yaml:"queryText"`
62+
QueryID string `json:"queryId" yaml:"queryId"`
63+
QueryText string `json:"queryText" yaml:"queryText"`
64+
QueryName string `json:"queryName,omitempty" yaml:"queryName,omitempty"`
65+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
66+
UsageContext UsageContext `json:"usageContext,omitempty" yaml:"usageContext,omitempty"`
3467
}
3568

3669
func ParseNewQuery(s string) (NewQuery, error) {
@@ -54,7 +87,10 @@ func ParseNewQuery(s string) (NewQuery, error) {
5487
}
5588

5689
type UpdateQuery struct {
57-
QueryText string `json:"queryText"`
90+
QueryText string `json:"queryText"`
91+
QueryName string `json:"queryName,omitempty" yaml:"queryName,omitempty"`
92+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
93+
UsageContext UsageContext `json:"usageContext,omitempty" yaml:"usageContext,omitempty"`
5894
}
5995

6096
type Query struct {
@@ -64,6 +100,11 @@ type Query struct {
64100
LastUpdateTime string `json:"lastUpdateTime"`
65101
LastUpdateUser string `json:"lastUpdateUser"`
66102
ResultSchema []map[string]interface{} `json:"resultSchema"`
103+
QueryName string `json:"queryName,omitempty" yaml:"queryName,omitempty"`
104+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
105+
UsageContext UsageContext `json:"usageContext,omitempty" yaml:"usageContext,omitempty"`
106+
Providers []string `json:"providers,omitempty" yaml:"providers,omitempty"`
107+
UsedByPolicies []string `json:"usedByPolicies,omitempty" yaml:"usedByPolicies,omitempty"`
67108
}
68109

69110
type QueryResponse struct {

api/lql_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
var (
3535
queryID = "my_lql"
3636
newQueryText = `my_lql { source { CloudTrailRawEvents } return { INSERT_ID } }`
37+
queryName = "Lql Query Name"
38+
description = "Lql Query Description"
3739
newQuery = api.NewQuery{
3840
QueryID: queryID,
3941
QueryText: newQueryText,
@@ -45,6 +47,18 @@ var (
4547
newQueryYAML = fmt.Sprintf(`---
4648
queryId: %s
4749
queryText: %s`, newQuery.QueryID, newQuery.QueryText)
50+
newQueryWithNameDescriptionJSON = fmt.Sprintf(`{
51+
"queryId": "%s",
52+
"queryText": "%s",
53+
"queryName": "%s",
54+
"description": "%s"
55+
}`, queryID, newQueryText, queryName, description)
56+
newQueryWithNameDescription = api.NewQuery{
57+
QueryID: queryID,
58+
QueryText: newQueryText,
59+
QueryName: queryName,
60+
Description: description,
61+
}
4862
lqlErrorReponse = `{ "message": "This is an error message" }`
4963
)
5064

@@ -92,6 +106,12 @@ var parseNewQueryTests = []parseNewQueryTest{
92106
Expected: newQuery,
93107
Error: nil,
94108
},
109+
parseNewQueryTest{
110+
Name: "name-description-blobl",
111+
Input: newQueryWithNameDescriptionJSON,
112+
Expected: newQueryWithNameDescription,
113+
Error: nil,
114+
},
95115
}
96116

97117
func TestParseNewQuery(t *testing.T) {

cli/cmd/lql_update.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ func updateQuery(cmd *cobra.Command, args []string) error {
8989
}
9090

9191
queryYaml, err := yaml.Marshal(&api.NewQuery{
92-
QueryID: queryRes.Data.QueryID,
93-
QueryText: queryRes.Data.QueryText,
92+
QueryID: queryRes.Data.QueryID,
93+
QueryText: queryRes.Data.QueryText,
94+
QueryName: queryRes.Data.QueryName,
95+
Description: queryRes.Data.Description,
9496
})
9597
if err != nil {
9698
return errors.Wrap(err, msg)
@@ -133,7 +135,9 @@ func updateQuery(cmd *cobra.Command, args []string) error {
133135
cli.Log.Debugw("updating query", "query", queryString)
134136
cli.StartProgress(" Updating query...")
135137
update, err := cli.LwApi.V2.Query.Update(newQuery.QueryID, api.UpdateQuery{
136-
QueryText: newQuery.QueryText,
138+
QueryText: newQuery.QueryText,
139+
QueryName: newQuery.QueryName,
140+
Description: newQuery.Description,
137141
})
138142
cli.StopProgress()
139143

0 commit comments

Comments
 (0)