forked from cxpsemea/Cx1ClientGo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
audit_v310.go
106 lines (98 loc) · 2.95 KB
/
audit_v310.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
package Cx1ClientGo
import (
"fmt"
"strings"
)
/*
This is separate from queries.go to split the functions that require a Web-Audit Session from those that do not.
This file contains the query-related functions that require an audit session (compiling queries, updating queries, creating overrides)
*/
type AuditQuery_v310 struct {
QueryID uint64 `json:"Id,string"`
Level string
LevelID string `json:"-"`
Path string
Modified string
Source string
Name string
Group string
Language string `json:"lang"`
Severity string
Cwe int64
IsExecutable bool
CxDescriptionId int64
QueryDescriptionId string
Key string
Title string
}
func (q *AuditQuery_v310) ParsePath() {
s := strings.Split(q.Path, "/")
if len(s) >= 4 {
q.Language = s[1]
q.Group = s[2]
q.Name = s[3]
} else { // path was empty (since v3.14?) so create it
q.Path = fmt.Sprintf("queries/%v/%v/%v/%v.cs", q.Language, q.Group, q.Name, q.Name)
}
}
func (q Query) ToAuditQuery_v310() AuditQuery_v310 {
return AuditQuery_v310{
QueryID: q.QueryID,
Level: q.Level,
LevelID: q.LevelID,
Path: q.Path,
Modified: q.Modified,
Source: q.Source,
Name: q.Name,
Group: q.Group,
Language: q.Language,
Severity: q.Severity,
Cwe: q.CweID,
IsExecutable: q.IsExecutable,
CxDescriptionId: q.GetMetadata().CxDescriptionID,
QueryDescriptionId: "",
Key: q.EditorKey,
Title: q.Name,
}
}
func (q AuditQuery_v310) String() string {
return fmt.Sprintf("[%d] %v: %v", q.QueryID, q.Level, q.Path)
}
func (q AuditQuery_v310) ToQuery() Query {
return Query{
QueryID: q.QueryID,
Level: q.Level,
LevelID: q.LevelID,
Path: q.Path,
Modified: q.Modified,
Source: q.Source,
Name: q.Name,
Group: q.Group,
Language: q.Language,
Severity: q.Severity,
CweID: q.Cwe,
IsExecutable: q.IsExecutable,
QueryDescriptionId: q.CxDescriptionId,
Custom: q.Level != AUDIT_QUERY_PRODUCT,
EditorKey: q.Key,
SastID: 0,
}
}
func (q AuditQuery_v310) CreateTenantOverride() AuditQuery_v310 {
new_query := q
new_query.Level = AUDIT_QUERY_TENANT
new_query.LevelID = AUDIT_QUERY_TENANT
return new_query
}
func (q AuditQuery_v310) CreateProjectOverrideByID(projectId string) AuditQuery_v310 {
new_query := q
new_query.Level = AUDIT_QUERY_PROJECT
new_query.LevelID = projectId
return new_query
}
func (q AuditQuery_v310) CreateApplicationOverrideByID(applicationId string) AuditQuery_v310 {
new_query := q
new_query.Level = AUDIT_QUERY_APPLICATION
new_query.LevelID = applicationId
return new_query
}