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

Add YAML view for Get-PSRuleBaseline #326

Closed
BernieWhite opened this issue Nov 1, 2019 · 2 comments · Fixed by #813
Closed

Add YAML view for Get-PSRuleBaseline #326

BernieWhite opened this issue Nov 1, 2019 · 2 comments · Fixed by #813
Assignees
Labels
enhancement New feature or request feature: baselines Issues that affect baselines help wanted Extra attention is needed

Comments

@BernieWhite
Copy link
Member

BernieWhite commented Nov 1, 2019

Currently Get-PSRuleBaseline returns a complex object of the baseline. Add an additional option to return the baseline as YAML, for example -OutputFormat Yaml.

@BernieWhite BernieWhite added the enhancement New feature or request label Nov 1, 2019
@BernieWhite BernieWhite added the help wanted Extra attention is needed label Jan 1, 2020
@BernieWhite BernieWhite added the feature: baselines Issues that affect baselines label Feb 4, 2021
@ArmaanMcleod
Copy link
Contributor

ArmaanMcleod commented Sep 26, 2021

@BernieWhite I can probably help with this. I had a first go and was able to get this output(only first 100 lines):

- - id: .\Azure.Default
    source: &o0
      path: C:\Users\armcleod\Documents\github-repos\PSRule.Rules.Azure\src\PSRule.Rules.Azure\rules\Baseline.Rule.yaml
      moduleName:
      type: Yaml
      helpPath: C:\Users\armcleod\Documents\github-repos\PSRule.Rules.Azure\.ps-rule
    info:
      synopsis: Default baseline for Azure rules.
    baselineId: Azure.Default
    synopsis: Default baseline for Azure rules.
    name: Azure.Default
    metadata:
      name: Azure.Default
      annotations: {}
      tags: {}
    kind: Baseline
    apiVersion: github.com/microsoft/PSRule/v1
    spec:
      binding:
      configuration:
      convention:
      rule:
        includeLocal:
        include: 
        exclude:
        tag:
          release: &o1 GA
  - id: .\Azure.Preview
    source: *o0
    info:
      synopsis: Includes Azure features in preview.
    baselineId: Azure.Preview
    synopsis: Includes Azure features in preview.
    name: Azure.Preview
    metadata:
      name: Azure.Preview
      annotations: {}
      tags: {}
    kind: Baseline
    apiVersion: github.com/microsoft/PSRule/v1
    spec:
      binding:
      configuration:
      convention:
      rule:
        includeLocal:
        include:
        exclude:
        tag:
          release:
          - *o1
          - &o108
            baseObject: *o108
            members:
            - isSettable: false
              isGettable: true
              overloadDefinitions:
              - char Chars(int index) {get;}
              typeNameOfValue: System.Char
              memberType: ParameterizedProperty
              value: {}
              name: Chars
              isInstance: true
            - memberType: Property
              value: &o162 {}
              isSettable: false
              isGettable: true
              typeNameOfValue: System.Int32
              name: Length
              isInstance: true
            - memberType: Method
              overloadDefinitions:
              - bool Equals(System.Object obj)
              - bool Equals(string value)
              - bool Equals(string value, System.StringComparison comparisonType)
              - bool IEquatable[string].Equals(string other)
              typeNameOfValue: System.Management.Automation.PSMethod
              value: {}
              name: Equals
              isInstance: true
            - memberType: Method
              overloadDefinitions:
              - string Replace(string oldValue, string newValue, bool ignoreCase, cultureinfo culture)
              - string Replace(string oldValue, string newValue, System.StringComparison comparisonType)
              - string Replace(char oldChar, char newChar)
              - string Replace(string oldValue, string newValue)
              typeNameOfValue: System.Management.Automation.PSMethod
              value: {}
              name: Replace
              isInstance: true
            - memberType: Method
              overloadDefinitions:
              - string[] Split(char separator, System.StringSplitOptions options)
              - string[] Split(char separator, int count, System.StringSplitOptions options)
              - string[] Split(Params char[] separator)
              - string[] Split(char[] separator, int count)
              - string[] Split(char[] separator, System.StringSplitOptions options)
              - string[] Split(char[] separator, int count, System.StringSplitOptions options)
              - string[] Split(string separator, System.StringSplitOptions options)
              - string[] Split(string separator, int count, System.StringSplitOptions options)

But it seems there are some serialization problems with the tags and some other things like the method overloads showing up in the output.

Seems like an issue how hashtables are getting serialized. Could probably create a YAML converter to handle this.

@BernieWhite
Copy link
Member Author

@ArmaanMcleod Great thanks. Yes, you may need to customise the serialization process. Ideally, we want it to look the original object.

https://github.com/Azure/PSRule.Rules.Azure/blob/cfc0b4974dff48123582002e66455206cdac8660/src/PSRule.Rules.Azure/rules/Baseline.Rule.yaml#L9-L17

Extra properties such as id, source, info and baselineId can be removed from serialized object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature: baselines Issues that affect baselines help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants