Skip to content

Python Helper Methods Reference

Complete reference for CyberTrackrHelper convenience methods.

Initialization

python
from cyber_trackr_helper import CyberTrackrHelper

# Basic initialization
helper = CyberTrackrHelper()

# With caching and rate limiting (production recommended)
helper = CyberTrackrHelper(
    enable_cache=True,
    cache_ttl=3600,  # 1 hour
    rate_limit_per_second=10
)

# Custom configuration
helper = CyberTrackrHelper(
    base_url="https://cyber.trackr.live/api",
    enable_cache=True,
    cache_dir="~/.cache/my_app",
    cache_ttl=7200,  # 2 hours
    cache_backend='sqlite',  # or 'filesystem', 'redis'
    rate_limit_per_second=5  # Conservative
)

Document Filtering Methods

list_stigs() → Dict[str, Any]

List only STIGs (excludes SRGs).

python
stigs = helper.list_stigs()
print(f"Found {len(stigs)} STIGs")

for name, versions in list(stigs.items())[:5]:
    print(f"  {name}: {len(versions)} versions")

list_srgs() → Dict[str, Any]

List only SRGs (excludes STIGs).

python
srgs = helper.list_srgs()
print(f"Found {len(srgs)} SRGs")

is_srg(name: str) → bool (static method)

Check if a document name is an SRG.

python
# Static method - can call without instance
is_srg = CyberTrackrHelper.is_srg("Application_Security_Requirements_Guide")
# Returns: True

is_stig = not CyberTrackrHelper.is_srg("Red_Hat_Enterprise_Linux_9")
# Returns: True

Search Methods

search_documents(keyword: str, doc_type: str = 'all') → Dict[str, Any]

Search for documents with smart, flexible matching.

Smart matching handles:

  • "Red Hat" matches "Red_Hat"
  • "RedHat" matches "Red_Hat"
  • "red hat" matches "Red_Hat"
  • Case-insensitive
  • Underscore/space/hyphen flexible
python
# All these return the same results
redhat1 = helper.search_documents("Red Hat", doc_type='stig')
redhat2 = helper.search_documents("RedHat", doc_type='stig')
redhat3 = helper.search_documents("red_hat", doc_type='stig')

# Search all document types
all_juniper = helper.search_documents("Juniper")

# Search only SRGs
alg_srgs = helper.search_documents("ALG", doc_type='srg')

fuzzy_search_documents(search_term: str, doc_type: str = 'all', threshold: float = 0.6) → List[tuple]

Search with fuzzy matching and similarity scoring.

python
# Returns list of (name, score, versions) tuples
results = helper.fuzzy_search_documents("RedHat Linux", threshold=0.6)

for name, score, versions in results[:5]:
    print(f"{score:.2f}: {name}")
# Output:
# 0.95: Red_Hat_Enterprise_Linux_9
# 0.93: Red_Hat_Enterprise_Linux_8
# 0.90: Red_Hat_Enterprise_Linux_7

get_latest_version(name: str) → Optional[Dict]

Get the latest version of a document.

python
latest = helper.get_latest_version("Red_Hat_Enterprise_Linux_9")
print(f"Latest: v{latest.version}r{latest.release}")
print(f"Released: {latest.released}")
print(f"Link: {latest.link}")

Batch Fetching Methods

fetch_complete_stig(name, version, release, delay=0.1, progress_callback=None) → Dict

Fetch a complete STIG with all requirement details (not just summaries).

python
# Basic usage
complete = helper.fetch_complete_stig(
    "Red_Hat_Enterprise_Linux_9", "1", "2"
)

# With progress tracking
def show_progress(current, total, vuln_id):
    print(f"Fetching {current}/{total}: {vuln_id}")

complete = helper.fetch_complete_stig(
    "Red_Hat_Enterprise_Linux_9", "1", "2",
    delay=0.2,  # 200ms between requests
    progress_callback=show_progress
)

print(f"Fetched {len(complete['requirements'])} requirements")

Severity Filtering Methods

get_requirements_by_severity(name, version, release, severities=['high']) → Dict

Filter requirements by severity level(s).

python
# Get only HIGH severity requirements
high_only = helper.get_requirements_by_severity(
    "Red_Hat_Enterprise_Linux_9", "1", "2",
    severities=['high']
)
print(f"High severity: {len(high_only)} requirements")

# Get HIGH and MEDIUM
high_med = helper.get_requirements_by_severity(
    "Red_Hat_Enterprise_Linux_9", "1", "2",
    severities=['high', 'medium']
)

get_high_severity_requirements(name, version, release) → Dict

Convenience method for HIGH severity only.

python
critical = helper.get_high_severity_requirements(
    "Red_Hat_Enterprise_Linux_9", "1", "2"
)
print(f"Critical requirements: {len(critical)}")

get_requirements_summary_by_severity(name, version, release) → Dict[str, List[str]]

Get summary grouped by severity.

python
summary = helper.get_requirements_summary_by_severity(
    "Red_Hat_Enterprise_Linux_9", "1", "2"
)

print(f"High: {len(summary['high'])}")
print(f"Medium: {len(summary['medium'])}")
print(f"Low: {len(summary['low'])}")

# Get specific severity V-IDs
for v_id in summary['high'][:5]:
    print(f"  - {v_id}")

RMF Control Methods

get_control_family(family_code: str, revision: int = 5) → Dict[str, str]

Get all controls in a family.

python
# Access Control family (Rev 5)
ac_controls = helper.get_control_family('AC', revision=5)

for control_id, title in list(ac_controls.items())[:5]:
    print(f"{control_id}: {title}")
