-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResources.qll
More file actions
118 lines (95 loc) · 3.06 KB
/
Resources.qll
File metadata and controls
118 lines (95 loc) · 3.06 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
private import AstNodes
private import codeql.Locations
private import Expr
private import Idents
private import Literals
private import internal.ResourceDeclaration
private import internal.ObjectProperty
private import internal.Object
/**
* A Object unknown AST node.
*/
class Object extends Expr instanceof ObjectImpl {
ObjectProperty getProperties() { result = ObjectImpl.super.getProperties() }
ObjectProperty getProp(int i) { result = ObjectImpl.super.getProperty(i) }
Expr getProperty(string name) {
exists(ObjectProperty property |
property = this.getProperties() and
property.getName().getName() = name
|
result = property.getValue()
)
}
}
/**
* A ObjectProperty unknown AST node.
*/
class ObjectProperty extends Expr instanceof ObjectPropertyImpl {
Idents getName() { result = ObjectPropertyImpl.super.getName() }
Expr getValue() { result = ObjectPropertyImpl.super.getValue() }
}
/**
* A ResourceDeclaration unknown AST node.
*/
class ResourceDeclaration extends AstNode instanceof ResourceDeclarationImpl {
/**
* The name of the resource instance
*/
Idents getIdentifier() { result = ResourceDeclarationImpl.super.getIdentifier() }
/**
* The name of the resource instance.
*/
Literals getName() { result = ResourceDeclarationImpl.super.getName() }
/**
* The object that represents the resource.
*/
Object getBody() { result = ResourceDeclarationImpl.super.getObject() }
ObjectProperty getProperties() { result = this.getBody().getProperties() }
Expr getProperty(string name) { result = this.getBody().getProperty(name) }
}
Resource resolveResource(Expr expr) {
exists(ResourceDeclaration resource |
// Object having an id property needs to be resolved
// {resource.id}.id
exists(MemberExpr memexpr |
memexpr = expr.(Object).getProperty("id") and
memexpr.getNamespace().(Idents).getName() = resource.getIdentifier().getName()
|
result = TResourceDeclaration(resource)
)
or
exists(Identifier ident |
ident = expr and
ident.getName() = resource.getIdentifier().(Identifier).getName()
|
result = TResourceDeclaration(resource)
)
)
}
class Resource extends TResource {
private ResourceDeclaration resource;
Resource() { this = TResourceDeclaration(resource) }
string getResourceType() {
exists(StringLiteral sl | sl = resource.getName() | result = sl.getValue())
}
Identifier getIdentifier() {
result = resource.getIdentifier()
}
string getName() {
exists(StringLiteral name |
name = resource.getProperty("name") and
result = name.getValue()
)
}
Expr getProperty(string name) { result = resource.getProperty(name) }
Resource getParent() { result = resolveResource(this.getProperty("parent")) }
string toString() { result = resource.toString() }
string getAPrimaryQlClass() { result = "Resource" }
Location getLocation() { result = resource.getLocation() }
}
cached
private module Cached {
cached
newtype TResource = TResourceDeclaration(ResourceDeclaration rd)
}
private import Cached