Skip to content

Add CLI tool to extract rule information with JSON output #2978

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 10, 2025

This PR adds a new get rule command to the PSRule CLI tool that extracts rule metadata and outputs it in JSON format for pipeline automation.

What's Changed

  • New CLI Command: Added ps-rule get rule command with comprehensive options
  • JSON Output: Returns structured JSON perfect for CI/CD pipeline consumption
  • Rule Metadata: Extracts tags, labels, annotations, severity, synopsis, description, and recommendations
  • Command Options: Supports --path, --module, --name, --baseline, --include-dependencies, --no-restore
  • Tests: Added unit tests to verify command functionality

Usage

# Basic usage - get all rules
ps-rule get rule

# Get specific rules with dependencies
ps-rule get rule --include-dependencies --name "Security.*" --path ./rules

# Get rules from specific modules
ps-rule get rule --module MyModule.Rules --baseline Production

JSON Output Structure

{
  "rules": [
    {
      "ruleName": "Security.TLS",
      "displayName": "Use TLS 1.2+",
      "synopsis": "Ensure TLS 1.2 or higher is used",
      "description": "TLS versions below 1.2 have known vulnerabilities",
      "recommendation": "Configure services to use TLS 1.2 or higher",
      "moduleName": "Security.Rules",
      "severity": "High",
      "tags": { "category": "Security", "type": "Protocol" },
      "annotations": { "version": "1.0.0", "author": "Security Team" },
      "labels": { "environment": "Production" }
    }
  ]
}

Benefits for Pipeline Automation

This command enables easy programmatic access to rule information for:

  • Build and release automation scripts
  • Copilot actions that need rule metadata
  • CI/CD pipelines that process rule information
  • Custom tooling that works with PSRule data

The JSON output format makes it simple to consume rule metadata in any language or tool that can parse JSON.

Fixes #2977.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 4 commits July 10, 2025 12:47
Co-authored-by: BernieWhite <13513058+BernieWhite@users.noreply.github.com>
Co-authored-by: BernieWhite <13513058+BernieWhite@users.noreply.github.com>
Co-authored-by: BernieWhite <13513058+BernieWhite@users.noreply.github.com>
Co-authored-by: BernieWhite <13513058+BernieWhite@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [FEATURE] Tool to extract information from rules and docs Add CLI tool to extract rule information with JSON output Jul 10, 2025
@Copilot Copilot AI requested a review from BernieWhite July 10, 2025 13:11
Copilot finished work on behalf of BernieWhite July 10, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Tool to extract information from rules and docs
2 participants