Skip to content

Commit

Permalink
Separate json from json_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
terwilligergreen committed Oct 31, 2015
1 parent 723cc9f commit 43aadb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ organizations.\n'
>>> c.related_controls
'AT-2,AT-4,PL-4,PS-7,SA-3,SA-12,SA-16'
>>> c.format('json')
{'description': 'The organization provides role-based security training to personnel with assigned security roles and responsibilities:\na. Before authorizing access to the information system or performing assigned duties;\nb. When required by information system changes; and\nc. [Assignment: organization-defined frequency] thereafter.', 'title': 'ROLE-BASED SECURITY TRAINING', 'responsible': 'organization', 'supplemental_guidance': 'Organizations determine the appropriate content of security training based on the assigned roles and responsibilities of individuals and the specific security requirements of organizations and the information systems to which personnel have authorized access. In addition, organizations provide enterprise architects, information system developers, software developers, acquisition/procurement officials, information system managers, system/network administrators, personnel conducting configuration management and auditing activities, personnel performing independent verification and validation activities, security control assessors, and other personnel having access to system-level software, adequate security-related technical training specifically tailored for their assigned duties. Comprehensive role-based training addresses management, operational, and technical roles and responsibilities covering physical, personnel, and technical safeguards and countermeasures. Such training can include for example, policies, procedures, tools, and artifacts for the organizational security roles defined. Organizations also provide the training necessary for individuals to carry out their responsibilities related to operations and supply chain security within the context of organizational information security programs. Role-based security training also applies to contractors providing services to federal agencies.', 'id': 'AT-3', 'description_intro': 'The organization provides role-based security training to personnel with assigned security roles and responsibilities:', 'description_sections': ['a. Before authorizing access to the information system or performing assigned duties;', 'b. When required by information system changes; and', 'c. [Assignment: organization-defined frequency] thereafter.']}
>>> print(c.format('json'))
{"description": "The organization provides role-based security training to personnel with assigned security roles and responsibilities:\na. Before authorizing access to the information system or performing assigned duties;\nb. When required by information system changes; and\nc. [Assignment: organization-defined frequency] thereafter.", "title": "ROLE-BASED SECURITY TRAINING", "responsible": "organization", "supplemental_guidance": "Organizations determine the appropriate content of security training based on the assigned roles and responsibilities of individuals and the specific security requirements of organizations and the information systems to which personnel have authorized access. In addition, organizations provide enterprise architects, information system developers, software developers, acquisition/procurement officials, information system managers, system/network administrators, personnel conducting configuration management and auditing activities, personnel performing independent verification and validation activities, security control assessors, and other personnel having access to system-level software, adequate security-related technical training specifically tailored for their assigned duties. Comprehensive role-based training addresses management, operational, and technical roles and responsibilities covering physical, personnel, and technical safeguards and countermeasures. Such training can include for example, policies, procedures, tools, and artifacts for the organizational security roles defined. Organizations also provide the training necessary for individuals to carry out their responsibilities related to operations and supply chain security within the context of organizational information security programs. Role-based security training also applies to contractors providing services to federal agencies.", "id": "AT-3", "description_intro": "The organization provides role-based security training to personnel with assigned security roles and responsibilities:", "description_sections": ["a. Before authorizing access to the information system or performing assigned duties;", "b. When required by information system changes; and", "c. [Assignment: organization-defined frequency] thereafter."]}
>>> print(c.format('yaml'))
description: 'The organization provides role-based security training to personnel
with assigned security roles and responsibilities:
Expand Down
30 changes: 17 additions & 13 deletions compliancelib/seccontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, id):
self._load_control_from_xml()
# split description
self.set_description_sections()
self._get_control_json()
self._get_control_json_dict()

def _load_control_from_xml(self):
"load control detail from 800-53 xml using a pure python process"
Expand Down Expand Up @@ -151,28 +151,32 @@ def format(self, format):
# control format is not defined
return False

