PSRule icon indicating copy to clipboard operation
PSRule copied to clipboard

Configuration for YAML/ JSON based rules

Open BernieWhite opened this issue 3 years ago • 4 comments

Currently PowerShell-based rules can use configuration values from options.

This is currently not supported for YAML/ JSON rules, we should add this feature.

Related to discussion Azure/PSRule.Rules.Azure#1314

May be able to work into: #1033

BernieWhite avatar Mar 20 '22 14:03 BernieWhite

@BernieWhite I can probably help with this one. Was thinking configuration could be another comparison property like field, name, type, source we could introduce.

ArmaanMcleod avatar Jun 19 '22 07:06 ArmaanMcleod

@ArmaanMcleod Thanks. Agreed.

BernieWhite avatar Jun 19 '22 07:06 BernieWhite

@BernieWhite If we had a configuration defined like below:

configuration:
  allowedBusinessUnits:
  - 'IT Operations'
  - 'Finance'
  - 'HR'

And a YAML rule

---
# Synopsis: A YAML rule for testing.
apiVersion: github.com/microsoft/PSRule/v1
kind: Rule
metadata:
  name: RuleYamlTagConfig
spec:
  condition:
    allOf:
    - field: 'tags.businessUnit'
      exists: true
    - field: 'tags.businessUnit'
      in:
        configuration: 'allowedBusinessUnits'

How would this work with the existing schema? Since in would expect an array of values to compare against.

Or would we need to convert this to an array of values:

- field: 'tags.businessUnit'
  in:
  - configuration: 'allowedBusinessUnits'

Probably need to find a consistent way to doing this for all the expressions.

ArmaanMcleod avatar Jun 26 '22 04:06 ArmaanMcleod

@ArmaanMcleod I was thinking something like this:

- field: 'tags.businessUnit'
  in:
    $:
      configuration: 'allowedBusinessUnits'

It should be easy to update the schema to support all the advanced use cases for complex function support through a $ object.

BernieWhite avatar Jun 26 '22 23:06 BernieWhite

This should be addressed by initial function support.

BernieWhite avatar Aug 26 '22 05:08 BernieWhite