Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added version and hasDefault expression #861 #870 #869

Merged
merged 2 commits into from Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -324,6 +324,7 @@ The following conceptual topics exist in the `PSRule` module:
- [Field](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#field)
- [Greater](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#greater)
- [GreaterOrEquals](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#greaterorequals)
- [HasDefault](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#hasdefault)
- [HasSchema](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#hasschema)
- [HasValue](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#hasvalue)
- [In](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#in)
Expand All @@ -342,6 +343,7 @@ The following conceptual topics exist in the `PSRule` module:
- [StartsWith](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#startswith)
- [Subset](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#subset)
- [Type](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#type)
- [Version](docs/concepts/PSRule/en-US/about_PSRule_Expressions.md#version)
- [Options](docs/concepts/PSRule/en-US/about_PSRule_Options.md)
- [Binding.Field](docs/concepts/PSRule/en-US/about_PSRule_Options.md#bindingfield)
- [Binding.IgnoreCase](docs/concepts/PSRule/en-US/about_PSRule_Options.md#bindingignorecase)
Expand Down
12 changes: 12 additions & 0 deletions docs/CHANGELOG-v1.md
Expand Up @@ -11,6 +11,14 @@ See [upgrade notes][upgrade-notes] for helpful information when upgrading from p

## Unreleased

What's changed since v1.10.0:

- General improvements:
- Added `version` expression to check semantic version constraints. [#861](https://github.com/microsoft/PSRule/issues/861)
- See [about_PSRule_Expressions] for details.
- Added `hasDefault` expression to check field default value. [#870](https://github.com/microsoft/PSRule/issues/870)
- See [about_PSRule_Expressions] for details.

## v1.10.0

What's changed since v1.9.0:
Expand All @@ -19,6 +27,8 @@ What's changed since v1.9.0:
- Added JSON support for reading rules and selectors from pipeline. [#857](https://github.com/microsoft/PSRule/issues/857)
- Added `HasSchema` expression to check the schema of an object. [#860](https://github.com/microsoft/PSRule/issues/860)
- See [about_PSRule_Expressions] for details.
- Engineering:
- Bump Microsoft.SourceLink.GitHub to 1.1.1. [#856](https://github.com/microsoft/PSRule/pull/856)
- Bug fixes:
- Fixed `$Assert.HasJsonSchema` accepts empty value. [#859](https://github.com/microsoft/PSRule/issues/859)
- Fixed module configuration is not loaded when case does not match. [#864](https://github.com/microsoft/PSRule/issues/864)
Expand All @@ -42,6 +52,8 @@ What's changed since v1.9.0:
- Added JSON support for reading rules and selectors from pipeline. [#857](https://github.com/microsoft/PSRule/issues/857)
- Added `HasSchema` expression to check the schema of an object. [#860](https://github.com/microsoft/PSRule/issues/860)
- See [about_PSRule_Expressions] for details.
- Engineering:
- Bump Microsoft.SourceLink.GitHub to 1.1.1. [#856](https://github.com/microsoft/PSRule/pull/856)
- Bug fixes:
- Fixed `$Assert.HasJsonSchema` accepts empty value. [#859](https://github.com/microsoft/PSRule/issues/859)

Expand Down
91 changes: 91 additions & 0 deletions docs/concepts/PSRule/en-US/about_PSRule_Expressions.md
Expand Up @@ -20,6 +20,7 @@ The following conditions are available:
- [Exists](#exists)
- [Greater](#greater)
- [GreaterOrEquals](#greaterorequals)
- [HasDefault](#hasdefault)
- [HasSchema](#hasschema)
- [HasValue](#hasvalue)
- [In](#in)
Expand All @@ -35,6 +36,7 @@ The following conditions are available:
- [SetOf](#setof)
- [StartsWith](#startswith)
- [Subset](#subset)
- [Version](#version)

The following operators are available:

Expand Down Expand Up @@ -457,6 +459,47 @@ spec:
greaterOrEquals: 3
```

### HasDefault

The `hasDefault` condition determines if the field exists that it is set to the specified value.
If the field does not exist, the condition will return `true`.

The following properties are accepted:

- `caseSensitive` - Optionally, a case-sensitive comparison can be performed for string values.
By default, case-insensitive comparison is performed.

Syntax:

```yaml
hasDefault: <string | int | bool>
caseSensitive: <bool>
```

For example:

```yaml
---
apiVersion: github.com/microsoft/PSRule/v1
kind: Rule
metadata:
name: 'ExampleHasDefault'
spec:
condition:
field: 'enabled'
hasDefault: true

---
apiVersion: github.com/microsoft/PSRule/v1
kind: Selector
metadata:
name: 'ExampleHasDefault'
spec:
if:
field: 'enabled'
hasDefault: true
```

### HasSchema

The `hasSchema` condition determines if the operand has a `$schema` property defined.
Expand Down Expand Up @@ -1194,6 +1237,54 @@ spec:
- 'Microsoft.Storage/storageAccounts/blobServices'
```

### Version

The `version` condition determines if the operand is a valid semantic version.
A constraint can optionally be provided to require the semantic version to be within a range.
Supported version constraints for expression are the same as the `$Assert.Version` assertion helper.

Syntax:

```yaml
version: <string>
includePrerelease: <bool>
```

For example:

```yaml
---
apiVersion: github.com/microsoft/PSRule/v1
kind: Rule
metadata:
name: 'ExampleVersion'
spec:
condition:
field: 'engine.version'
version: '^1.2.3'

---
apiVersion: github.com/microsoft/PSRule/v1
kind: Selector
metadata:
name: 'ExampleAnyVersion'
spec:
if:
field: 'engine.version'
version: ''

---
apiVersion: github.com/microsoft/PSRule/v1
kind: Selector
metadata:
name: 'ExampleVersionIncludingPrerelease'
spec:
if:
field: 'engine.version'
version: '>=1.5.0'
includePrerelease: true
```

## NOTE

An online version of this document is available at https://microsoft.github.io/PSRule/concepts/PSRule/en-US/about_PSRule_Expressions.md.
Expand Down
61 changes: 35 additions & 26 deletions docs/concepts/PSRule/en-US/about_PSRule_Selectors.md
Expand Up @@ -17,35 +17,44 @@ When evaluating an object from input, PSRule can use selectors to perform comple
- Optionally a condition can be nested in an operator.
- Operators can be nested within other operators.

Conditions and operators available for use include:

- AllOf
- AnyOf
- Contains
- Equals
- EndsWith
- Exists
- Greater
- GreaterOrEquals
- HasValue
- In
- IsLower
- IsString
- IsUpper
- Less
- LessOrEquals
- Match
- Not
- NotEquals
- NotIn
- NotMatch
- StartsWith
The following conditions are available:

- [Contains](about_PSRule_Expressions.md#contains)
- [Count](about_PSRule_Expressions.md#count)
- [Equals](about_PSRule_Expressions.md#equals)
- [EndsWith](about_PSRule_Expressions.md#endswith)
- [Exists](about_PSRule_Expressions.md#exists)
- [Greater](about_PSRule_Expressions.md#greater)
- [GreaterOrEquals](about_PSRule_Expressions.md#greaterorequals)
- [HasDefault](about_PSRule_Expressions.md#hasdefault)
- [HasSchema](about_PSRule_Expressions.md#hasschema)
- [HasValue](about_PSRule_Expressions.md#hasvalue)
- [In](about_PSRule_Expressions.md#in)
- [IsLower](about_PSRule_Expressions.md#islower)
- [IsString](about_PSRule_Expressions.md#isstring)
- [IsUpper](about_PSRule_Expressions.md#isupper)
- [Less](about_PSRule_Expressions.md#less)
- [LessOrEquals](about_PSRule_Expressions.md#lessorequals)
- [Match](about_PSRule_Expressions.md#match)
- [NotEquals](about_PSRule_Expressions.md#notequals)
- [NotIn](about_PSRule_Expressions.md#notin)
- [NotMatch](about_PSRule_Expressions.md#notmatch)
- [SetOf](about_PSRule_Expressions.md#setof)
- [StartsWith](about_PSRule_Expressions.md#startswith)
- [Subset](about_PSRule_Expressions.md#subset)
- [Version](about_PSRule_Expressions.md#version)

The following operators are available:

- [AllOf](about_PSRule_Expressions.md#allof)
- [AnyOf](about_PSRule_Expressions.md#anyof)
- [Not](about_PSRule_Expressions.md#not)

The following comparison properties are available:

- Field
- Name
- Type
- [Field](about_PSRule_Expressions.md#field)
- [Name](about_PSRule_Expressions.md#name)
- [Type](about_PSRule_Expressions.md#type)

To learn more about conditions, operators, and properties see [about_PSRule_Expressions](about_PSRule_Expressions.md).

Expand Down