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 JSON output format for Baseline cmdlets #839

Closed
ArmaanMcleod opened this issue Oct 28, 2021 · 3 comments · Fixed by #840
Closed

Add JSON output format for Baseline cmdlets #839

ArmaanMcleod opened this issue Oct 28, 2021 · 3 comments · Fixed by #840
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ArmaanMcleod
Copy link
Contributor

ArmaanMcleod commented Oct 28, 2021

Extending from #833

We can added JSON output format to the following cmdlets:

  • Get-PSRuleBaseline
  • Export-PSRuleBaseline

E.g.

Get-PSRuleBaseline -Module PSRule.Rules.Azure -OutputFormat Json -Option @{'Output.JsonIndent' = 4}
@ArmaanMcleod ArmaanMcleod added the enhancement New feature or request label Oct 28, 2021
@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Oct 28, 2021

@BernieWhite Tested this out and have this:

[
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.Default"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA"
                }
            }
        },
        "synopsis": "Default baseline for Azure rules."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.Preview"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": [
                        "GA",
                        "preview"
                    ]
                }
            }
        },
        "synopsis": "Includes Azure features in preview."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.All"
        },
        "spec": {
            "rule": {
                "tag": {}
            }
        },
        "synopsis": "Includes all Azure rules."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2020_06"
        },
        "spec": {
            "rule": {
                "tag": {
                    "ruleSet": [
                        "2020_06"
                    ],
                    "release": "GA"
                }
            }
        },
        "synopsis": "Include rules released June 2020 or prior for Azure GA features."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2020_09"
        },
        "spec": {
            "rule": {
                "tag": {
                    "ruleSet": [
                        "2020_06",
                        "2020_09"
                    ],
                    "release": "GA"
                }
            }
        },
        "synopsis": "Include rules released September 2020 or prior for Azure GA features."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2020_12"
        },
        "spec": {
            "rule": {
                "tag": {
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12"
                    ],
                    "release": "GA"
                }
            }
        },
        "synopsis": "Include rules released December 2020 or prior for Azure GA features."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2021_03"
        },
        "spec": {
            "rule": {
                "tag": {
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12",
                        "2021_03"
                    ],
                    "release": "GA"
                }
            }
        },
        "synopsis": "Include rules released March 2021 or prior for Azure GA features."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2021_06"
        },
        "spec": {
            "rule": {
                "tag": {
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12",
                        "2021_03",
                        "2021_06"
                    ],
                    "release": "GA"
                }
            }
        },
        "synopsis": "Include rules released June 2021 or prior for Azure GA features."
    },
    {
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.GA_2021_09"
        },
        "spec": {
            "rule": {
                "tag": {
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12",
                        "2021_03",
                        "2021_06",
                        "2021_09"
                    ],
                    "release": "GA"
                }
            }
        },
        "synopsis": "Include rules released September 2021 or prior for Azure GA features."
    }
]

I included synopsis as a property, given JSON doesn't support /* */, // comments in the specification.

But JSONC (json with comments) is an option, and this would be fine with having a synopsis as a comment.

@ArmaanMcleod ArmaanMcleod self-assigned this Oct 28, 2021
@ArmaanMcleod ArmaanMcleod changed the title Added JSON output format for Baseline cmdlets Add JSON output format for Baseline cmdlets Oct 29, 2021
@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Oct 30, 2021

This would be acceptable for JSONC

[
    {/* Synopsis: Default baseline for Azure rules. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.Default"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA"
                }
            }
        }
    },
    {/* Synopsis: Includes Azure features in preview. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.Preview"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": [
                        "GA",
                        "preview"
                    ]
                }
            }
        }
    },
    {/* Synopsis: Includes all Azure rules. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.All"
        },
        "spec": {
            "rule": {
                "tag": {}
            }
        }
    },
    {/* Synopsis: Include rules released June 2020 or prior for Azure GA features. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2020_06"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA",
                    "ruleSet": [
                        "2020_06"
                    ]
                }
            }
        }
    },
    {/* Synopsis: Include rules released September 2020 or prior for Azure GA features. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2020_09"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA",
                    "ruleSet": [
                        "2020_06",
                        "2020_09"
                    ]
                }
            }
        }
    },
    {/* Synopsis: Include rules released December 2020 or prior for Azure GA features. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2020_12"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA",
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12"
                    ]
                }
            }
        }
    },
    {/* Synopsis: Include rules released March 2021 or prior for Azure GA features. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2021_03"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA",
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12",
                        "2021_03"
                    ]
                }
            }
        }
    },
    {/* Synopsis: Include rules released June 2021 or prior for Azure GA features. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "annotations": {
                "obsolete": "true"
            },
            "name": "Azure.GA_2021_06"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA",
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12",
                        "2021_03",
                        "2021_06"
                    ]
                }
            }
        }
    },
    {/* Synopsis: Include rules released September 2021 or prior for Azure GA features. */
        "apiVersion": "github.com/microsoft/PSRule/v1",
        "kind": "Baseline",
        "metadata": {
            "name": "Azure.GA_2021_09"
        },
        "spec": {
            "rule": {
                "tag": {
                    "release": "GA",
                    "ruleSet": [
                        "2020_06",
                        "2020_09",
                        "2020_12",
                        "2021_03",
                        "2021_06",
                        "2021_09"
                    ]
                }
            }
        }
    }
]

@BernieWhite
Copy link
Member

@ArmaanMcleod Currently synopsis is not included in the schema. So when we take the next step and support JSON-based resources then this might be a problem. My preference would be to // Synopsis: on a new line above apiVersion if that is possibly. That preserves the closest behaviour to how it currently works. Otherwise it may make sense to add support for a synopsis property within the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants