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

Clean up #755 #648 #897

Merged
merged 3 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Change log

See [upgrade notes][upgrade-notes] for helpful information when upgrading from previous versions.
See [upgrade notes][1] for helpful information when upgrading from previous versions.

[upgrade-notes]: docs/upgrade-notes.md
[1]: https://microsoft.github.io/PSRule/latest/upgrade-notes/

## Next release

- v2 **Comming soon** - Please check out [upgrade notes][1] to get prepared for the next release.

## Current release

- [v1](docs/CHANGELOG-v1.md)
- [v1](https://microsoft.github.io/PSRule/latest/CHANGELOG-v1/)

## Prior releases

- [v0](docs/CHANGELOG-v0.md)
- [v0](https://microsoft.github.io/PSRule/latest/CHANGELOG-v0/)
4 changes: 2 additions & 2 deletions docs/CHANGELOG-v0.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Change log

See [upgrade notes][upgrade-notes] for helpful information when upgrading from previous versions.
See [upgrade notes][1] for helpful information when upgrading from previous versions.

[upgrade-notes]: upgrade-notes.md
[1]: https://microsoft.github.io/PSRule/latest/upgrade-notes/

## v0.22.0

Expand Down
12 changes: 10 additions & 2 deletions docs/CHANGELOG-v1.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Change log

See [upgrade notes][upgrade-notes] for helpful information when upgrading from previous versions.
See [upgrade notes][1] for helpful information when upgrading from previous versions.

[upgrade-notes]: upgrade-notes.md
[1]: https://microsoft.github.io/PSRule/latest/upgrade-notes/

**Important notes**:

Expand All @@ -21,6 +21,14 @@ What's changed since v1.11.0:
- See [about_PSRule_Assert] for details.
- Improve tracking of suppressed objects. [#794](https://github.com/microsoft/PSRule/issues/794)
- Added `Execution.SuppressedRuleWarning` option to output warning for suppressed rules.
- Engineering:
- **Breaking change:** Removal of deprecated default baseline from module manifest. [#755](https://github.com/microsoft/PSRule/issues/755)
- Set the default module baseline using module configuration.
- See [upgrade notes][1] for details.
- **Breaking change:** Require `apiVersion` on YAML and JSON to be specified. [#648](https://github.com/microsoft/PSRule/issues/648)
- Resources should use `github.com/microsoft/PSRule/v1` as the `apiVersion`.
- Resources that do not specify an `apiVersion` will be ignored.
- See [upgrade notes][1] for details.

## v1.11.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ PrivateData = @{
# ReleaseNotes = ''

} # End of PSData hashtable
PSRule = @{
Baseline = 'Enterprise.Default'
}
} # End of PrivateData hashtable

# HelpInfo URI of this module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ spec:
resourceId: [ 'ResourceId' ]
subscriptionId: [ 'SubscriptionId' ]
resourceGroupName: [ 'ResourceGroupName' ]
rule:
baseline: 'Enterprise.Default'
80 changes: 78 additions & 2 deletions docs/upgrade-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,85 @@

This document contains notes to help upgrade from previous versions of PSRule.

## Upgrading to v2.0.0

Follow these notes to upgrade to PSRule _v2.0.0_ from previous versions.

### Setting default module baseline

When packaging rules in a module, you can set the default baseline.
The default baseline from the module will be automatically used unless overriden.

Prior to _v1.9.0_ the default baseline was set by configuring the module manifest `.psd1` file.
From _v1.9.0_ the default baseline can be configured by within a module configuration.
Using module configuration is the recommended method.
Setting the default baseline from module manifest and has been removed from _v2.0.0_.

A module configuration can be defined in YAML.

!!! Example

```yaml hl_lines="8-9"
---
# Synopsis: Example module configuration for Enterprise.Rules module.
apiVersion: github.com/microsoft/PSRule/v1
kind: ModuleConfig
metadata:
name: Enterprise.Rules
spec:
rule:
baseline: Enterprise.Default
```

### Setting resource API version

When creating YAML and JSON resources you define a resource by specifying the `apiVersion` and `kind`.
An `apiVersion` was added as a requirement from _v1.2.0_.
For compability resources without an `apiVersion` were supported however deprecated for removal in _v2.0.0_.
This has now been removed from _v2.0.0_.

When defining resource specify an `apiVersion`.
Currently this must be set to `github.com/microsoft/PSRule/v1`.

=== "YAML"

```yaml hl_lines="3-4"
---
# Synopsis: An example rule to require TLS.
apiVersion: github.com/microsoft/PSRule/v1
kind: Rule
metadata:
name: 'Local.YAML.RequireTLS'
spec:
condition:
field: 'configure.supportsHttpsTrafficOnly'
equals: true
```

=== "JSON"

```json hl_lines="4-5"
[
{
// Synopsis: An example rule to require TLS.
"apiVersion": "github.com/microsoft/PSRule/v1",
"kind": "Rule",
"metadata": {
"name": "Local.JSON.RequireTLS"
},
"spec": {
"condition": {
"field": "configure.supportsHttpsTrafficOnly",
"equals": true
}
}
}
]
```

## Upgrading to v1.4.0

Follow these notes to upgrade from PSRule version _v1.3.0_ to _v1.4.0_.
Follow these notes to upgrade to PSRule _v1.4.0_ from previous versions.

### Change in default output styles

Expand Down Expand Up @@ -53,7 +129,7 @@ variables:

## Upgrading to v1.0.0

Follow these notes to upgrade from PSRule version _v0.22.0_ to _v1.0.0_.
Follow these notes to upgrade to PSRule _v1.0.0_ from previous versions.

### Replaced $Rule target properties

Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ nav:
- Change log:
- v1: 'CHANGELOG-v1.md'
- v0: 'CHANGELOG-v0.md'
- Upgrade guide: upgrade-notes.md
- Upgrade notes: upgrade-notes.md
# - Deprecations: deprecations.md
- Support: support.md
# - Setup:
Expand Down
8 changes: 1 addition & 7 deletions src/PSRule/Common/JsonConverters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
Expand Down Expand Up @@ -545,12 +545,6 @@ private bool TrySpec(
comment: comment,
spec: deserializedSpec
);

if (string.IsNullOrEmpty(apiVersion))
{
spec.SetApiVersionIssue();
}

return true;
}
}
Expand Down
19 changes: 5 additions & 14 deletions src/PSRule/Common/ResourceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using PSRule.Definitions;
Expand All @@ -8,23 +8,14 @@ namespace PSRule
{
internal static class ResourceExtensions
{
internal static void SetApiVersionIssue(this IResource resource)
{
if (!(resource is IAnnotated<ResourceAnnotation> annotated))
return;

var validate = annotated.RequireAnnotation<ResourceAnnotation, ValidateResourceAnnotation>();
validate.ApiVersionNotSet = true;
annotated.SetAnnotation(validate);
}

internal static bool GetApiVersionIssue(this IResource resource)
internal static bool TryValidateResourceAnnotation(this IResource resource, out ValidateResourceAnnotation value)
{
value = null;
if (!(resource is IAnnotated<ResourceAnnotation> annotated))
return false;

var validate = annotated.GetAnnotation<ValidateResourceAnnotation>();
return validate != null && validate.ApiVersionNotSet;
value = annotated.GetAnnotation<ValidateResourceAnnotation>();
return value != null;
}

internal static bool Match(this IResourceFilter filter, Baseline resource)
Expand Down
3 changes: 0 additions & 3 deletions src/PSRule/Common/YamlConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,6 @@ private bool TryResource(IParser reader, string apiVersion, string kind, Func<IP
return false;

spec = descriptor.CreateInstance(RunspaceContext.CurrentThread.Source.File, metadata, comment, value);
if (string.IsNullOrEmpty(apiVersion))
spec.SetApiVersionIssue();

return true;
}
return false;
Expand Down
8 changes: 7 additions & 1 deletion src/PSRule/Definitions/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ protected ResourceRef(string id, ResourceKind kind)
}
}

/// <summary>
/// A base resource annotation.
/// </summary>
internal abstract class ResourceAnnotation
{

}

/// <summary>
/// Annotation used to flag validation issues.
/// </summary>
internal sealed class ValidateResourceAnnotation : ResourceAnnotation
{
public bool ApiVersionNotSet { get; internal set; }

}

public sealed class ResourceObject
Expand Down
5 changes: 1 addition & 4 deletions src/PSRule/Definitions/Spec.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using PSRule.Definitions.Baselines;
Expand All @@ -16,9 +16,6 @@ protected Spec() { }

public static string GetFullName(string apiVersion, string name)
{
if (string.IsNullOrEmpty(apiVersion))
apiVersion = Specs.V1;

return string.Concat(apiVersion, FullNameSeparator, name);
}
}
Expand Down
29 changes: 19 additions & 10 deletions src/PSRule/Pipeline/PipelineContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ public SourceScope(SourceFile source, string[] content)