# Output:
# AC-1: POLICY AND PROCEDURES
# AC-2: ACCOUNT MANAGEMENT
# AC-3: ACCESS ENFORCEMENT

get_control_family_info(family_code: str, revision: int = 5) → Dict

Get comprehensive family information.

python
info = helper.get_control_family_info('AC')

print(f"Family: {info['family_name']}")  # "Access Control"
print(f"Code: {info['family_code']}")  # "AC"
print(f"Controls: {info['control_count']}")  # 25
print(f"Revision: {info['revision']}")  # 5

compare_control_revisions(control_id: str) → Dict

Compare a control between Rev 4 and Rev 5.

python
comparison = helper.compare_control_revisions('AC-1')

print("Rev 4:")
print(f"  Title: {comparison['rev4']['title']}")

print("Rev 5:")
print(f"  Title: {comparison['rev5']['title']}")

get_control_with_ccis(control_id: str, revision: int = 5) → Dict

Get control with all mapped CCIs.

python
ac1_with_ccis = helper.get_control_with_ccis('AC-1', revision=5)

print(f"Control: {ac1_with_ccis['control']['title']}")
print(f"CCIs: {len(ac1_with_ccis['ccis'])}")

CCI Methods

search_ccis(keyword: str) → Dict[str, str]

Search CCIs by keyword (case-insensitive).

python
password_ccis = helper.search_ccis('password')

for cci_id, definition in list(password_ccis.items())[:3]:
    print(f"{cci_id}: {definition[:60]}...")

get_ccis_for_rmf_control(control_id: str, revision: int = 5) → List[str]

Get all CCIs mapped to an RMF control.

python
ac1_ccis = helper.get_ccis_for_rmf_control('AC-1', revision=5)
print(f"AC-1 maps to {len(ac1_ccis)} CCIs")
print(ac1_ccis)
# ['CCI-000001', 'CCI-000002', ...]

get_cci_with_controls(cci_id: str) → Dict

Get CCI details with RMF control mapping.

python
cci_info = helper.get_cci_with_controls('CCI-000213')

print(f"CCI: {cci_info['cci']['cci']}")
print(f"Definition: {cci_info['cci']['definition']}")
print(f"RMF Controls: {list(cci_info['mapped_controls'].keys())}")

Cross-Reference Methods

map_stig_to_rmf(name, version, release, delay=0.1) → Dict

Map all STIG requirements to RMF controls via CCIs.

python
mapping = helper.map_stig_to_rmf(
    "Red_Hat_Enterprise_Linux_9", "1", "2",
    delay=0.2  # Be respectful
)

for v_id, data in list(mapping.items())[:3]:
    print(f"{v_id}:")
    print(f"  CCIs: {data['ccis']}")
    print(f"  RMF Controls: {data['rmf_controls']}")

get_compliance_chain(name, version, release, vuln_id: str) → Dict

Get full compliance chain for one requirement.

python
chain = helper.get_compliance_chain(
    "Red_Hat_Enterprise_Linux_9", "1", "2",
    "V-257777"
)

print(f"Requirement: {chain['stig_requirement']['title']}")
print(f"Severity: {chain['stig_requirement']['severity']}")
print(f"CCIs: {[cci['id'] for cci in chain['ccis']]}")
print(f"RMF Controls: {chain['rmf_controls']}")

SCAP Methods

list_scap_for_stig(stig_name: str) → Dict

Find SCAP documents for a specific STIG.

python
scap_docs = helper.list_scap_for_stig("Windows_10")

for name, versions in scap_docs.items():
    print(f"{name}: {len(versions)} versions")

get_latest_scap_for_stig(stig_name: str) → Optional[Dict]

Get latest SCAP document for a STIG.

python
latest_scap = helper.get_latest_scap_for_stig("Windows_10")
if latest_scap:
    print(f"Latest SCAP: v{latest_scap.version}r{latest_scap.release}")

Utility Functions

Standalone utility functions for ID parsing and data processing.

python
from cyber_trackr_helper import (
    parse_v_id,
    parse_sv_id,
    parse_srg_id,
    parse_cci_id,
    parse_rmf_control,
    get_control_family_name,
    normalize_search_term,
    fuzzy_match_score,
    filter_by_severity,
    group_by_severity
)

# ID parsing
v_num = parse_v_id("V-214518")  # Returns: 214518
sv_parsed = parse_sv_id("SV-214518r997541_rule")
# Returns: {'number': 214518, 'revision': 997541, 'type': 'rule'}

rmf_parsed = parse_rmf_control("AC-2 (1)")
# Returns: {'family': 'AC', 'number': 2, 'enhancement': 1}

# Text utilities
normalized = normalize_search_term("Red Hat")  # Returns: "redhat"
score = fuzzy_match_score("RedHat", "Red_Hat_Enterprise_Linux")  # Returns: 0.67

# Control family names
family_name = get_control_family_name('AC')  # Returns: "Access Control"

# Severity utilities
high_only = filter_by_severity(requirements, ['high'])
grouped = group_by_severity(requirements)
# Returns: {'high': [...], 'medium': [...], 'low': [...]}

Performance Tips

  1. Enable caching for repeated operations

    python
    helper = CyberTrackrHelper(enable_cache=True, cache_ttl=3600)
  2. Use fuzzy search for user input

    python
    results = helper.fuzzy_search_documents(user_input, threshold=0.7)
  3. Batch operations with progress callbacks

    python
    complete = helper.fetch_complete_stig(name, ver, rel, progress_callback=print_progress)
  4. Filter by severity to reduce data

    python
    high_only = helper.get_high_severity_requirements(name, ver, rel)

See Also

Released under the Apache-2.0 License.