Skip to content

Commit 6c4d421

Browse files
authored
Add support for target scope #1350 (#1351)
1 parent 1362719 commit 6c4d421

21 files changed

+467
-45
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ The following conceptual topics exist in the `PSRule` module:
270270
- [NotMatch](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#notmatch)
271271
- [NotStartsWith](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#notstartswith)
272272
- [NotWithinPath](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#notwithinpath)
273+
- [Scope](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#scope)
273274
- [SetOf](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#setof)
274275
- [Source](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#source)
275276
- [StartsWith](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#startswith)

docs/CHANGELOG-v2.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
3232

3333
What's changed since pre-release v2.7.0-B0001:
3434

35+
- General improvements:
36+
- Added support target scope by @BernieWhite.
37+
[#1350](https://github.com/microsoft/PSRule/issues/1350)
3538
- Bug fixes:
3639
- Fixed exception with comments in JSON baselines by @BernieWhite.
3740
[#1336](https://github.com/microsoft/PSRule/issues/1336)

docs/concepts/PSRule/en-US/about_PSRule_Expressions.md

+37
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The following comparison properties are available:
6666

6767
- [Field](#field)
6868
- [Name](#name)
69+
- [Scope](#scope)
6970
- [Source](#source)
7071
- [Type](#type)
7172

@@ -1682,6 +1683,42 @@ spec:
16821683
caseSensitive: true
16831684
```
16841685

1686+
### Scope
1687+
1688+
The comparison property `scope` is used with a condition to evaluate the scope of the object.
1689+
The `scope` property must be set to `.`.
1690+
Any other value will cause the condition to evaluate to `false`.
1691+
1692+
Syntax:
1693+
1694+
```yaml
1695+
scope: '.'
1696+
```
1697+
1698+
For example:
1699+
1700+
```yaml
1701+
---
1702+
apiVersion: github.com/microsoft/PSRule/v1
1703+
kind: Rule
1704+
metadata:
1705+
name: 'ExampleScope'
1706+
spec:
1707+
condition:
1708+
scope: '.'
1709+
startsWith: '/'
1710+
1711+
---
1712+
apiVersion: github.com/microsoft/PSRule/v1
1713+
kind: Selector
1714+
metadata:
1715+
name: 'ExampleScope'
1716+
spec:
1717+
if:
1718+
scope: '.'
1719+
startsWith: '/'
1720+
```
1721+
16851722
### SetOf
16861723

16871724
The `setOf` condition can be used to determine if the operand is a set of specified values.

docs/concepts/PSRule/en-US/about_PSRule_Variables.md

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ The following properties are available for read access:
172172
See option `Binding.Field` for more information.
173173
- `Input` - Allows adding additional input paths to the pipeline.
174174
- `Repository` - Provides access to information about the current repository.
175+
- `Scope` - The scope of the object currently being processed by the pipeline.
175176
- `Source` - A collection of sources for the object currently being processed on the pipeline.
176177
- `TargetObject` - The object currently being processed on the pipeline.
177178
- `TargetName` - The name of the object currently being processed on the pipeline.

schemas/PSRule-language.schema.json

+95-4
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@
478478
"if": {
479479
"type": "object",
480480
"title": "If",
481-
"description": "A condition is made up of one or more expressions that will determine if an object is selected by the selector.",
482-
"markdownDescription": "A condition is made up of one or more [expressions](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/) that will determine if an object is selected by the selector. [See help](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Selectors/)",
481+
"description": "A condition made up of one or more expressions that will determine if an object is selected by the selector.",
482+
"markdownDescription": "A condition made up of one or more [expressions](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/) that will determine if an object is selected by the selector. [See help](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Selectors/)",
483483
"$ref": "#/definitions/expressions"
484484
}
485485
},
@@ -551,6 +551,9 @@
551551
},
552552
"if": {
553553
"type": "object",
554+
"title": "If",
555+
"description": "A condition made up of one or more expressions that will determine if the rule is suppressed.",
556+
"markdownDescription": "A condition made up of one or more [expressions](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/) that will determine if the rule is suppressed. [See help](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_SuppressionGroups/)",
554557
"$ref": "#/definitions/expressions"
555558
}
556559
},
@@ -999,6 +1002,9 @@
9991002
},
10001003
{
10011004
"$ref": "#/definitions/expressions/definitions/operands/definitions/source"
1005+
},
1006+
{
1007+
"$ref": "#/definitions/expressions/definitions/operands/definitions/scope"
10021008
}
10031009
],
10041010
"definitions": {
@@ -1078,6 +1084,17 @@
10781084
"required": [
10791085
"source"
10801086
]
1087+
},
1088+
"scope": {
1089+
"type": "object",
1090+
"properties": {
1091+
"scope": {
1092+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
1093+
}
1094+
},
1095+
"required": [
1096+
"scope"
1097+
]
10811098
}
10821099
}
10831100
},
@@ -1151,6 +1168,16 @@
11511168
"description": "The source of the object currently being processed by the pipeline.",
11521169
"markdownDescription": "The source of the object currently being processed by the pipeline. [See help](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#source)",
11531170
"default": ""
1171+
},
1172+
"scope": {
1173+
"type": "string",
1174+
"title": "Scope",
1175+
"description": "The scope of the object currently being processed by the pipeline.",
1176+
"markdownDescription": "The scope of the object currently being processed by the pipeline. [See help](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Expressions/#scope)",
1177+
"default": ".",
1178+
"enum": [
1179+
"."
1180+
]
11541181
}
11551182
}
11561183
},
@@ -1315,6 +1342,9 @@
13151342
},
13161343
"source": {
13171344
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1345+
},
1346+
"scope": {
1347+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
13181348
}
13191349
},
13201350
"required": [
@@ -1407,6 +1437,9 @@
14071437
},
14081438
"source": {
14091439
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1440+
},
1441+
"scope": {
1442+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
14101443
}
14111444
},
14121445
"required": [
@@ -1465,6 +1498,9 @@
14651498
},
14661499
"source": {
14671500
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1501+
},
1502+
"scope": {
1503+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
14681504
}
14691505
},
14701506
"required": [
@@ -1500,6 +1536,9 @@
15001536
},
15011537
"source": {
15021538
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1539+
},
1540+
"scope": {
1541+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
15031542
}
15041543
},
15051544
"required": [
@@ -1538,6 +1577,9 @@
15381577
},
15391578
"source": {
15401579
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1580+
},
1581+
"scope": {
1582+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
15411583
}
15421584
},
15431585
"required": [
@@ -1576,6 +1618,9 @@
15761618
},
15771619
"source": {
15781620
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1621+
},
1622+
"scope": {
1623+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
15791624
}
15801625
},
15811626
"required": [
@@ -1751,6 +1796,9 @@
17511796
},
17521797
"source": {
17531798
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1799+
},
1800+
"scope": {
1801+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
17541802
}
17551803
},
17561804
"required": [
@@ -1802,6 +1850,9 @@
18021850
},
18031851
"source": {
18041852
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1853+
},
1854+
"scope": {
1855+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
18051856
}
18061857
},
18071858
"required": [
@@ -1853,6 +1904,9 @@
18531904
},
18541905
"source": {
18551906
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1907+
},
1908+
"scope": {
1909+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
18561910
}
18571911
},
18581912
"required": [
@@ -1904,6 +1958,9 @@
19041958
},
19051959
"source": {
19061960
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
1961+
},
1962+
"scope": {
1963+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
19071964
}
19081965
},
19091966
"required": [
@@ -1954,6 +2011,9 @@
19542011
},
19552012
"source": {
19562013
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
2014+
},
2015+
"scope": {
2016+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
19572017
}
19582018
},
19592019
"required": [
@@ -2003,6 +2063,9 @@
20032063
},
20042064
"source": {
20052065
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
2066+
},
2067+
"scope": {
2068+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
20062069
}
20072070
},
20082071
"required": [
@@ -2053,6 +2116,9 @@
20532116
},
20542117
"source": {
20552118
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
2119+
},
2120+
"scope": {
2121+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
20562122
}
20572123
},
20582124
"required": [
@@ -2102,6 +2168,9 @@
21022168
},
21032169
"source": {
21042170
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
2171+
},
2172+
"scope": {
2173+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
21052174
}
21062175
},
21072176
"required": [
@@ -2159,6 +2228,9 @@
21592228
},
21602229
"source": {
21612230
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
2231+
},
2232+
"scope": {
2233+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
21622234
}
21632235
},
21642236
"required": [
@@ -2209,6 +2281,9 @@
22092281
},
22102282
"source": {
22112283
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
2284+
},
2285+
"scope": {
2286+
"$ref": "#/definitions/expressions/definitions/properties/definitions/scope"
22122287
}
22132288
},
22142289
"required": [
@@ -2234,6 +2309,9 @@
22342309
"field": {
22352310
"$ref": "#/definitions/expressions/definitions/properties/definitions/field"
22362311
},
2312+
"name": {
2313+
"$ref": "#/definitions/expressions/definitions/properties/definitions/name"
2314+
},
22372315
"value": {
22382316
"$ref": "#/definitions/expressions/definitions/properties/definitions/value"
22392317
}
@@ -2246,7 +2324,8 @@
22462324
"$ref": "#/definitions/expressions/definitions/operands"
22472325
}
22482326
],
2249-
"additionalProperties": false
2327+
"additionalProperties": false,
2328+
"minProperties": 2
22502329
},
22512330
"isArray": {
22522331
"type": "object",
@@ -2425,6 +2504,9 @@
24252504
"field": {
24262505
"$ref": "#/definitions/expressions/definitions/properties/definitions/field"
24272506
},
2507+
"name": {
2508+
"$ref": "#/definitions/expressions/definitions/properties/definitions/name"
2509+
},
24282510
"value": {
24292511
"$ref": "#/definitions/expressions/definitions/properties/definitions/value"
24302512
}
@@ -2453,6 +2535,9 @@
24532535
"field": {
24542536
"$ref": "#/definitions/expressions/definitions/properties/definitions/field"
24552537
},
2538+
"name": {
2539+
"$ref": "#/definitions/expressions/definitions/properties/definitions/name"
2540+
},
24562541
"value": {
24572542
"$ref": "#/definitions/expressions/definitions/properties/definitions/value"
24582543
}
@@ -2618,6 +2703,9 @@
26182703
},
26192704
"value": {
26202705
"$ref": "#/definitions/expressions/definitions/properties/definitions/value"
2706+
},
2707+
"source": {
2708+
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
26212709
}
26222710
},
26232711
"required": [
@@ -2629,7 +2717,7 @@
26292717
}
26302718
],
26312719
"additionalProperties": false,
2632-
"maxProperties": 2
2720+
"minProperties": 2
26332721
},
26342722
"notWithinPath": {
26352723
"type": "object",
@@ -2657,6 +2745,9 @@
26572745
},
26582746
"value": {
26592747
"$ref": "#/definitions/expressions/definitions/properties/definitions/value"
2748+
},
2749+
"source": {
2750+
"$ref": "#/definitions/expressions/definitions/properties/definitions/source"
26602751
}
26612752
},
26622753
"required": [

0 commit comments

Comments
 (0)