Skip to content

Commit c068982

Browse files
authored
Add locker and notifier logging (#69)
- Add locker git ops logging - Add notifier logging - Ensure STDOUT notifier always runs - Add remote locker push failure notification behavior - Fix links in CONTRIBUTING.md - Fix formatting and content in coding standards rst - Update notifier unit tests
1 parent 14e9e63 commit c068982

File tree

13 files changed

+332
-141
lines changed

13 files changed

+332
-141
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.5.0 (2020-09-14)
2+
3+
- [ADDED] Remote locker push failure notifications were added.
4+
- [ADDED] Logging for git locker operations was added.
5+
- [ADDED] Notifier logging was added.
6+
- [CHANGED] The file descriptor (stdout) notifier always notifies now.
7+
18
# 1.4.0 (2020-09-03)
29

310
- [CHANGED] PagerDuty notifier can send alerts for a subset of the accreditation checks based on the config.

CONTRIBUTING.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Contributing
22

3-
If you want to add to the framework, please familiarise yourself with the code & our [Coding Standards][]. Make a fork of the repository & file a Pull Request from your fork with the changes. You will need to click the checkbox in the template to show you agree to the [Developer Certificate of Origin](../blob/master/DCO1.1.txt).
3+
If you want to add to the framework, please familiarize yourself with the code & our [Coding Standards][]. Make a fork of the repository & file a Pull Request from your fork with the changes. You will need to click the checkbox in the template to show you agree to the [Developer Certificate of Origin](https://github.com/ComplianceAsCode/auditree-framework/blob/main/DCO1.1.txt).
44

55
If you make **regular & substantial contributions** to Auditree, you may want to become a collaborator. This means you can approve pull requests (though not your own) & create releases of the tool. Please [file an issue][new collab] to request collaborator access. A collaborator supports the project, ensuring coding standards are met & best practices are followed in contributed code, cutting & documenting releases, promoting the project etc.
66

77
## Fetchers & checks
88

9-
If you would like to contribute checks, either add them via PR to[Arboretum][] or push to your own repository & let us know of its existence.
9+
If you would like to contribute checks, either add them via PR to [Arboretum][] or push to your own repository & let us know of its existence.
1010

1111
There are some guidelines to follow when making a common fetcher or check:
1212

@@ -77,9 +77,8 @@ example `[ADDED]`, `[CHANGED]`, etc.
7777

7878
[semver]: https://semver.org/
7979
[changelog]: https://keepachangelog.com/en/1.0.0/#how
80-
8180
[Arboretum]: https://github.com/ComplianceAsCode/auditree-arboretum
82-
[Coding Standards]: https://github.com/ComplianceAsCode/auditree-framework/blob/master/doc/coding-standards.rst
81+
[Coding Standards]: https://complianceascode.github.io/auditree-framework/coding-standards.html
8382
[flake8]: https://gitlab.com/pycqa/flake8
8483
[new collab]: https://github.com/ComplianceAsCode/auditree-framework/issues/new?template=new-collaborator.md
8584
[yapf]: https://github.com/google/yapf

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.4.0'
17+
__version__ = '1.5.0'

compliance/locker.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
format_json, get_sha256_hash, parse_dot_key
3131
)
3232
from compliance.utils.exceptions import (
33-
EvidenceNotFoundError, HistoricalEvidenceNotFoundError, StaleEvidenceError
33+
EvidenceNotFoundError,
34+
HistoricalEvidenceNotFoundError,
35+
LockerPushError,
36+
StaleEvidenceError
3437
)
3538

3639
import git
@@ -180,11 +183,10 @@ def init(self):
180183

181184
def logger_init_msgs(self):
182185
"""Log locker initialization information."""
183-
self.logger.info(f'Local locker location is {self.local_path}')
184186
gpgsign = self.gitconfig.get('commit', {}).get('gpgsign')
185187
if self._do_push and not gpgsign:
186188
self.logger.warning(
187-
'Commits will not be cryptographically signed, best '
189+
'Commits may not be cryptographically signed, best '
188190
'practice is to set gitconfig.commit.gpgsign to true '
189191
'in your locker configuration.'
190192
)
@@ -523,8 +525,12 @@ def validate(self, evidence, ignore_ttl=False):
523525
def checkout(self):
524526
"""Pull (clone) the remote repository to the local git repository."""
525527
if os.path.isdir(os.path.join(self.local_path, '.git')):
528+
self.logger.info(f'Using locker found in {self.local_path}...')
526529
self.repo = git.Repo(self.local_path)
527530
else:
531+
self.logger.info(
532+
f'Cloning locker {self.repo_url} to {self.local_path}...'
533+
)
528534
self.repo = git.Repo.clone_from(
529535
self.repo_url_with_creds, self.local_path, branch=self.branch
530536
)
@@ -550,6 +556,9 @@ def checkin(self, message=None):
550556
f'Files updated at local time {time.ctime(time.time())}'
551557
f'\n\n{updated_files}'
552558
)
559+
self.logger.info(
560+
f'Committing changes to local locker in {self.local_path}...'
561+
)
553562
try:
554563
diff = self.repo.index.diff('HEAD')
555564
if len(diff) > 0:
@@ -560,7 +569,12 @@ def checkin(self, message=None):
560569
def push(self):
561570
"""Push the local git repository to the remote repository."""
562571
if self._do_push:
563-
self.repo.remotes[0].push()
572+
self.logger.info(
573+
f'Pushing local locker to remote repo {self.repo_url}...'
574+
)
575+
push_info = self.repo.remotes[0].push()[0]
576+
if push_info.flags >= git.remote.PushInfo.ERROR:
577+
raise LockerPushError(push_info)
564578

565579
def add_content_to_locker(self, content, folder='', filename=None):
566580
"""
@@ -694,7 +708,7 @@ def __enter__(self):
694708

695709
def __exit__(self, exc_type, exc_val, exc_tb):
696710
"""
697-
Handle local locker checkin and remote push if applicable.
711+
Handle local locker check-in and remote push if applicable.
698712
699713
Log an exception if raised, commit the files to the repo and if
700714
configured push it up to the `repo_url`.
@@ -708,8 +722,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
708722

709723
def _repo_init(self):
710724
if os.path.isdir(os.path.join(self.local_path, '.git')):
725+
self.logger.info(f'Using locker found in {self.local_path}...')
711726
self.repo = git.Repo(self.local_path)
712727
else:
728+
self.logger.info(f'Creating locker in {self.local_path}...')
713729
self.repo = git.Repo.init(self.local_path)
714730
self.init_config()
715731

0 commit comments

Comments
 (0)