Skip to content

Commit bc15ca0

Browse files
authored
Add evidence locker TOC (#71)
* Add evidence locker TOC * Replace os with pathlib in report.py * Temporarily remove mention of demo checks
1 parent c068982 commit bc15ca0

File tree

13 files changed

+224
-102
lines changed

13 files changed

+224
-102
lines changed

CHANGES.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,74 @@
1-
# 1.5.0 (2020-09-14)
1+
# [1.6.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.6.0)
2+
3+
- [ADDED] Check reports table of contents now appended to an evidence locker's README.
4+
- [ADDED] `ComplianceCheck.get_historical_evidence` supports historical evidence retrieval.
5+
6+
# [1.5.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.5.0)
27

38
- [ADDED] Remote locker push failure notifications were added.
49
- [ADDED] Logging for git locker operations was added.
510
- [ADDED] Notifier logging was added.
611
- [CHANGED] The file descriptor (stdout) notifier always notifies now.
712

8-
# 1.4.0 (2020-09-03)
13+
# [1.4.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.4.0)
914

1015
- [CHANGED] PagerDuty notifier can send alerts for a subset of the accreditation checks based on the config.
1116
- [ADDED] A warning for possible sensitive information contained within notifications was added.
1217

13-
# 1.3.0 (2020-09-01)
18+
# [1.3.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.3.0)
1419

1520
- [CHANGED] Simplified `controls.json` format. Original format is also supported.
1621
- [ADDED] Documentation for `controls.json` and check execution was added.
1722
- [ADDED] ControlDescriptor unit tests were added.
1823
- [FIXED] ComplianceFetcher session object is auto-closed now in tearDownClass.
1924

20-
# 1.2.7 (2020-08-28)
25+
# [1.2.7](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.7)
2126

2227
- [CHANGED] Removed PyYAML dependency to resolve downstream dependency issues.
2328
- [CHANGED] Removed Github.get_issue_template helper method.
2429

25-
# 1.2.6 (2020-08-28)
30+
# [1.2.6](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.6)
2631

2732
- [FIXED] ComplianceFetcher.session can now be reset.
2833

29-
# 1.2.5 (2020-08-26)
34+
# [1.2.5](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.5)
3035

3136
- [FIXED] Credentials section bug affecting the Slack notifier is squashed.
3237

33-
# 1.2.4 (2020-08-24)
38+
# [1.2.4](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.4)
3439

3540
- [CHANGED] Fetchers and checks that failed to load appear as errors in STDERR now.
3641

37-
# 1.2.3 (2020-08-18)
42+
# [1.2.3](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.3)
3843

3944
- [CHANGED] Github service `get_commit_details` now take `path` as an optional argument.
4045

41-
# 1.2.2 (2020-08-14)
46+
# [1.2.2](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.2)
4247

4348
- [FIXED] Github service branch protection method now returns "required_signatures" content.
4449

45-
# 1.2.1 (2020-08-12)
50+
# [1.2.1](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.1)
4651

4752
- [FIXED] Notifier `msg_` methods are now accurately found based on check `test_` method names.
4853

49-
# 1.2.0 (2020-08-11)
54+
# [1.2.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.2.0)
5055

5156
- [ADDED] Branch option to retrieving commit details from the Github service was added.
5257

53-
# 1.1.0 (2020-08-11)
58+
# [1.1.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.1.0)
5459

5560
- [ADDED] Repository details retrieval was added to Github service class.
5661
- [ADDED] Recent commit details retrieval was added to Github service class.
5762
- [ADDED] Repository branch protection details retrieval was added to Github service class.
5863

59-
# 1.0.2 (2020-07-28)
64+
# [1.0.2](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.0.2)
6065

6166
- [FIXED] Added PyYAML library as a dependency to resolve Github service issue.
6267

63-
# 1.0.1 (2020-07-27)
68+
# [1.0.1](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.0.1)
6469

6570
- [FIXED] Added external evidence as a valid evidence type to evidence map.
6671

67-
# 1.0.0 (2020-07-21)
72+
# [1.0.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.0.0)
6873

6974
- [ADDED] Made the Auditree Framework public.

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
graft templates

README.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,7 @@ This will update the files in `doc` with the latest documentation. These files s
9595

9696
## Try it
9797

98-
First, create an empty [credentials file][]:
99-
100-
```shell
101-
touch ~/.credentials
102-
```
103-
104-
Go to the demo checks and install required dependencies:
105-
106-
```shell
107-
cd doc/demo-checks
108-
pip install -r requirements.txt
109-
```
110-
111-
Run the fetchers:
112-
113-
```shell
114-
compliance --fetch -v --evidence=local -C setup.json
115-
```
116-
117-
And then run the checks of the demo accreditations:
118-
119-
```shell
120-
compliance --check demo.accreditation1,demo.accreditation2 --evidence=local -v -C setup.json
121-
```
122-
123-
See a more detailed [quick start guide][].
98+
Coming soon...
12499

125100
## Contribute
126101

compliance/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# limitations under the License.
1515
"""Compliance automation package."""
1616

17-
__version__ = '1.5.0'
17+
__version__ = '1.6.0'

compliance/check.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ def add_issue_if_diff(self, actual, expected, msg, as_warning=False):
286286
else:
287287
self.add_failures(msg, sorted(diff))
288288

289+
def get_historical_evidence(self, evidence_path, evidence_dt):
290+
"""
291+
Retrieve historical evidence from the locker and track as metadata.
292+
293+
:param evidence_path: the evidence path.
294+
:param evidence_dt: the evidence date.
295+
"""
296+
evidence = self.locker.get_evidence(evidence_path, True, evidence_dt)
297+
self.add_evidence_metadata(evidence_path, evidence_dt)
298+
return evidence
299+
289300
def add_evidence_metadata(self, evidence_path, evidence_dt=None):
290301
"""
291302
Add evidence metadata to the evidences property of each check.

compliance/locker.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
INDEX_FILE = 'index.json'
4242
DAY = 60 * 60 * 24
4343
AE_DEFAULT = 30 * DAY
44-
AE_EXEMPT = [INDEX_FILE, 'README.md', 'readme.md']
44+
READMES = ['README.md', 'readme.md', 'Readme.md']
45+
AE_EXEMPT = [INDEX_FILE] + READMES
4546

4647

4748
class Locker(object):
@@ -411,24 +412,27 @@ def get_file(self, filename):
411412
"""
412413
return os.path.join(self.local_path, filename)
413414

414-
def get_remote_location(self, filename, include_commit=True):
415+
def get_remote_location(self, filename, include_commit=True, sha=None):
415416
"""
416417
Provide the path for a file/commit SHA in the locker.
417418
418419
The file may or may not exist in the locker.
419420
420421
:param filename: the name of a file in the locker.
421-
:param include_commit: if the commit SHA should be included.
422+
:param include_commit: if the latest commit SHA should be included.
423+
:param sha: use this commit SHA; requires include_commit to be False.
422424
423425
:returns: the remote repository path to the filename provided.
424426
"""
425427
if not self.repo_url_with_creds:
426428
return os.path.join(self.local_path, filename)
427429

428-
ref = 'master'
430+
ref = self.branch
429431
if include_commit:
430432
ref = self.repo.head.commit.hexsha
431-
return f'{self.repo_url}/blob/{ref}/{filename}'
433+
elif not include_commit and sha:
434+
ref = sha
435+
return f'{self.repo_url}/blob/{ref}/{filename.strip("/")}'
432436

433437
def get_evidence(self, evidence_path, ignore_ttl=False, evidence_dt=None):
434438
"""
@@ -594,6 +598,22 @@ def add_content_to_locker(self, content, folder='', filename=None):
594598
f.write(content)
595599
self.repo.index.add([results_file])
596600

601+
def get_content_from_locker(self, folder='', filename=None):
602+
"""
603+
Read non-evidence related content from the local locker.
604+
605+
:param folder: the folder in the local locker to get the content from.
606+
:param filename: the name of the file in the local locker.
607+
"""
608+
if not filename:
609+
raise ValueError('Filename cannot be empty.')
610+
file_path = os.path.join(self.local_path, folder, filename)
611+
content = None
612+
if os.path.exists(file_path):
613+
with open(file_path) as f:
614+
content = f.read()
615+
return content
616+
597617
def get_reports_metadata(self):
598618
"""
599619
Provide all metadata related to reports as a dictionary.

compliance/notify.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ def _get_report_links(self, test_desc, link_format=None):
158158

159159
return [
160160
link_format.format(
161-
url=test_obj.locker.get_remote_location(
162-
report.path, include_commit=True
163-
),
161+
url=test_obj.locker.get_remote_location(report.path),
164162
name=report.name
165163
) for report in test_obj.reports
166164
]

0 commit comments

Comments
 (0)