Source code for yaml_tools.templates
"""
Template bits for generating SSG-style controls in YAML.
"""
import re
from typing import Any, Dict, List
from .utils import pystache_render
PROFILES: List = ['LOW', 'MODERATE', 'HIGH', 'PRIVACY']
IMPACT_LVLS: List = ['low', 'moderate', 'high']
CTL_FIELD_MAP: Dict = {
'id': 'Control Identifier',
'name': 'Control (or Control Enhancement) Name',
'notes': 'Discussion',
'description': 'Control Text',
'status': 'pending',
'levels': None,
}
PREAMBLE: str = '''
policy: NIST
title: Configuration Recommendations for Yocto- and OpenEmbedded-based Linux Variants
id: nist_openembedded
version: Revision 5
source: https://csrc.nist.gov/files/pubs/sp/800/53/r5/upd1/final/docs/sp800-53r5-control-catalog.xlsx
levels:
- id: low
- id: moderate
- id: high
'''
ID_TEMPLATE: str = '''
controls:
- id: {{caps}}
status: {{status}}
notes: |-
{{notes}}
rules: []
description: |-
{{description}}
title: >-
{{caps}} - {{name}}
levels: []
'''
[docs]
def generate_control(context: Dict) -> Any:
"""
Render an ID template string given a context dict.
"""
id_yaml = pystache_render(ID_TEMPLATE, context)
return id_yaml