Skip to content

Commit

Permalink
Deprecate baseline binding microsoft#1215 (microsoft#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Sep 1, 2024
1 parent baa2892 commit a811466
Show file tree
Hide file tree
Showing 32 changed files with 186 additions and 649 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ What's changed since pre-release v3.0.0-B0203:
- The `Execution.Break` option can be set to `Never`, `OnError`, `OnWarning`, or `OnInformation`.
- If a rule fails with a severity level equal or higher than the configured level the pipeline will break.
- General improvements:
- **Breaking change**: Improve scope handling for correctly handling cases with multiple module by @BernieWhite.
- As a result of this change the `binding` property can no longer be used within baselines.
- Use module configuration or workspace options instead.
- Added support for native logging within emitters by @BernieWhite.
[#1837](https://github.com/microsoft/PSRule/issues/1837)
- Engineering:
Expand Down
78 changes: 0 additions & 78 deletions docs/concepts/PSRule/en-US/about_PSRule_Baseline.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ A baseline includes a set of rule and configuration options that are used for ev

The following baseline options can be configured:

- [Binding.Field](about_PSRule_Options.md#bindingfield)
- [Binding.IgnoreCase](about_PSRule_Options.md#bindingignorecase)
- [Binding.NameSeparator](about_PSRule_Options.md#bindingnameseparator)
- [Binding.PreferTargetInfo](about_PSRule_Options.md#bindingprefertargetinfo)
- [Binding.TargetName](about_PSRule_Options.md#bindingtargetname)
- [Binding.TargetType](about_PSRule_Options.md#bindingtargettype)
- [Binding.UseQualifiedName](about_PSRule_Options.md#bindingusequalifiedname)
- [Configuration](about_PSRule_Options.md#configuration)
- [Rule.Include](about_PSRule_Options.md#ruleinclude)
- [Rule.IncludeLocal](about_PSRule_Options.md#ruleincludelocal)
Expand Down Expand Up @@ -55,7 +48,6 @@ metadata:
annotations: { }
spec:
# One or more baseline options
binding: { }
rule: { }
configuration: { }
```
Expand All @@ -70,16 +62,6 @@ kind: Baseline
metadata:
name: Baseline1
spec:
binding:
field:
id:
- ResourceId
targetName:
- Name
- ResourceName
- ResourceGroupName
targetType:
- ResourceType
rule:
include:
- Rule1
Expand All @@ -96,13 +78,6 @@ kind: Baseline
metadata:
name: Baseline2
spec:
binding:
targetName:
- Name
- ResourceName
- ResourceGroupName
targetType:
- ResourceType
rule:
include:
- Rule1
Expand All @@ -125,7 +100,6 @@ To define a JSON baseline spec use the following structure:
"annotations": {}
},
"spec": {
"binding": {},
"rule": {},
"configuration": {}
}
Expand All @@ -145,21 +119,6 @@ For example:
"name": "Baseline1"
},
"spec": {
"binding": {
"field": {
"id": [
"ResourceId"
]
},
"targetName": [
"Name",
"ResourceName",
"ResourceGroupName"
],
"targetType": [
"ResourceType"
]
},
"rule": {
"include": [
"Rule1",
Expand All @@ -182,16 +141,6 @@ For example:
"name": "Baseline2"
},
"spec": {
"binding": {
"targetName": [
"Name",
"ResourceName",
"ResourceGroupName"
],
"targetType": [
"ResourceType"
]
},
"rule": {
"include": [
"Rule1",
Expand Down Expand Up @@ -276,11 +225,6 @@ kind: Baseline
metadata:
name: TestBaseline1
spec:
binding:
targetName:
- AlternateName
targetType:
- kind
rule:
include:
- 'WithBaseline'
Expand All @@ -294,11 +238,6 @@ kind: Baseline
metadata:
name: TestBaseline2
spec:
binding:
targetName:
- AlternateName
targetType:
- kind
rule:
include:
- 'WithBaseline'
Expand All @@ -320,14 +259,6 @@ spec:
"name": "TestBaseline1"
},
"spec": {
"binding": {
"targetName": [
"AlternateName"
],
"targetType": [
"kind"
]
},
"rule": {
"include": [
"WithBaseline"
Expand All @@ -346,14 +277,6 @@ spec:
"name": "TestBaseline2"
},
"spec": {
"binding": {
"targetName": [
"AlternateName"
],
"targetType": [
"kind"
]
},
"rule": {
"include": [
"WithBaseline"
Expand All @@ -376,4 +299,3 @@ An online version of this document is available at https://microsoft.github.io/P
- Options
- PSRule
- Baseline
- Binding
14 changes: 7 additions & 7 deletions docs/concepts/PSRule/en-US/about_PSRule_Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ This topic describes what options are available, when to and how to use them.
The following workspace options are available for use:

- [Baseline.Group](#baselinegroup)
- [Binding.Field](#bindingfield)
- [Binding.IgnoreCase](#bindingignorecase)
- [Binding.NameSeparator](#bindingnameseparator)
- [Binding.PreferTargetInfo](#bindingprefertargetinfo)
- [Binding.TargetName](#bindingtargetname)
- [Binding.TargetType](#bindingtargettype)
- [Binding.UseQualifiedName](#bindingusequalifiedname)
- [Convention.Include](#conventioninclude)
- [Execution.AliasReference](#executionaliasreference)
- [Execution.Break](#executionbreak)
Expand Down Expand Up @@ -60,13 +67,6 @@ The following workspace options are available for use:

Additionally the following baseline options can be included:

- [Binding.Field](#bindingfield)
- [Binding.IgnoreCase](#bindingignorecase)
- [Binding.NameSeparator](#bindingnameseparator)
- [Binding.PreferTargetInfo](#bindingprefertargetinfo)
- [Binding.TargetName](#bindingtargetname)
- [Binding.TargetType](#bindingtargettype)
- [Binding.UseQualifiedName](#bindingusequalifiedname)
- [Configuration](#configuration)
- [Rule.Baseline](#rulebaseline)
- [Rule.Include](#ruleinclude)
Expand Down
11 changes: 11 additions & 0 deletions docs/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ From _v3_ these properties will be removed.
These changes do not affect normal usage of PSRule.
Supporting scripts that directly use the old names may not work correctly until you update these names.

### Binding configuration in baselines

Prior to v3, a baseline could configure a binding configuration to modify how objects are recognized by name, type, and scope.
This existed to support scenarios before a module configuration and language scopes where core to how PSRule operates.

- Rules within a module will automatically use binding configuration from the module configuration.
If no binding configuration is set, the configuration of the workspace will be used.
- Rules within the workspace will automatically use the binding configuration from options (`ps-rule.yaml`).

Configuring binding configuration on a baseline is removed from PSRule v3.

## Deprecations for v2

### Default baseline by module manifest
Expand Down
10 changes: 0 additions & 10 deletions docs/scenarios/baselines/Baseline.rule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ kind: Baseline
metadata:
name: TestBaseline1
spec:
binding:
targetName:
- AlternateName
targetType:
- kind
rule:
include:
- 'WithBaseline'
Expand All @@ -24,11 +19,6 @@ kind: Baseline
metadata:
name: TestBaseline2
spec:
binding:
targetName:
- AlternateName
targetType:
- kind
rule:
include:
- 'WithBaseline'
Expand Down
3 changes: 0 additions & 3 deletions schemas/PSRule-language.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@
"description": "A specification for a baseline.",
"markdownDescription": "A specification for a baseline. [See help](https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Baseline/)",
"properties": {
"binding": {
"$ref": "#/definitions/binding-option"
},
"configuration": {
"$ref": "#/definitions/configuration"
},
Expand Down
17 changes: 0 additions & 17 deletions src/PSRule.Types/Options/BaselineOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@

namespace PSRule.Options;

/// <summary>
/// Options that configure baselines.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options"/>.
/// </remarks>
public interface IBaselineOption : IOption
{
/// <summary>
/// A mapping of baseline group names to baselines.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#baselinegroup"/>.
/// </remarks>
StringArrayMap? Group { get; }
}

/// <summary>
/// Options that configure baselines.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions src/PSRule.Types/Options/IBaselineOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using PSRule.Data;

namespace PSRule.Options;

/// <summary>
/// Options that configure baselines.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options"/>.
/// </remarks>
public interface IBaselineOption : IOption
{
/// <summary>
/// A mapping of baseline group names to baselines.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/ps-rule/options#baselinegroup"/>.
/// </remarks>
StringArrayMap? Group { get; }
}
1 change: 0 additions & 1 deletion src/PSRule/Common/BaselineJsonSerializationMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private static void MapBaselineSpec(JsonWriter writer, JsonSerializer serializer

MapPropertyName(writer, propertyName);
writer.WriteStartObject();
MapProperty(writer, serializer, nameof(baselineSpec.Binding), baselineSpec.Binding);
MapProperty(writer, serializer, nameof(baselineSpec.Configuration), baselineSpec.Configuration);
MapProperty(writer, nameof(baselineSpec.Convention), baselineSpec.Convention);
MapProperty(writer, serializer, nameof(baselineSpec.Rule), baselineSpec.Rule);
Expand Down
1 change: 0 additions & 1 deletion src/PSRule/Common/BaselineYamlSerializationMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ private static void MapBaselineSpec(IEmitter emitter, string propertyName, Basel

MapPropertyName(emitter, propertyName);
emitter.Emit(new MappingStart());
MapProperty(emitter, nameof(baselineSpec.Binding), baselineSpec.Binding);
MapProperty(emitter, nameof(baselineSpec.Configuration), baselineSpec.Configuration);
MapProperty(emitter, nameof(baselineSpec.Convention), baselineSpec.Convention);
MapProperty(emitter, nameof(baselineSpec.Rule), baselineSpec.Rule);
Expand Down
51 changes: 4 additions & 47 deletions src/PSRule/Configuration/BaselineOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ internal sealed class BaselineInline : BaselineOption, IBaselineV1Spec
{
public BaselineInline()
{
Binding = new BindingOption();
Configuration = new ConfigurationOption();
Rule = new RuleOption();
}

public BindingOption Binding { get; set; }

public ConfigurationOption Configuration { get; set; }

public ConventionOption Convention { get; set; }
Expand Down Expand Up @@ -87,28 +84,11 @@ public static BaselineOption FromString(string value)
return string.IsNullOrEmpty(value) ? null : new BaselineRef(value);
}

/// <summary>
/// Load from environment variables.
/// </summary>
internal static void Load(IBaselineV1Spec option)
{
// Binding.Field - currently not supported

if (Environment.TryBool("PSRULE_BINDING_IGNORECASE", out var ignoreCase))
option.Binding.IgnoreCase = ignoreCase;

if (Environment.TryString("PSRULE_BINDING_NAMESEPARATOR", out var nameSeparator))
option.Binding.NameSeparator = nameSeparator;

if (Environment.TryBool("PSRULE_BINDING_PREFERTARGETINFO", out var preferTargetInfo))
option.Binding.PreferTargetInfo = preferTargetInfo;

if (Environment.TryStringArray("PSRULE_BINDING_TARGETNAME", out var targetName))
option.Binding.TargetName = targetName;

if (Environment.TryStringArray("PSRULE_BINDING_TARGETTYPE", out var targetType))
option.Binding.TargetType = targetType;

if (Environment.TryBool("PSRULE_BINDING_USEQUALIFIEDNAME", out var useQualifiedName))
option.Binding.UseQualifiedName = useQualifiedName;

if (Environment.TryString("PSRULE_RULE_BASELINE", out var baseline))
option.Rule.Baseline = baseline;

Expand All @@ -128,33 +108,10 @@ internal static void Load(IBaselineV1Spec option)
}

/// <summary>
/// Load matching values
/// Load from a dictionary.
/// </summary>
/// <param name="option">A baseline options object to load.</param>
/// <param name="properties">One or more indexed properties.</param>
internal static void Load(IBaselineV1Spec option, Dictionary<string, object> properties)
{
if (properties.TryPopValue("Binding.Field", out Hashtable map))
option.Binding.Field = new FieldMap(map);

if (properties.TryPopBool("Binding.IgnoreCase", out var ignoreCase))
option.Binding.IgnoreCase = ignoreCase;

if (properties.TryPopString("Binding.NameSeparator", out var nameSeparator))
option.Binding.NameSeparator = nameSeparator;

if (properties.TryPopBool("Binding.PreferTargetInfo", out var preferTargetInfo))
option.Binding.PreferTargetInfo = preferTargetInfo;

if (properties.TryPopStringArray("Binding.TargetName", out var targetName))
option.Binding.TargetName = targetName;

if (properties.TryPopStringArray("Binding.TargetType", out var targetType))
option.Binding.TargetType = targetType;

if (properties.TryPopValue("Binding.UseQualifiedName", out bool useQualifiedName))
option.Binding.UseQualifiedName = useQualifiedName;

if (properties.TryPopString("Rule.Baseline", out var baseline))
option.Rule.Baseline = baseline;

Expand Down
Loading

0 comments on commit a811466

Please sign in to comment.