Skip to content

Commit 7f131c1

Browse files
authored
Python: Get rid of _attr predicates
1 parent 1008411 commit 7f131c1

File tree

1 file changed

+11
-41
lines changed

1 file changed

+11
-41
lines changed

python/ql/src/semmle/python/frameworks/Fabric.qll

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,16 @@ private module FabricV1 {
2323
/** Gets a reference to the `fabric` module. */
2424
API::Node fabric() { result = API::moduleImport("fabric") }
2525

26-
/**
27-
* Gets a reference to the attribute `attr_name` of the `fabric` module.
28-
* WARNING: Only holds for a few predefined attributes.
29-
*/
30-
private API::Node fabric_attr(string attr_name) { result = fabric().getMember(attr_name) }
31-
3226
/** Provides models for the `fabric` module. */
3327
module fabric {
3428
// -------------------------------------------------------------------------
3529
// fabric.api
3630
// -------------------------------------------------------------------------
3731
/** Gets a reference to the `fabric.api` module. */
38-
API::Node api() { result = fabric_attr("api") }
32+
API::Node api() { result = fabric().getMember("api") }
3933

4034
/** Provides models for the `fabric.api` module */
4135
module api {
42-
/**
43-
* Gets a reference to the attribute `attr_name` of the `fabric.api` module.
44-
* WARNING: Only holds for a few predefined attributes.
45-
*/
46-
private API::Node api_attr(string attr_name) { result = api().getMember(attr_name) }
47-
4836
/**
4937
* A call to either
5038
* - `fabric.api.local`
@@ -57,7 +45,7 @@ private module FabricV1 {
5745
*/
5846
private class FabricApiLocalRunSudoCall extends SystemCommandExecution::Range,
5947
DataFlow::CallCfgNode {
60-
FabricApiLocalRunSudoCall() { this = api_attr(["local", "run", "sudo"]).getACall() }
48+
FabricApiLocalRunSudoCall() { this = api().getMember(["local", "run", "sudo"]).getACall() }
6149

6250
override DataFlow::Node getCommand() {
6351
result.asCfgNode() = [node.getArg(0), node.getArgByName("command")]
@@ -77,30 +65,16 @@ private module FabricV2 {
7765
/** Gets a reference to the `fabric` module. */
7866
API::Node fabric() { result = API::moduleImport("fabric") }
7967

80-
/**
81-
* Gets a reference to the attribute `attr_name` of the `fabric` module.
82-
* WARNING: Only holds for a few predefined attributes.
83-
*/
84-
private API::Node fabric_attr(string attr_name) { result = fabric().getMember(attr_name) }
85-
8668
/** Provides models for the `fabric` module. */
8769
module fabric {
8870
// -------------------------------------------------------------------------
8971
// fabric.connection
9072
// -------------------------------------------------------------------------
9173
/** Gets a reference to the `fabric.connection` module. */
92-
API::Node connection() { result = fabric_attr("connection") }
74+
API::Node connection() { result = fabric().getMember("connection") }
9375

9476
/** Provides models for the `fabric.connection` module */
9577
module connection {
96-
/**
97-
* Gets a reference to the attribute `attr_name` of the `fabric.connection` module.
98-
* WARNING: Only holds for a few predefined attributes.
99-
*/
100-
private API::Node connection_attr(string attr_name) {
101-
result = connection().getMember(attr_name)
102-
}
103-
10478
/**
10579
* Provides models for the `fabric.connection.Connection` class
10680
*
@@ -109,7 +83,7 @@ private module FabricV2 {
10983
module Connection {
11084
/** Gets a reference to the `fabric.connection.Connection` class. */
11185
API::Node classRef() {
112-
result in [fabric_attr("Connection"), connection_attr("Connection")]
86+
result in [fabric().getMember("Connection"), connection().getMember("Connection")]
11387
}
11488

11589
/**
@@ -136,7 +110,7 @@ private module FabricV2 {
136110
}
137111

138112
/** Gets a reference to an instance of `fabric.connection.Connection`. */
139-
DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) }
113+
DataFlow::LocalSourceNode instance() { result = instance(DataFlow::TypeTracker::end()) }
140114

141115
/**
142116
* Gets a reference to either `run`, `sudo`, or `local` method on a
@@ -191,7 +165,7 @@ private module FabricV2 {
191165
// fabric.tasks
192166
// -------------------------------------------------------------------------
193167
/** Gets a reference to the `fabric.tasks` module. */
194-
API::Node tasks() { result = fabric_attr("tasks") }
168+
API::Node tasks() { result = fabric().getMember("tasks") }
195169

196170
/** Provides models for the `fabric.tasks` module */
197171
module tasks {
@@ -213,16 +187,10 @@ private module FabricV2 {
213187
// fabric.group
214188
// -------------------------------------------------------------------------
215189
/** Gets a reference to the `fabric.group` module. */
216-
API::Node group() { result = fabric_attr("group") }
190+
API::Node group() { result = fabric().getMember("group") }
217191

218192
/** Provides models for the `fabric.group` module */
219193
module group {
220-
/**
221-
* Gets a reference to the attribute `attr_name` of the `fabric.group` module.
222-
* WARNING: Only holds for a few predefined attributes.
223-
*/
224-
private API::Node group_attr(string attr_name) { result = group().getMember(attr_name) }
225-
226194
/**
227195
* Provides models for the `fabric.group.Group` class and its subclasses.
228196
*
@@ -280,7 +248,9 @@ private module FabricV2 {
280248
*/
281249
module SerialGroup {
282250
private class ClassInstantiation extends Group::ModeledSubclass {
283-
ClassInstantiation() { this in [group_attr("SerialGroup"), fabric_attr("SerialGroup")] }
251+
ClassInstantiation() {
252+
this in [group().getMember("SerialGroup"), fabric().getMember("SerialGroup")]
253+
}
284254
}
285255
}
286256

@@ -292,7 +262,7 @@ private module FabricV2 {
292262
module ThreadingGroup {
293263
private class ClassInstantiation extends Group::ModeledSubclass {
294264
ClassInstantiation() {
295-
this in [group_attr("ThreadingGroup"), fabric_attr("ThreadingGroup")]
265+
this in [group().getMember("ThreadingGroup"), fabric().getMember("ThreadingGroup")]
296266
}
297267
}
298268
}

0 commit comments

Comments
 (0)