def _get_control_json_dict(self):
"produce json dict version of control detail"
self.json_dict = {}
self.json_dict['id'] = self.id
self.json_dict['title'] = self.title
self.json_dict['description'] = self.description
self.json_dict['description_intro'] = self.description_intro
self.json_dict['description_sections'] = self.description_sections
self.json_dict['responsible'] = self.responsible
self.json_dict['supplemental_guidance'] = self.supplemental_guidance
return self.json_dict
# To Do: needs test

def _get_control_json(self):
"produce json version of control detail"
self.json = {}
self.json['id'] = self.id
self.json['title'] = self.title
self.json['description'] = self.description
self.json['description_intro'] = self.description_intro
self.json['description_sections'] = self.description_sections
self.json['responsible'] = self.responsible
self.json['supplemental_guidance'] = self.supplemental_guidance
return self.json
# To Do: needs test
return json.dumps(self.json_dict)

def _get_control_yaml(self):
"produce yaml version of control detail"
return yaml.safe_dump(self.json, allow_unicode=True, default_flow_style=False, line_break="\n",
return yaml.safe_dump(self.json_dict, allow_unicode=True, default_flow_style=False, line_break="\n",
indent=4, explicit_start=False, explicit_end=False,)

def _get_control_control_masonry(self):
"produce control masonry yaml version of control detail"
# get json version
c = self._get_control_json()
c = self._get_control_json_dict()
# replace ":" with ":"
description_sections = []
for section in self.description_sections:
Expand Down
10 changes: 1 addition & 9 deletions compliancelib/tests/test_seccontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,7 @@ def test_generate_yaml(self):
# To do - this test does not work
id = "AT-3"
c = SecControl(id)
self.assertTrue(c.format('yaml')[0:1] == "AT")

c_yaml = c.format('yaml')
print c_yaml
# self.assertTrue(c_yaml[c.id]["id"] == c.id)
self.assertTrue(c_yaml[c.id]["title"] == c.title)
self.assertTrue(c_yaml[c.id]["description"] == c.description)
self.assertTrue(c_yaml[c.id]["responsible"] == c.responsible)
self.assertTrue(c_yaml[c.id]["supplemental_guidance"] == c.supplemental_guidance)
self.assertTrue(c.format('yaml')) == "description: 'The organization provides role-based security training to personnel\n with assigned security roles and responsibilities:\n\n a. Before authorizing access to the information system or performing assigned\n duties;\n\n b. When required by information system changes; and\n\n c. [Assignment: organization-defined frequency] thereafter.'\ndescription_intro: 'The organization provides role-based security training to personnel\n with assigned security roles and responsibilities:'\ndescription_sections:\n- a. Before authorizing access to the information system or performing assigned duties;\n- b. When required by information system changes; and\n- 'c. [Assignment: organization-defined frequency] thereafter.'\nid: AT-3\nresponsible: organization\nsupplemental_guidance: Organizations determine the appropriate content of security\n training based on the assigned roles and responsibilities of individuals and the\n specific security requirements of organizations and the information systems to\n which personnel have authorized access. In addition, organizations provide enterprise\n architects, information system developers, software developers, acquisition/procurement\n officials, information system managers, system/network administrators, personnel\n conducting configuration management and auditing activities, personnel performing\n independent verification and validation activities, security control assessors,\n and other personnel having access to system-level software, adequate security-related\n technical training specifically tailored for their assigned duties. Comprehensive\n role-based training addresses management, operational, and technical roles and\n responsibilities covering physical, personnel, and technical safeguards and countermeasures.\n Such training can include for example, policies, procedures, tools, and artifacts\n for the organizational security roles defined. Organizations also provide the\n training necessary for individuals to carry out their responsibilities related\n to operations and supply chain security within the context of organizational information\n security programs. Role-based security training also applies to contractors providing\n services to federal agencies.\ntitle: ROLE-BASED SECURITY TRAINING\n"

# test for other (not organization, information system, or [Withdrawn)

Expand Down

0 comments on commit 43aadb4

Please sign in to comment.