Skip to content

Commit 8570b5f

Browse files
authored
Add filtered content flag and clone logging (#112)
- Add filtered content flag - Set content flags (including binary content) on metadata - Add Clone duration logging
1 parent b0b9738 commit 8570b5f

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [1.14.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.14.0)
2+
3+
- [ADDED] The `filtered_content` attribute has been added to `RawEvidence`.
4+
- [ADDED] Locker clone duration logging has been added.
5+
- [FIXED] The `binary_content` attribute on raw evidence is retained as metadata now.
6+
- [FIXED] All partitioned evidence defined via constructor correctly retains attributes now.
7+
18
# [1.13.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.13.0)
29

310
- [ADDED] Configurable shallow cloning of locker is now supported.

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.13.0'
17+
__version__ = '1.14.0'

compliance/evidence.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
DAY = HOUR * 24
3838
YEAR = DAY * 365
3939

40+
CONTENT_FLAGS = ['binary_content', 'filtered_content']
41+
4042
LazyLoader = namedtuple('LazyLoader', 'path ev_class')
4143

4244

@@ -66,11 +68,21 @@ def __init__(self, name, category, ttl=DAY, description='', **kwargs):
6668

6769
@classmethod
6870
def from_evidence(cls, evidence):
71+
kwargs = {}
72+
for content_flag in CONTENT_FLAGS:
73+
if hasattr(evidence, content_flag):
74+
kwargs[content_flag] = getattr(evidence, content_flag)
75+
if hasattr(evidence, 'part_fields') or hasattr(evidence, 'part_root'):
76+
kwargs['partition'] = {
77+
'fields': getattr(evidence, 'part_fields', None),
78+
'root': getattr(evidence, 'part_root', None)
79+
}
6980
new_evidence = cls(
7081
evidence.name,
7182
evidence.category,
7283
evidence.ttl,
73-
evidence.description
84+
evidence.description,
85+
**kwargs
7486
)
7587
if evidence.content:
7688
new_evidence.set_content(evidence.content)
@@ -144,6 +156,7 @@ def __init__(self, *args, **kwargs):
144156
self.part_fields = partition.get('fields')
145157
self.part_root = partition.get('root')
146158
self.binary_content = kwargs.get('binary_content', False)
159+
self.filtered_content = kwargs.get('filtered_content', False)
147160

148161
@property
149162
def rootdir(self):

compliance/locker.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from urllib.parse import urlparse
2727

2828
from compliance.config import get_config
29-
from compliance.evidence import TmpEvidence, get_evidence_class
29+
from compliance.evidence import CONTENT_FLAGS, TmpEvidence, get_evidence_class
3030
from compliance.utils.data_parse import (
3131
format_json, get_sha256_hash, parse_dot_key
3232
)
@@ -302,6 +302,9 @@ def index(self, evidence, checks=None, evidence_used=None):
302302
repo_files.append(self.get_file(evidence.path))
303303
if tombstones:
304304
metadata[evidence.name]['tombstones'] = tombstones
305+
for content_flag in CONTENT_FLAGS:
306+
if getattr(evidence, content_flag, False):
307+
metadata[evidence.name][content_flag] = True
305308
if checks is not None:
306309
metadata[evidence.name]['checks'] = checks
307310
if evidence_used is not None:
@@ -575,16 +578,20 @@ def get_locker_repo(self, locker='evidence locker'):
575578
)
576579
kwargs = {'branch': self.branch}
577580
shallow_days = get_config().get('locker.shallow_days', -1)
581+
addl_msg = None
578582
if shallow_days >= 0:
579583
since_dt = dt.utcnow() - timedelta(days=shallow_days + 1)
580584
since = since_dt.strftime('%Y/%m/%d')
581585
kwargs['shallow_since'] = since
582-
self.logger.info(
583-
f'{locker.title()} contains commits since {since}...'
584-
)
586+
addl_msg = f'{locker.title()} contains commits since {since}'
587+
start = time.perf_counter()
585588
self.repo = git.Repo.clone_from(
586589
self.repo_url_with_creds, self.local_path, **kwargs
587590
)
591+
duration = time.perf_counter() - start
592+
self.logger.info(f'{locker.title()} cloned in {duration:.3f}s')
593+
if addl_msg:
594+
self.logger.info(addl_msg)
588595

589596
def init_config(self):
590597
"""Apply the git configuration."""
@@ -815,7 +822,9 @@ def _get_evidence(self, evidence_path, ignore_ttl=False, evidence_dt=None):
815822
partition={
816823
'fields': metadata.get('partition_fields'),
817824
'root': metadata.get('partition_root')
818-
}
825+
},
826+
binary_content=metadata.get('binary_content', False),
827+
filtered_content=metadata.get('filtered_content', False)
819828
)
820829
except TypeError:
821830
ev_dt_str = (evidence_dt or dt.utcnow()).strftime('%Y-%m-%d')

0 commit comments

Comments
 (0)