Skip to content

Commit d53345c

Browse files
Chronicle Teambumblebee211196
authored andcommitted
No public description
PiperOrigin-RevId: 563629578
1 parent 528580b commit d53345c

4 files changed

Lines changed: 70 additions & 1 deletion

File tree

common/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"AUSTRALIA-SOUTHEAST1",
2424
"EUROPE",
2525
"EUROPE-WEST2",
26+
"EUROPE-WEST6",
2627
"ME-WEST1",
2728
"US",
2829
]

parsers/commands/submit_parser.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333

3434

3535
@click.command(name="submit_parser", help="[New]Submit a new parser")
36+
@click.option(
37+
"--skip_validation_on_no_logs",
38+
is_flag=True,
39+
help="Skip validation if no logs are found",
40+
default=False,
41+
)
3642
@click.argument("project_id", required=True, default="")
3743
@click.argument("customer_id", required=True, default="")
3844
@click.argument("log_type", required=True, default="")
@@ -45,6 +51,7 @@
4551
@options.v2_option
4652
@exception_handler.catch_exception()
4753
def submit_parser(
54+
skip_validation_on_no_logs: bool,
4855
v2: bool,
4956
credential_file: str,
5057
verbose: bool,
@@ -58,6 +65,8 @@ def submit_parser(
5865
"""Submit a new parser.
5966
6067
Args:
68+
skip_validation_on_no_logs (bool): Option to skip validation if no logs are
69+
are found.
6170
v2 (bool): Option for enabling v2 commands.
6271
credential_file (AnyStr): Path of Service Account JSON.
6372
verbose (bool): Option for printing verbose output to console.
@@ -121,6 +130,8 @@ def submit_parser(
121130
parser_constants.KEY_CREATOR: {
122131
parser_constants.KEY_AUTHOR: author
123132
},
133+
parser_constants.KEY_VALIDATED_ON_EMPTY_LOGS: (
134+
skip_validation_on_no_logs),
124135
}
125136

126137
submit_parser_url = url.get_dataplane_url(

parsers/commands/submit_parser_test.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,63 @@ def test_submit_parser(
8585
},
8686
"creator": {
8787
"author": "test_author"
88-
}
88+
},
89+
"validatedOnEmptyLogs": False,
90+
}, timeout=url.HTTP_REQUEST_TIMEOUT_IN_SECS)
91+
92+
93+
@mock.patch(
94+
"common.chronicle_auth.initialize_dataplane_http_session"
95+
)
96+
@mock.patch("parsers.url.get_dataplane_url")
97+
def test_submit_parser_skip_validation(
98+
mock_get_dataplane_url: mock.MagicMock,
99+
mock_http_session: mock.MagicMock,
100+
test_data_submit_parser: mock_test_utility.MockResponse) -> None:
101+
"""Test case to check success response.
102+
103+
Args:
104+
mock_get_dataplane_url (mock.MagicMock): Mock object
105+
mock_http_session (mock.MagicMock): Mock object
106+
test_data_submit_parser (mock_test_utility.MockResponse): Test input data
107+
"""
108+
create_temp_config_file(TEMP_SUBMIT_CONF_FILE, "test_config")
109+
mock_get_dataplane_url.return_value = SUBMIT_URL
110+
client = mock.Mock()
111+
client.request.side_effect = [test_data_submit_parser]
112+
mock_http_session.return_value = client
113+
result = runner.invoke(submit_parser_command.submit_parser, [
114+
"test_project", "test_instance", "test_log_type",
115+
TEMP_SUBMIT_CONF_FILE, "test_author",
116+
"--v2", "--skip_validation_on_no_logs",
117+
"--env", "PROD", "--region", "US"])
118+
assert """Submitting Parser...
119+
120+
Parser Details:
121+
Parser ID: test_parser_id
122+
Log type: test_log_type
123+
State: INACTIVE
124+
Type: CUSTOM
125+
Author: test_author
126+
Validation Report ID: -
127+
Create Time: 2023-01-01T00:00:00.000000Z
128+
129+
============================================================
130+
131+
""" == result.output
132+
mock_get_dataplane_url.assert_called_once_with(
133+
"US", "submit_parser", "prod", RESOURCES)
134+
mock_http_session.return_value.request.assert_called_once_with(
135+
"POST", SUBMIT_URL, json={
136+
"cbn": "dGVzdF9jb25maWc=",
137+
"type": "CUSTOM",
138+
"changelogs": {
139+
"entries": []
140+
},
141+
"creator": {
142+
"author": "test_author"
143+
},
144+
"validatedOnEmptyLogs": True,
89145
}, timeout=url.HTTP_REQUEST_TIMEOUT_IN_SECS)
90146

91147

parsers/constants/key_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
KEY_SUCCESSFULLY_NORMALIZED_LOG_COUNT = 'successfullyNormalizedLogCount'
9797
KEY_TYPE = 'type'
9898
KEY_VALIDATION_ERRORS = 'validationErrors'
99+
KEY_VALIDATED_ON_EMPTY_LOGS = 'validatedOnEmptyLogs'
99100
KEY_VALIDATION_REPORT = 'validationReport'
100101
KEY_VALIDATION_REPORT_ID = 'validationReportID'
101102
KEY_VALIDATION_REPORTS = 'validationReports'

0 commit comments

Comments
 (0)