Skip to content

Commit

Permalink
Change rule properties to align with docs #164 #165 (#166)
Browse files Browse the repository at this point in the history
- Change rule properties to align with docs #164
- Changed Hint keyword to Recommend to align with rule documentation #165
- Added rule documentation
  • Loading branch information
BernieWhite authored Jun 6, 2019
1 parent 18ee54c commit 3b5bc3a
Show file tree
Hide file tree
Showing 50 changed files with 635 additions and 272 deletions.
25 changes: 16 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@

## Unreleased

- **Important change**: Changed `Hint` keyword to `Recommend` to align with rule documentation. [#165](https://github.com/BernieWhite/PSRule/issues/165)
- Use of `Hint` keyword is deprecated and will be removed in a future release. Currently `Hint` is aliased to `Recommend` for compatibility.
- **Breaking change**: Changed rule properties to align with rule documentation. [#164](https://github.com/BernieWhite/PSRule/issues/164)
- Rule `Synopsis`, is a brief summary of the rule and `Description` is a detailed purpose of the rule.
- `Description:` metadata keyword used in comment help is now `Synopsis:`, use of `Description:` will set synopsis. Description metadata keyword is deprecated and will be removed in a future update.
- Output property `Message` on rule results is now `Recommendation`.

## v0.6.0-B190614 (pre-release)

- Added rule documentation, which allows additional rule information to be stored in markdown files. [#157](https://github.com/BernieWhite/PSRule/issues/157)
- Rule documentation also adds culture support. [#18](https://github.com/BernieWhite/PSRule/issues/18)
- Rule documentation can be access like help with the `Get-PSRuleHelp` cmdlet.
- Rule documentation can be accessed like help with the `Get-PSRuleHelp` cmdlet.
- Added annotations, which are non-indexed metadata stored in rule documentation. [#148](https://github.com/BernieWhite/PSRule/issues/148)
- Annotations can contain a link to online version of the documentation. [#147](https://github.com/BernieWhite/PSRule/issues/147)

Expand Down Expand Up @@ -56,7 +63,7 @@ What's changed since v0.3.0:
- `-Format` is automatically detected for `.yaml`, `.yml` and `.json` file extensions.
- Added `-OutputFormat` parameter to serialize output from `Invoke-PSRule` as YAML or JSON. [#29](https://github.com/BernieWhite/PSRule/issues/29)
- Added support for logging pass or fail outcomes to a data stream such as Error, Warning or Information. [#97](https://github.com/BernieWhite/PSRule/issues/97)
- **Breaking change** - Deprecated usage of the `-TargetName` parameter on the `Hint` keyword has been removed. [#81](https://github.com/BernieWhite/PSRule/issues/81)
- **Breaking change**: Deprecated usage of the `-TargetName` parameter on the `Hint` keyword has been removed. [#81](https://github.com/BernieWhite/PSRule/issues/81)

What's changed since pre-release v0.4.0-B190328:

Expand All @@ -79,7 +86,7 @@ What's changed since pre-release v0.4.0-B190328:
- `-Format` is automatically detected for `.yaml`, `.yml` and `.json` file extensions.
- Added `-OutputFormat` parameter to serialize output from `Invoke-PSRule`. [#29](https://github.com/BernieWhite/PSRule/issues/29)
- Added support for logging pass or fail outcomes to a data stream such as Error, Warning or Information. [#97](https://github.com/BernieWhite/PSRule/issues/97)
- **Breaking change** - Deprecated usage of the `-TargetName` parameter on the `Hint` keyword has been removed. [#81](https://github.com/BernieWhite/PSRule/issues/81)
- **Breaking change**: Deprecated usage of the `-TargetName` parameter on the `Hint` keyword has been removed. [#81](https://github.com/BernieWhite/PSRule/issues/81)

## v0.3.0

Expand All @@ -99,15 +106,15 @@ What's changed since v0.2.0:
- Support TargetName binding of nested properties [#71](https://github.com/BernieWhite/PSRule/issues/71)
- Added online help links to keywords [#72](https://github.com/BernieWhite/PSRule/issues/72)
- Added schema for PSRule options [#74](https://github.com/BernieWhite/PSRule/issues/74)
- **Breaking change** - Changed parameter alias for `-Path` from `-f` to `-p` [#99](https://github.com/BernieWhite/PSRule/issues/99)
- **Breaking change** - The `-TargetName` parameter of the `Hint` keyword has been deprecated [#81](https://github.com/BernieWhite/PSRule/issues/81)
- **Important change**: The `-TargetName` parameter of the `Hint` keyword has been deprecated [#81](https://github.com/BernieWhite/PSRule/issues/81)
- `-TargetName` parameter not longer sets the pipeline object _TargetName_ and generates a warning instead.
- The `-TargetName` will be completely removed in **v0.4.0**, at which time using the parameter will generate an error.
- **Breaking change**: Changed parameter alias for `-Path` from `-f` to `-p` [#99](https://github.com/BernieWhite/PSRule/issues/99)

What's changed since pre-release v0.3.0-B190231:

- Added support for input de-serialization from FileInfo objects [#95](https://github.com/BernieWhite/PSRule/issues/95)
- **Breaking change** - Changed parameter alias for `-Path` from `-f` to `-p` [#99](https://github.com/BernieWhite/PSRule/issues/99)
- **Breaking change**: Changed parameter alias for `-Path` from `-f` to `-p` [#99](https://github.com/BernieWhite/PSRule/issues/99)

## v0.3.0-B190231 (pre-release)

Expand All @@ -122,7 +129,7 @@ What's changed since pre-release v0.3.0-B190231:
- Added object type binding and dynamic filtering for rules [#82](https://github.com/BernieWhite/PSRule/issues/82)
- Added support for case-sensitive binding operations [#87](https://github.com/BernieWhite/PSRule/issues/87)
- Binding ignores case by default. Set option `Binding.CaseSensitive` to `true` to enable case-sensitivity.
- **Breaking change** - The `-TargetName` parameter of the `Hint` keyword has been deprecated [#81](https://github.com/BernieWhite/PSRule/issues/81)
- **Important change**: The `-TargetName` parameter of the `Hint` keyword has been deprecated [#81](https://github.com/BernieWhite/PSRule/issues/81)
- `-TargetName` parameter not longer sets the pipeline object _TargetName_ and generates a warning instead.
- The `-TargetName` will be completely removed in **v0.4.0**, at which time using the parameter will generate an error.

Expand Down Expand Up @@ -167,7 +174,7 @@ What's changed since pre-release v0.2.0-B190121:

- Fix Get-PSRule generates exception when no .rule.ps1 scripts exist in path [#53](https://github.com/BernieWhite/PSRule/issues/53)
- Fix LocalizedData.PathNotFound warning when no .rule.ps1 scripts exist in path [#54](https://github.com/BernieWhite/PSRule/issues/54)
- **Breaking change** - Renamed `Test-PSRule` cmdlet to `Test-PSRuleTarget` which aligns more closely to the verb-noun naming standard [#57](https://github.com/BernieWhite/PSRule/issues/57)
- **Breaking change**: Renamed `Test-PSRule` cmdlet to `Test-PSRuleTarget` which aligns more closely to the verb-noun naming standard [#57](https://github.com/BernieWhite/PSRule/issues/57)

## v0.2.0-B190105 (pre-release)

Expand Down Expand Up @@ -197,7 +204,7 @@ What's changed since pre-release v0.1.0-B181235:
- Rules with the same name can exist and be cross linked with DependsOn, as long a the script file name is different
- Added `-Not` to `Exists` keyword
- Improved verbose logging of `Exists`, `AllOf`, `AnyOf` keywords and core engine
- **Breaking change** - Renamed outcome filtering parameters to align to type name and increase clarity
- **Breaking change**: Renamed outcome filtering parameters to align to type name and increase clarity
- `Invoke-PSRule` has a `-Outcome` parameter instead of `-Status`
- `-Outcome` supports values of `Pass`, `Fail`, `Error`, `None`, `Processed` and `All`

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ The following language keywords are used by the `PSRule` module:
- [AllOf](docs/keywords/PSRule/en-US/about_PSRule_Keywords.md#allof) - Assert that all of the child expressions must be true.
- [Within](docs/keywords/PSRule/en-US/about_PSRule_Keywords.md#within) - Assert that the field must match any of the values.
- [TypeOf](docs/keywords/PSRule/en-US/about_PSRule_Keywords.md#typeof) - Assert that the object must be of a specific type.
- [Recommend](docs/keywords/PSRule/en-US/about_PSRule_Keywords.md#recommend) - Return the process to resolve the issue and pass the rule.

### Commands

Expand All @@ -163,6 +164,10 @@ The following commands exist in the `PSRule` module:

The following conceptual topics exist in the `PSRule` module:

- [Docs](docs/concepts/PSRule/en-US/about_PSRule_Docs.md)
- [Getting documentation](docs/concepts/PSRule/en-US/about_PSRule_Docs.md#getting-documentation)
- [Online help](docs/concepts/PSRule/en-US/about_PSRule_Docs.md#online-help)
- [Creating documentation](docs/concepts/PSRule/en-US/about_PSRule_Docs.md#creating-documentation)
- [Options](docs/concepts/PSRule/en-US/about_PSRule_Options.md)
- [Baseline.RuleName](docs/concepts/PSRule/en-US/about_PSRule_Options.md#baselinerulename)
- [Baseline.Exclude](docs/concepts/PSRule/en-US/about_PSRule_Options.md#baselineexclude)
Expand Down
4 changes: 4 additions & 0 deletions docs/commands/PSRule/en-US/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
href: Test-PSRuleTarget.md
topicHref: Test-PSRuleTarget.md

- name: Documentation
href: ../../../concepts/PSRule/en-US/about_PSRule_Docs.md
topicHref: ../../../concepts/PSRule/en-US/about_PSRule_Docs.md

- name: Keywords
href: ../../../keywords/PSRule/en-US/about_PSRule_Keywords.md
topicHref: ../../../keywords/PSRule/en-US/about_PSRule_Keywords.md
Expand Down
112 changes: 112 additions & 0 deletions docs/concepts/PSRule/en-US/about_PSRule_Docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# PSRule_Docs

## about_PSRule_Docs

## SHORT DESCRIPTION

Describes usage of documentation within PSRule.

## LONG DESCRIPTION

PSRule includes a built-in documentation system that provide culture specific help and metadata for rules.

Rule documentation is composed of markdown files that can be optionally shipped with a module.

### Getting documentation

To get documentation for a rule use the `Get-PSRuleHelp` cmdlet.

For example:

```powershell
Get-PSRuleHelp <rule-name>
```

Each rule can include the following documentation:

- Annotations - Additional metadata included in results.
- Synopsis - A brief description on the intended purpose of the rule.
- Description - A detailed description on the intended purpose of the rule.
- Recommendation - A detailed explanation of the requirements to pass the rule.
- Note - Any additional information or background.

See cmdlet help for detailed information on the `Get-PSRuleHelp` cmdlet.

### Online help

Rule documentation may optionally include a link to an online version.
When included, the `-Online` parameter can be used to open the online version in the default web browser.

For example:

```powershell
Get-PSRuleHelp <rule-name> -Online
```

### Creating documentation

Rule documentation is composed of markdown files, one per rule. When creating rules for more then one culture, a separate markdown file is created per rule per culture.

The markdown files for each rule is automatically discovered based on naming convention.

Markdown is saved in a file with the same filename as the rule name with the `.md` extension. The file name should match the same case exactly, with a lower case extension.

As an example, the `storageAccounts.UseHttps.md` markdown file would be created.

```powershell
# Synopsis: Configure storage accounts to only accept encrypted traffic i.e. HTTPS/SMB
Rule 'storageAccounts.UseHttps' -If { ResourceType 'Microsoft.Storage/storageAccounts' } {
Hint 'Storage accounts should only allow secure traffic'
$TargetObject.Properties.supportsHttpsTrafficOnly
}
```

This directory PSRule will look for these markdown files depends on how the rules are packaged:

- If the rules are loose (not part of a module), PSRule will search for documentation in the `.\<culture>\` subdirectory relative to where the rule script _.ps1_ file is located.
- When the rules are shipped as part of a module, PSRule will search for documentation in the `.\<culture>\` subdirectory relative to where the module manifest _.psd1_ file is located.

The `<culture>` subdirectory will be the current culture that PowerShell is executed under (the same as `(Get-Culture).Name`). Alternatively, the culture can set by using the `-Culture` parameter of PSRule cmdlets.

The markdown of each file uses following structure.

```text
---
{{ Annotations }}
---
# {{ Name of rule }}
## SYNOPSIS
{{ A short description of the rule }}
## DESCRIPTION
{{ A detailed description of the rule }}
## RECOMMENDATION
{{ A detailed explanation of the steps required to pass the rule }}
## NOTES
{{ Additional information or background }}
```

Optionally, one or more annotations formatted as YAML key value pairs can be included. i.e. `severity: Critical`

## NOTE

An online version of this document is available at https://github.com/BernieWhite/PSRule/blob/master/docs/concepts/PSRule/en-US/about_PSRule_Docs.md.

## SEE ALSO

- [Get-PSRuleHelp](https://github.com/BernieWhite/PSRule/blob/master/docs/commands/PSRule/en-US/Get-PSRuleHelp.md)

## KEYWORDS

- Help
- Rule
56 changes: 43 additions & 13 deletions docs/keywords/PSRule/en-US/about_PSRule_Keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The following are the built-in keywords that can be used within PSRule:
- [AllOf](#allof) - Assert that all of the child expressions must be true
- [Within](#within) - Assert that the field must match any of the values
- [TypeOf](#typeof) - Assert that the object must be of a specific type
- [Recommend](#recommend) - Return the process to resolve the issue and pass the rule.

### Rule

Expand All @@ -47,21 +48,21 @@ Rule [-Name] <string> [-Tag <hashtable>] [-Type <string[]>] [-If <scriptBlock>]
Examples:

```powershell
# Description: This rule checks for the presence of a name field
# Synopsis: This rule checks for the presence of a name field
Rule 'NameMustExist' {
Exists 'Name'
}
```

```powershell
# Description: This rule checks that the title field is valid, when the rule NameMustExist is successful
# Synopsis: This rule checks that the title field is valid, when the rule NameMustExist is successful
Rule 'TitleIsValid' -DependsOn 'NameMustExist' {
Within 'Title' 'Mr', 'Miss', 'Mrs', 'Ms'
}
```

```powershell
# Description: This rule uses a threshold stored as $Configuration.minInstanceCount
# Synopsis: This rule uses a threshold stored as $Configuration.minInstanceCount
Rule 'HasMinInstances' {
$TargetObject.Sku.capacity -ge $Configuration.minInstanceCount
} -Configure @{ minInstanceCount = 2 }
Expand All @@ -85,21 +86,21 @@ Exists [-Field] <string[]> [-CaseSensitive] [-Not] [-InputObject <PSObject>]
Examples:

```powershell
# Description: Checks for the presence of a name property
# Synopsis: Checks for the presence of a name property
Rule 'nameMustExist' {
Exists 'Name'
}
```

```powershell
# Description: Checks for the presence of name nested under the metadata property
# Synopsis: Checks for the presence of name nested under the metadata property
Rule 'nameMustExist' {
Exists 'metadata.name'
}
```

```powershell
# Description: Checks for the presence of name nested under the metadata property
# Synopsis: Checks for the presence of name nested under the metadata property
Rule 'nameMustExist' {
$TargetObject.metadata | Exists 'name'
}
Expand Down Expand Up @@ -129,7 +130,7 @@ Match [-Field] <string> [-Expression] <string[]> [-CaseSensitive] [-InputObject
Examples:

```powershell
# Description: Check that PhoneNumber is complete and formatted correctly
# Synopsis: Check that PhoneNumber is complete and formatted correctly
Rule 'validatePhoneNumber' {
Match 'PhoneNumber' '^(\+61|0)([0-9] {0,1}){8}[0-9]$'
}
Expand Down Expand Up @@ -157,7 +158,7 @@ Within [-Field] <string> [-AllowedValue] <PSObject[]]> [-CaseSensitive] [-InputO
Examples:

```powershell
# Description: Ensure that the title field has one of the allowed values
# Synopsis: Ensure that the title field has one of the allowed values
Rule 'validateTitle' {
Within 'Title' 'Mr', 'Miss', 'Mrs', 'Ms'
}
Expand Down Expand Up @@ -186,7 +187,7 @@ AllOf [-Body] {
Examples:

```powershell
# Description: The Name field must exist and have a value of either John or Jane
# Synopsis: The Name field must exist and have a value of either John or Jane
Rule 'nameCheck' {
AllOf {
Exists 'Name'
Expand Down Expand Up @@ -218,7 +219,7 @@ AnyOf [-Body] {
Examples:

```powershell
# Description: The Last or Surname field must exist
# Synopsis: The Last or Surname field must exist
Rule 'personCheck' {
AnyOf {
Exists 'Last'
Expand Down Expand Up @@ -247,7 +248,7 @@ TypeOf [-TypeName] <string[]> [-InputObject <PSObject>]
Examples:

```powershell
# Description: The object must be a hashtable
# Synopsis: The object must be a hashtable
Rule 'objectType' {
TypeOf 'System.Collections.Hashtable'
}
Expand All @@ -257,12 +258,40 @@ Output:

If **any** the specified type names match the pipeline object then TypeOf will return `$True`, otherwise `$False`.

### Recommend

The `Recommend` keyword is used within a `Rule` definition to provide a process to resolve the issue and pass the rule. This may include manual steps to change that state of the object or the desired state accessed by the rule.

Previously this keyword was `Hint`. The previous keyword `Hint` is aliased by deprecated.

Syntax:

```text
Recommend [-Message] <string>
```

- `Message` - A message that includes the process to resolve the issue and pass the rule.

Examples:

```powershell
# Synopsis: Provide recommendation to resolve the issue
Rule 'objectRecommend' {
Recommend 'Use at least two (2) instances'
$TargetObject.count -ge 2
}
```

Output:

None.

## EXAMPLES

```powershell
# Description: App Service Plan has multiple instances
# Synopsis: App Service Plan has multiple instances
Rule 'appServicePlan.MinInstanceCount' -If { $TargetObject.ResourceType -eq 'Microsoft.Web/serverfarms' } {
Hint 'Use at least two (2) instances'
Recommend 'Use at least two (2) instances'
$TargetObject.Sku.capacity -ge 2
}
Expand All @@ -285,5 +314,6 @@ An online version of this document is available at https://github.com/BernieWhit
- AllOf
- Within
- TypeOf
- Recommend

[Invoke-PSRule]: https://github.com/BernieWhite/PSRule/blob/master/docs/commands/PSRule/en-US/Invoke-PSRule.md
Loading

0 comments on commit 3b5bc3a

Please sign in to comment.