internal enum ResourceIssueType
{
Unknown,
MissingApiVersion
Unknown
}

internal sealed class ResourceIssue
Expand Down Expand Up @@ -161,9 +160,7 @@ internal Runspace GetRunspace()

internal void Import(IResource resource)
{
if (resource.GetApiVersionIssue())
_TrackedIssues.Add(new ResourceIssue(resource.Kind, resource.Id, ResourceIssueType.MissingApiVersion));

TrackIssue(resource);
if (TryBaseline(resource, out Baseline baseline) && TryBaselineRef(resource.Id, out BaselineRef baselineRef))
{
_Unresolved.Remove(baselineRef);
Expand All @@ -183,6 +180,12 @@ internal void Import(IResource resource)
}
}

private void TrackIssue(IResource resource)
{
//if (resource.TryValidateResourceAnnotation())
// _TrackedIssues.Add(new ResourceIssue(resource.Kind, resource.Id, ResourceIssueType.MissingApiVersion));
}

BernieWhite marked this conversation as resolved.
Show resolved Hide resolved
private bool TryBaselineRef(string resourceId, out BaselineRef baselineRef)
{
baselineRef = null;
Expand Down Expand Up @@ -221,14 +224,20 @@ private static bool TryModuleConfig(IResource resource, out ModuleConfigV1 modul

internal void Begin(RunspaceContext runspaceContext)
{
for (var i = 0; _TrackedIssues != null && i < _TrackedIssues.Count; i++)
{
if (_TrackedIssues[i].Issue == ResourceIssueType.MissingApiVersion)
runspaceContext.WarnMissingApiVersion(_TrackedIssues[i].Kind, _TrackedIssues[i].Id);
}
ReportIssue(runspaceContext);
Baseline.Init(runspaceContext);
}

/// <summary>
/// Report any tracked issues.
/// </summary>
private void ReportIssue(RunspaceContext runspaceContext)
{
//for (var i = 0; _TrackedIssues != null && i < _TrackedIssues.Count; i++)
//if (_TrackedIssues[i].Issue == ResourceIssueType.MissingApiVersion)
// runspaceContext.WarnMissingApiVersion(_TrackedIssues[i].Kind, _TrackedIssues[i].Id);
}

#region IBindingContext

public bool GetPathExpression(string path, out PathExpression expression)
Expand Down
4 changes: 0 additions & 4 deletions src/PSRule/Pipeline/SourcePipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Threading;
using Newtonsoft.Json;
using PSRule.Configuration;
using PSRule.Definitions;
using PSRule.Pipeline.Output;
using PSRule.Resources;
using YamlDotNet.Serialization;
Expand Down Expand Up @@ -117,9 +116,6 @@ public ModuleInfo(PSModuleInfo info)
Name = info.Name;
Version = info.Version?.ToString();
ProjectUri = info.ProjectUri?.ToString();
if (TryPrivateData(info, FIELD_PSRULE, out Hashtable moduleData))
Baseline = moduleData.ContainsKey(FIELD_BASELINE) ? ResourceHelper.GetIdString(Name, moduleData[FIELD_BASELINE] as string) : null;

if (TryPrivateData(info, FIELD_PSDATA, out Hashtable psData) && psData.ContainsKey(FIELD_PRERELEASE))
Version = string.Concat(Version, PRERELEASE_SEPARATOR, psData[FIELD_PRERELEASE].ToString());
}
Expand Down
Loading