Skip to content

Commit 60ead2d

Browse files
committed
feat(iac): Make Dependencies an abstract class and update tests
1 parent 65f4fcd commit 60ead2d

2 files changed

Lines changed: 39 additions & 21 deletions

File tree

ql/lib/codeql/iac/Dependencies.qll

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
1+
/**
2+
* Dependencies module for Infrastructure as Code languages.
3+
*/
14
private import codeql.Locations
25
private import codeql.hcl.Terraform
36

47
/**
58
* Dependency for all Infrastructure as Code languages.
69
*/
7-
class Dependency extends Location {
10+
abstract class Dependency extends Location {
11+
/**
12+
* Gets the name of the dependency.
13+
*/
14+
abstract string getName();
15+
/**
16+
* Gets the version of the dependency (in a format that is human-readable).
17+
*/
18+
abstract string getVersion();
19+
/**
20+
* Gets the raw version of the dependency (in a format that is machine-readable).
21+
*/
22+
abstract string getRawVersion();
23+
/**
24+
* Gets the semantic version of the dependency.
25+
*/
26+
abstract SemanticVersion getSemanticVersion();
27+
}
28+
29+
30+
/**
31+
* Dependency for Terraform.
32+
*/
33+
class TerraformDependency extends Dependency {
834
string name;
935
string version;
1036

11-
Dependency() {
37+
TerraformDependency() {
1238
// Terraform Provider
1339
exists(Terraform::Terraform tf, Terraform::RequiredProvider rp | rp = tf.getRequiredProvider() |
1440
this = rp.getLocation() and
@@ -19,25 +45,15 @@ class Dependency extends Location {
1945

2046
override string toString() { result = this.getName() + "@" + this.getVersion() }
2147

22-
/**
23-
* Gets the name of the dependency.
24-
*/
25-
string getName() { result = name }
48+
override string getName() { result = name }
2649

27-
/**
28-
* Gets the version of the dependency.
29-
*/
30-
string getVersion() { result = this.getSemanticVersion().getPretty() }
3150

32-
/**
33-
* Gets the raw version of the dependency.
34-
*/
35-
string getRawVersion() { result = version }
51+
override string getVersion() { result = this.getSemanticVersion().getPretty() }
3652

37-
/**
38-
* Gets the semantic version of the dependency.
39-
*/
40-
SemanticVersion getSemanticVersion() { result = version }
53+
54+
override string getRawVersion() { result = version }
55+
56+
override SemanticVersion getSemanticVersion() { result = version }
4157
}
4258

4359
class SemanticVersion extends string {
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
dependencies
22
| providers.tf:5:15:8:5 | hashicorp/azurerm@3.0.0 |
3-
| providers.tf:9:14:9:22 | hashicorp/time@~>0.7.2 |
4-
| providers.tf:10:14:10:22 | hashicorp/random@~>3.3.1 |
3+
| providers.tf:9:14:9:22 | hashicorp/time@0.7.2 |
4+
| providers.tf:10:14:10:22 | hashicorp/random@3.3.1 |
55
semver
6-
| 3.0.0 |
6+
| providers.tf:5:15:8:5 | hashicorp/azurerm@3.0.0 | =3.0.0 |
7+
| providers.tf:9:14:9:22 | hashicorp/time@0.7.2 | ~>0.7.2 |
8+
| providers.tf:10:14:10:22 | hashicorp/random@3.3.1 | ~>3.3.1 |

0 commit comments

Comments
 (0)