scanner-cli 0.1.0rc7__py3-none-any.whl → 0.1.0rc8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: scanner-cli
3
- Version: 0.1.0rc7
3
+ Version: 0.1.0rc8
4
4
  Summary: Python command-line interface for Scanner API
5
5
  Author: Scanner, Inc.
6
6
  Author-email: support@scanner.dev
@@ -9,7 +9,6 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.10
10
10
  Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
12
- Classifier: Programming Language :: Python :: 3.13
13
12
  Requires-Dist: PyYAML (>=6.0.2,<7.0.0)
14
13
  Requires-Dist: click (>=8.1.7,<9.0.0)
15
14
  Requires-Dist: scanner-client (>=0.1.0rc8,<0.2.0)
@@ -0,0 +1,9 @@
1
+ src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ src/cli.py,sha256=1in8DDTlhYNXaaxvLwdYWiNHBr4VMnTBIzq59fLkhXc,9100
3
+ src/migrate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ src/migrate/elastic.py,sha256=y_cn_3Y_t8NHwYcpAQQLfnCkEBSULoU_vxxGwk47QAc,8681
5
+ src/sync.py,sha256=WABCtvI6fpwXNJKo9lzafw3HkGYljpGjre5ywKnO0yA,7738
6
+ scanner_cli-0.1.0rc8.dist-info/METADATA,sha256=Dch4WTSbmhU152rnEBOAFDh1eYRbNlMXBi-vK3Qgd10,5890
7
+ scanner_cli-0.1.0rc8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
8
+ scanner_cli-0.1.0rc8.dist-info/entry_points.txt,sha256=vqXMrIG6N6pY66bNf0y-gbUxbU8v5dXvuL3mV832Fh8,43
9
+ scanner_cli-0.1.0rc8.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
src/cli.py CHANGED
@@ -114,7 +114,7 @@ def cli():
114
114
  @cli.command()
115
115
  @_default_click_options
116
116
  def validate(api_url: str, api_key: str, file_paths: str, directories: str, recursive: bool):
117
- """ Validate detection rules """
117
+ """ Validate detection rule files """
118
118
  _validate_default_options(api_url, api_key, file_paths, directories)
119
119
 
120
120
  scanner_client = Scanner(api_url, api_key)
