Skip to content

Commit 444fcf8

Browse files
committed
feat: Enhance documentation for Azure resource property helpers
1 parent c2aaa74 commit 444fcf8

File tree

1 file changed

+63
-9
lines changed

1 file changed

+63
-9
lines changed

ql/lib/codeql/bicep/frameworks/Microsoft/General.qll

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
1+
/**
2+
* General resource property helpers for Azure resources in Bicep.
3+
*
4+
* Provides common property accessors for location, SKU, and tags.
5+
*
6+
* Classes:
7+
* - AzureResource: Abstract base for Azure resources, provides access to location, SKU, and tags.
8+
* - ResourceProperties: Abstract base for resource property objects.
9+
* - Sku: Represents the SKU of a resource, with access to name and tier.
10+
* - Tags: Represents the tags of a resource, with access to tag values by key.
11+
*/
112
private import bicep
213

14+
/**
15+
* Abstract base class for Azure resources in Bicep.
16+
* Provides accessors for common resource properties such as location, SKU, and tags.
17+
*/
318
abstract class AzureResource extends Resource {
4-
string resourceLocation() {
5-
result = this.getProperty("location").(StringLiteral).getValue()
6-
}
19+
/**
20+
* Gets the location of the resource as a string value.
21+
* @return The Azure region/location of the resource (e.g., "eastus").
22+
*/
23+
string resourceLocation() { result = this.getProperty("location").(StringLiteral).getValue() }
724

25+
/**
26+
* Gets the SKU object for the resource.
27+
* @return The SKU object representing the resource's SKU.
28+
*/
829
Sku getSku() { result = this.getProperty("sku") }
930

31+
/**
32+
* Gets the Tags object for the resource.
33+
* @return The Tags object representing the resource's tags.
34+
*/
1035
Tags getTags() { result = this.getProperty("tags") }
1136
}
1237

38+
/**
39+
* Abstract base class for resource property objects.
40+
* Can be extended to provide additional property accessors for specific resource types.
41+
*/
1342
abstract class ResourceProperties extends Object {
14-
string toString() {
15-
result = super.toString()
16-
}
43+
/**
44+
* Returns a string representation of the resource properties object.
45+
*/
46+
string toString() { result = super.toString() }
1747
}
1848

49+
/**
50+
* Represents the SKU of an Azure resource.
51+
* Provides access to the SKU name and tier.
52+
*/
1953
class Sku extends Object {
2054
private Resource resource;
2155

@@ -24,19 +58,37 @@ class Sku extends Object {
2458
*/
2559
Sku() { this = resource.getProperty("sku") }
2660

61+
/**
62+
* Gets the SKU name as a StringLiteral.
63+
* @return The SKU name property as a StringLiteral.
64+
*/
65+
StringLiteral getName() { result = this.getProperty("name") }
66+
2767
/**
2868
* Returns the SKU name (e.g., Basic, Standard, Premium).
69+
* @return The SKU name as a string.
70+
*/
71+
string name() { result = this.getName().getValue() }
72+
73+
/**
74+
* Gets the SKU tier as a StringLiteral.
75+
* @return The SKU tier property as a StringLiteral.
2976
*/
30-
string getName() { result = this.getProperty("name").(StringLiteral).getValue() }
77+
StringLiteral getTier() { result = this.getProperty("tier") }
3178

3279
/**
3380
* Returns the SKU tier (e.g., Basic, Standard, Premium).
81+
* @return The SKU tier as a string.
3482
*/
35-
string getTier() { result = this.getProperty("tier").(StringLiteral).getValue() }
83+
string tier() { result = this.getTier().getValue() }
3684

3785
string toString() { result = "SKU" }
3886
}
3987

88+
/**
89+
* Represents the tags of an Azure resource.
90+
* Provides access to tag values by key.
91+
*/
4092
class Tags extends Object {
4193
private Resource resource;
4294

@@ -46,7 +98,9 @@ class Tags extends Object {
4698
Tags() { this = resource.getProperty("tags") }
4799

48100
/**
49-
* Returns the value of a tag by its key.
101+
* Gets the value of a tag by its key.
102+
* @param key The tag key to look up.
103+
* @return The value of the tag as a Literals object, or undefined if not present.
50104
*/
51105
Literals getTag(string key) { result = this.getProperty(key) }
52106

0 commit comments

Comments
 (0)