diff --git a/common/options.py b/common/options.py index e7b39ea..f2a26d9 100644 --- a/common/options.py +++ b/common/options.py @@ -23,6 +23,7 @@ "AUSTRALIA-SOUTHEAST1", "EUROPE", "EUROPE-WEST2", + "EUROPE-WEST6", "ME-WEST1", "US", ] diff --git a/parsers/commands/submit_parser.py b/parsers/commands/submit_parser.py index efb2b8d..8d7004a 100644 --- a/parsers/commands/submit_parser.py +++ b/parsers/commands/submit_parser.py @@ -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="") @@ -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, @@ -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. @@ -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( diff --git a/parsers/commands/submit_parser_test.py b/parsers/commands/submit_parser_test.py index d84c72a..3a14957 100644 --- a/parsers/commands/submit_parser_test.py +++ b/parsers/commands/submit_parser_test.py @@ -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) diff --git a/parsers/constants/key_constants.py b/parsers/constants/key_constants.py index 919c57c..8be0bb2 100644 --- a/parsers/constants/key_constants.py +++ b/parsers/constants/key_constants.py @@ -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'