File tree 5 files changed +38
-2
lines changed
5 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
9
9
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.
10
10
11
+ ## 0.4.4 - 2020-04-01
12
+
13
+ ###Added
14
+
15
+ - Added message to STDERR when no results are found
16
+
11
17
###Fixed
12
18
13
19
- Add milliseconds to end timestamp, to represent end of day with milliseconds precision.
14
20
21
+ ## Unreleased
22
+
15
23
## 0.4.3 - 2020-03-17
16
24
17
25
### Added
Original file line number Diff line number Diff line change 1
- __version__ = "0.4.3 "
1
+ __version__ = "0.4.4 "
Original file line number Diff line number Diff line change 15
15
from code42cli .securitydata .cursor_store import FileEventCursorStore
16
16
from code42cli .securitydata .logger_factory import get_error_logger
17
17
from code42cli .securitydata .options import ExposureType as ExposureTypeOptions
18
- from code42cli .util import print_error , print_bold , is_interactive
18
+ from code42cli .util import print_error , print_bold , is_interactive , print_to_stderr
19
19
20
20
_EXCEPTIONS_OCCURRED = False
21
+ _TOTAL_EVENTS = 0
21
22
22
23
23
24
def extract (output_logger , args ):
@@ -142,6 +143,8 @@ def handle_error(exception):
142
143
def handle_response (response ):
143
144
response_dict = json .loads (response .text )
144
145
events = response_dict .get (u"fileEvents" )
146
+ global _TOTAL_EVENTS
147
+ _TOTAL_EVENTS += len (events )
145
148
for event in events :
146
149
output_logger .info (event )
147
150
@@ -170,6 +173,9 @@ def _verify_compatibility_with_advanced_query(key, val):
170
173
def _handle_result ():
171
174
if is_interactive () and _EXCEPTIONS_OCCURRED :
172
175
print_error (u"View exceptions that occurred at [HOME]/.code42cli/log/code42_errors." )
176
+ global _TOTAL_EVENTS
177
+ if not _TOTAL_EVENTS :
178
+ print_to_stderr (u"No results found\n " )
173
179
174
180
175
181
def _try_append_exposure_types_filter (filters , args ):
Original file line number Diff line number Diff line change @@ -70,3 +70,7 @@ def get_url_parts(url_str):
70
70
if len (parts ) > 1 and parts [1 ] != u"" :
71
71
port = int (parts [1 ])
72
72
return parts [0 ], port
73
+
74
+
75
+ def print_to_stderr (error_text ):
76
+ sys .stderr .write (error_text )
Original file line number Diff line number Diff line change @@ -511,3 +511,21 @@ def sdk_side_effect(self, *args):
511
511
512
512
extraction_module .extract (logger , namespace_with_begin )
513
513
assert extraction_module ._EXCEPTIONS_OCCURRED
514
+
515
+
516
+ def test_extract_when_no_results_are_found_prints_error_to_stderr (
517
+ mocker , logger , namespace_with_begin , extractor
518
+ ):
519
+ mock_error = mocker .patch ("code42cli.securitydata.extraction.print_to_stderr" )
520
+ extraction_module ._TOTAL_EVENTS = 0
521
+ extraction_module .extract (logger , namespace_with_begin )
522
+ assert mock_error .call_count
523
+
524
+
525
+ def test_extract_when_results_are_found_does_not_print_error_to_stderr (
526
+ mocker , logger , namespace_with_begin , extractor
527
+ ):
528
+ mock_error = mocker .patch ("code42cli.securitydata.extraction.print_to_stderr" )
529
+ extraction_module ._TOTAL_EVENTS = 1
530
+ extraction_module .extract (logger , namespace_with_begin )
531
+ assert not mock_error .call_count
You can’t perform that action at this time.
0 commit comments