Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 563629578
  • Loading branch information
Chronicle Team authored and bumblebee211196 committed Sep 8, 2023
1 parent 528580b commit d53345c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"AUSTRALIA-SOUTHEAST1",
"EUROPE",
"EUROPE-WEST2",
"EUROPE-WEST6",
"ME-WEST1",
"US",
]
Expand Down
11 changes: 11 additions & 0 deletions parsers/commands/submit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@


@click.command(name="submit_parser", help="[New]Submit a new parser")
@click.option(
"--skip_validation_on_no_logs",
is_flag=True,
help="Skip validation if no logs are found",
default=False,
)
@click.argument("project_id", required=True, default="")
@click.argument("customer_id", required=True, default="")
@click.argument("log_type", required=True, default="")
Expand All @@ -45,6 +51,7 @@
@options.v2_option
@exception_handler.catch_exception()
def submit_parser(
skip_validation_on_no_logs: bool,
v2: bool,
credential_file: str,
verbose: bool,
Expand All @@ -58,6 +65,8 @@ def submit_parser(
"""Submit a new parser.
Args:
skip_validation_on_no_logs (bool): Option to skip validation if no logs are
are found.
v2 (bool): Option for enabling v2 commands.
credential_file (AnyStr): Path of Service Account JSON.
verbose (bool): Option for printing verbose output to console.
Expand Down Expand Up @@ -121,6 +130,8 @@ def submit_parser(
parser_constants.KEY_CREATOR: {
parser_constants.KEY_AUTHOR: author
},
parser_constants.KEY_VALIDATED_ON_EMPTY_LOGS: (
skip_validation_on_no_logs),
}

submit_parser_url = url.get_dataplane_url(
Expand Down
58 changes: 57 additions & 1 deletion parsers/commands/submit_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,63 @@ def test_submit_parser(
},
"creator": {
"author": "test_author"
}
},
"validatedOnEmptyLogs": False,
}, timeout=url.HTTP_REQUEST_TIMEOUT_IN_SECS)


@mock.patch(
"common.chronicle_auth.initialize_dataplane_http_session"
)
@mock.patch("parsers.url.get_dataplane_url")
def test_submit_parser_skip_validation(
mock_get_dataplane_url: mock.MagicMock,
mock_http_session: mock.MagicMock,
test_data_submit_parser: mock_test_utility.MockResponse) -> None:
"""Test case to check success response.
Args:
mock_get_dataplane_url (mock.MagicMock): Mock object
mock_http_session (mock.MagicMock): Mock object
test_data_submit_parser (mock_test_utility.MockResponse): Test input data
"""
create_temp_config_file(TEMP_SUBMIT_CONF_FILE, "test_config")
mock_get_dataplane_url.return_value = SUBMIT_URL
client = mock.Mock()
client.request.side_effect = [test_data_submit_parser]
mock_http_session.return_value = client
result = runner.invoke(submit_parser_command.submit_parser, [
"test_project", "test_instance", "test_log_type",
TEMP_SUBMIT_CONF_FILE, "test_author",
"--v2", "--skip_validation_on_no_logs",
"--env", "PROD", "--region", "US"])
assert """Submitting Parser...
Parser Details:
Parser ID: test_parser_id
Log type: test_log_type
State: INACTIVE
Type: CUSTOM
Author: test_author
Validation Report ID: -
Create Time: 2023-01-01T00:00:00.000000Z
============================================================
""" == result.output
mock_get_dataplane_url.assert_called_once_with(
"US", "submit_parser", "prod", RESOURCES)
mock_http_session.return_value.request.assert_called_once_with(
"POST", SUBMIT_URL, json={
"cbn": "dGVzdF9jb25maWc=",
"type": "CUSTOM",
"changelogs": {
"entries": []
},
"creator": {
"author": "test_author"
},
"validatedOnEmptyLogs": True,
}, timeout=url.HTTP_REQUEST_TIMEOUT_IN_SECS)


Expand Down
1 change: 1 addition & 0 deletions parsers/constants/key_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
KEY_SUCCESSFULLY_NORMALIZED_LOG_COUNT = 'successfullyNormalizedLogCount'
KEY_TYPE = 'type'
KEY_VALIDATION_ERRORS = 'validationErrors'
KEY_VALIDATED_ON_EMPTY_LOGS = 'validatedOnEmptyLogs'
KEY_VALIDATION_REPORT = 'validationReport'
KEY_VALIDATION_REPORT_ID = 'validationReportID'
KEY_VALIDATION_REPORTS = 'validationReports'
Expand Down

0 comments on commit d53345c

Please sign in to comment.