@@ -129,19 +129,22 @@ def validate(api_url: str, api_key: str, file_paths: str, directories: str, recu
129
129
  result = scanner_client.detection_rule_yaml.validate(file)
130
130
 
131
131
  if result.is_valid:
132
- click.echo(f"{file}: " + click.style("Valid", fg="green"))
132
+ click.echo(f"{file}: " + click.style("OK", fg="green"))
133
133
  else:
134
134
  any_failures = True
135
135
  click.echo(f"{file}: " + click.style(f"{result.error}", fg="red"))
136
136
  except Exception as e:
137
137
  any_failures = True
138
- click.echo(f"{file}: " + click.style(e, fg="red"))
138
+ response = e.args[0]
139
+ click.echo(f"{file}: " + click.style(f"An exception occurred when attempting to validate file: {response.content}", fg="red"))
139
140
 
140
141
  if any_failures:
141
142
  # To make it so the CLI exits with a non-zero exit code
142
143
  raise click.ClickException(
143
- "validate failed for one or more files"
144
+ "`validate` failed for one or more files. See https://docs.scanner.dev/scanner/using-scanner/beta-features/detection-rules-as-code/writing-detection-rules for requirements."
144
145
  )
146
+ else:
147
+ click.secho("All specified detection rule files are valid. Use `run-tests` to run the detection rule tests.", bold=True)
145
148
 
146
149
 
147
150
  @cli.command()
@@ -155,36 +158,50 @@ def run_tests(api_url: str, api_key: str, file_paths: str, directories: str, rec
155
158
  files = _get_valid_files(file_paths, directories, recursive)
156
159
  click.echo(f'Running tests on {len(files)} {"file" if len(files) == 1 else "files"}')
157
160
 
158
- any_failures: bool = False
161
+ any_validation_errors: bool = False
162
+ any_test_failures: bool = False
159
163
 
160
164
  for file in files:
165
+ click.secho(f"{file}", bold=True)
161
166
  try:
162
- response = scanner_client.detection_rule_yaml.run_tests(file)
163
- results = response.results.to_dict()
167
+ # Check for validation errors
168
+ validation_result = scanner_client.detection_rule_yaml.validate(file)
169
+ if not validation_result.is_valid:
170
+ any_validation_errors = True
171
+ click.secho(f"Validation error: {validation_result.error}", fg="red")
172
+ click.echo("")
173
+ continue
174
+
175
+ # Run detection rule tests
176
+ run_tests_response = scanner_client.detection_rule_yaml.run_tests(file)
177
+ results = run_tests_response.results.to_dict()
164
178
 
165
- click.secho(f"{file}", bold=True)
166
179
  if len(results) == 0:
167
180
  click.secho("No tests found", fg="yellow")
168
181
  else:
169
- for name, status in response.results.to_dict().items():
182
+ for name, status in results.items():
170
183
  if status == "Passed":
171
- click.echo(f"{name}: " + click.style("Passed", fg="green"))
184
+ click.echo(f"{name}: " + click.style("OK", fg="green"))
172
185
  else:
173
- any_failures = True
174
- click.echo(f"{name}: " + click.style("Failed", fg="red"))
175
-
176
- click.echo("")
186
+ any_test_failures = True
187
+ click.echo(f"{name}: " + click.style("Test failed", fg="red"))
177
188
  except Exception as e:
178
- any_failures = True
179
- click.secho(f"{file}", bold=True)
180
- click.secho(e, fg="red")
181
- click.echo("")
189
+ any_test_failures = True
190
+ response = e.args[0]
191
+ click.secho(f"An exception occurred when attempting to run tests: {response.content}", fg="red")
182
192
 
183
- if any_failures:
193
+ click.echo("")
194
+
195
+ error_messages = []
196
+ if any_validation_errors:
197
+ error_messages.append("Validation failed for one or more files. See https://docs.scanner.dev/scanner/using-scanner/beta-features/detection-rules-as-code/writing-detection-rules for requirements.")
198
+
199
+ if any_test_failures:
200
+ error_messages.append("`run-tests` failed for one or more files. See https://docs.scanner.dev/scanner/using-scanner/beta-features/detection-rules-as-code/cli#failing-tests for more information.")
201
+
202
+ if error_messages:
184
203
  # To make it so the CLI exits with a non-zero exit code
185
- raise click.ClickException(
186
- "run-tests failed for one or more files"
187
- )
204
+ raise click.ClickException("\n".join(error_messages))
188
205
 
189
206
 
190
207
  @cli.command()
@@ -1,9 +0,0 @@
1
- src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- src/cli.py,sha256=z0MT8XdVjccgfYLhbkl2S4mjMiIqfG-LZzwnfVgJctM,7781
3
- src/migrate/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- src/migrate/elastic.py,sha256=y_cn_3Y_t8NHwYcpAQQLfnCkEBSULoU_vxxGwk47QAc,8681
5
- src/sync.py,sha256=WABCtvI6fpwXNJKo9lzafw3HkGYljpGjre5ywKnO0yA,7738
6
- scanner_cli-0.1.0rc7.dist-info/METADATA,sha256=bIzAcU3Dg2bt75c77WpdL6c1Y2CB7CgMvAUg7FNSLhY,5941
7
- scanner_cli-0.1.0rc7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
8
- scanner_cli-0.1.0rc7.dist-info/entry_points.txt,sha256=vqXMrIG6N6pY66bNf0y-gbUxbU8v5dXvuL3mV832Fh8,43
9
- scanner_cli-0.1.0rc7.dist-info/RECORD,,