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

Require rule sources from current working directory to be explicitly included #760

Closed
BernieWhite opened this issue Jul 31, 2021 · 2 comments · Fixed by #938
Closed

Require rule sources from current working directory to be explicitly included #760

BernieWhite opened this issue Jul 31, 2021 · 2 comments · Fixed by #938
Assignees
Labels
breaking-change Changes that affect existing functionality deprecation Clean up deprecated functionality feature: core Issues that affect the core engine
Milestone

Comments

@BernieWhite
Copy link
Member

In v1 when calling PSRule cmdlets without -Path and -Module parameters, rule sources from the current working directory $PWD are automatically included.

Including $PWD is problematic in some scenarios such as build pipelines when rule sources may be stored in temporary paths such as out/.

Now that the default recommend path .ps-rule/ for standalone rules is automatically included also including $PWD is not required.

From v2 onwards, $PWD should not be included unless -Path . or -Path $PWD is explicitly specified.

@BernieWhite BernieWhite added deprecation Clean up deprecated functionality breaking-change Changes that affect existing functionality feature: core Issues that affect the core engine labels Jul 31, 2021
@BernieWhite BernieWhite added this to the v2.0.0 milestone Jul 31, 2021
@ArmaanMcleod
Copy link
Contributor

@BernieWhite Considering the new behaviour from #610, this would mean that sources loaded from -Path would have to come after modules.

I would still expect module sources to be preferred by default:

Import-Module .\out\modules\PSRule
Import-Module .\tests\PSRule.Tests\TestModule\
cd .\tests\PSRule.Tests\TestModule\
Get-PSRuleHelp

Name                                ModuleName               Synopsis
----                                ----------               --------
M1.Rule1                            TestModule               Synopsis en-AU.
M1.Rule2                            TestModule               This is the default
M1.YamlTestName                     TestModule               This is an example YAML rule.

But if we are only explicit with -Path, we only get loose files

Get-PSRuleHelp -Path $PWD

Name                                ModuleName               Synopsis
----                                ----------               --------
M1.Rule1                                                     This is the default
M1.Rule2                                                     This is the default
M1.YamlTestName                                              A YAML rule for testing

If we also include -Module, we expect modules to be preferred:

Get-PSRuleHelp -Path $PWD -Module TestModule

WARNING: A rule with the same name 'M1.Rule1' already exists.
WARNING: A rule with the same name 'M1.Rule2' already exists.
WARNING: A rule with the same name 'M1.YamlTestName' already exists.

Name                                ModuleName               Synopsis
----                                ----------               --------
M1.Rule1                            TestModule               Synopsis en-AU.
M1.Rule2                            TestModule               This is the default
M1.YamlTestName                     TestModule               This is an example YAML rule.

Is that correct?

@BernieWhite
Copy link
Member Author

@ArmaanMcleod We still want the behaviour from #610 to be true. More specifically if you run any command such as Get-PSRule we want to change the default behaviour of finding rules recursively from $PWD to $PWD/.ps-rule/.

i.e. if you cd docs\scenarios\azure-resources and run Get-PSRule you would get:

RuleName                            ModuleName                 Synopsis
--------                            ----------                 --------
appServicePlan.MinInstanceCount                                App Service Plan has multiple instances
appServicePlan.MinPlan                                         Use at least a Standard App Service Plan
appServiceApp.ARRAffinity                                      Disable client affinity for stateless services
appServiceApp.UseHTTPS                                         Use HTTPS only
storageAccounts.UseHttps                                       Configure storage accounts to only accept encrypted traffic i.e. HTTPS/SMB
storageAccounts.UseEncryption                                  Use at-rest storage encryption

The current behaviour is complex.

  • If no module is specified, rules are discovered from $PWD and $PWD/.ps-rule/ by default. Based on the Include.Path option default. Help
  • If any module is specified, rules are discovered from the module base paths and $PWD/.ps-rule/ by default.

The new behaviour should be, don't include $PWD at all unless it is specified, which could be by:

  • Manually specifying -Path $PWD on cmdlets.
  • Specifying the source: '.' property on GitHub Actions or Azure Pipelines task, which effectively explicitly sets -Path $PWD.
  • Setting the Include.Path and including ..

In terms of preferring modules, we should use the same behaviour that if the source is already loaded from a module which is done first then is should not be loaded again as a loose/ standalone source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Changes that affect existing functionality deprecation Clean up deprecated functionality feature: core Issues that affect the core engine
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants