Skip to content

Commit 28221b4

Browse files
docs: update api reference documentation (#891)
This PR updates API reference documentation as below - add missing function implementation and its params. - correcting parameters doc for some functions - add documentation for cim-compliance-report Ref: https://splunk.atlassian.net/browse/ADDON-75003
1 parent 5cf1bd4 commit 28221b4

29 files changed

+424
-146
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CimComplianceReport
2+
3+
::: pytest_splunk_addon.cim_compliance
4+
handler: python
5+
6+
## CIMReportGenerator
7+
8+
::: pytest_splunk_addon.cim_compliance.cim_report_generator
9+
handler: python
10+
11+
12+
## MarkDownReport
13+
14+
::: pytest_splunk_addon.cim_compliance.markdown_report
15+
handler: python
16+
17+
18+
## MarkDownTable
19+
20+
::: pytest_splunk_addon.cim_compliance.markdown_table
21+
handler: python

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ nav:
7474
- AppTestGenerator: "api_reference/app_test_generator.md"
7575
- DataGenerator: "api_reference/sample_generation.md"
7676
- EventIngestor: "api_reference/event_ingestion.md"
77+
- CimComplianceReport: "api_reference/cim_compliance_report.md"
7778
- Contributing: "contributing.md"
7879
- Troubleshooting: "troubleshoot.md"

pytest_splunk_addon/addon_parser/fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Field(object):
2828
2929
* name (str): name of the field
3030
* type (str): Field type. Supported [required, conditional, optional]
31+
* multi_value (bool): True if field is multi value field
3132
* expected_values (list): The field should have this expected values
3233
* negative_values (list): The field should not have negative values
3334
* condition (spl): The field should only be checked if the condition satisfies

pytest_splunk_addon/addon_parser/props_parser.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ def _get_extract_fields(self, name: str, value: str):
182182
EXTRACT-one = regex with (?<capturing_group>.*)
183183
184184
Args:
185-
name: key in the configuration settings
186-
value: value of the respective name in the configuration
185+
name (str): key in the configuration settings
186+
value (str): value of the respective name in the configuration
187187
188188
Regex:
189189
Parse the fields from a regex. Examples,
@@ -220,8 +220,8 @@ def _get_eval_fields(self, name, value):
220220
EVAL-action = if(isnull(action), "unknown", action)
221221
222222
Args:
223-
name: key in the configuration settings
224-
value: value of the respective name in the configuration
223+
name (str): key in the configuration settings
224+
value (str): value of the respective name in the configuration
225225
226226
Yields:
227227
generator of fields
@@ -240,8 +240,8 @@ def _get_fieldalias_fields(self, name: str, value: str):
240240
FIELDALIAS-class = source AS dest, sc2 AS dest2
241241
242242
Args:
243-
name: key in the configuration settings
244-
value: value of the respective name in the configuration
243+
name (str): key in the configuration settings
244+
value (str): value of the respective name in the configuration
245245
246246
Regex:
247247
Description:
@@ -274,8 +274,8 @@ def _get_report_fields(self, name: str, value: str):
274274
transforms.conf and returns the list
275275
276276
Args:
277-
name: key in the configuration settings
278-
value: value of the respective name in the configuration
277+
name (str): key in the configuration settings
278+
value (str): value of the respective name in the configuration
279279
280280
Yields:
281281
generator of (transform_stanza ,fields) parsed from transforms.conf
@@ -294,8 +294,8 @@ def _get_lookup_fields(self, name: str, value: str):
294294
Extracts the lookup fields
295295
296296
Args:
297-
name: key in the configuration settings
298-
value: value of the respective name in the configuration
297+
name (str): key in the configuration settings
298+
value (str): value of the respective name in the configuration
299299
300300
Returns:
301301
List of lookup fields

pytest_splunk_addon/cim_compliance/cim_report_generator.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
class CIMReportGenerator(object):
5757
"""
58-
Generate the Report
58+
Generate the Report.
5959
data format::
6060
6161
[
@@ -67,6 +67,9 @@ class CIMReportGenerator(object):
6767
"status": "pass"/"fail"
6868
}
6969
]
70+
71+
Args:
72+
data (list): List of dictionaries with specified format.
7073
"""
7174

7275
def __init__(self, data=[], report_class=MarkDownReport):
@@ -78,7 +81,7 @@ def add_data(self, data):
7881
adds data to object property.
7982
8083
Args:
81-
data(list): List of dictionaries with specified format.
84+
data (list): List of dictionaries with specified format.
8285
"""
8386
self.data.append(data)
8487

@@ -87,8 +90,8 @@ def _group_by(self, keys, data=None):
8790
Function to generate group of data using Keys provided
8891
8992
Args:
90-
keys(list): Contains keys to group data by.
91-
data(list): list of dictionaries with specified format.
93+
keys (list): Contains keys to group data by.
94+
data (list): list of dictionaries with specified format.
9295
9396
Yields:
9497
data_set.DataSet: data set object mapped with the tags
@@ -105,8 +108,8 @@ def _get_count_by(self, keys, data=None):
105108
Function to generate count of data using Keys provided
106109
107110
Args:
108-
keys(list): Contains keys to generate count by.
109-
data(list): list of dictionaries with specified format.
111+
keys (list): Contains keys to generate count by.
112+
data (list): list of dictionaries with specified format.
110113
111114
Yields:
112115
data_set.DataSet: data set object mapped with the tags
@@ -123,7 +126,7 @@ def pass_count(counter):
123126
Function to Get count in Pass/Total format.
124127
125128
Args:
126-
counter(collections.Counter): Contains counts of passing/failing Testcases.
129+
counter (collections.Counter): Contains counts of passing/failing Testcases.
127130
128131
Yields:
129132
String: string with pass/total format.
@@ -139,7 +142,7 @@ def fail_count(counter):
139142
Function to Get count in Fail/Total format.
140143
141144
Args:
142-
counter(collections.Counter): Contains counts of passing/failing Testcases.
145+
counter (collections.Counter): Contains counts of passing/failing Testcases.
143146
144147
Yields:
145148
String: string with fail/total format.
@@ -231,7 +234,9 @@ def generate_field_summary_table(self):
231234
del field_summary_table
232235

233236
def generate_skip_tests_table(self):
234-
""" """
237+
"""
238+
Displays summary of the skipped tests
239+
"""
235240
skipped_tests = list(filter(lambda d: d["status"] == "skipped", self.data))
236241
if skipped_tests:
237242
skipped_tests_table = MarkdownTable(
@@ -255,7 +260,7 @@ def generate_report(self, report_path):
255260
Function to generate report from the stored data.
256261
257262
Args:
258-
report_path(string): Path to create the report.
263+
report_path (string): Path to create the report.
259264
"""
260265
self.report_generator.set_title("CIM AUDIT REPORT")
261266
self.data.sort(

pytest_splunk_addon/cim_compliance/markdown_report.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121

2222
class MarkDownReport(CIMReport):
23+
"""
24+
Generate the markdown content
25+
"""
26+
2327
def __init__(self):
2428
self.markdown_str = ""
2529
self.note_str = ""
@@ -29,7 +33,7 @@ def set_title(self, title_string):
2933
Function to set title of a report
3034
3135
Args:
32-
title_string(string): String containing title for report.
36+
title_string (str): String containing title for report.
3337
"""
3438
self.title_str = "# {} \n".format(title_string)
3539

@@ -38,7 +42,7 @@ def add_section_title(self, section_title):
3842
Function to add new section to report
3943
4044
Args:
41-
section_title(string): String containing title for new Section.
45+
section_title (str): String containing title for new Section.
4246
"""
4347
self.markdown_str += "\n## {}\n".format(section_title)
4448

@@ -47,7 +51,7 @@ def add_section_description(self, description):
4751
Adds description string to the section
4852
4953
Args:
50-
description(str): Description string.
54+
description (str): Description string.
5155
"""
5256
self.markdown_str += "\n**Description:** " + description + "\n"
5357

@@ -56,7 +60,7 @@ def add_section_note(self, section_note):
5660
Function to set Note in a report
5761
5862
Args:
59-
section_note(string): String containing note for report.
63+
section_note (str): String containing note for report.
6064
"""
6165
self.note_str = "## Note: {} \n".format(section_note)
6266

@@ -65,7 +69,7 @@ def add_table(self, table_string):
6569
Function to add a table to the Report.
6670
6771
Args:
68-
table_string(string): Stringified table.
72+
table_string (str): Stringified table.
6973
"""
7074
self.markdown_str += table_string
7175

@@ -74,7 +78,7 @@ def write(self, path):
7478
Function to add a table to the Report.
7579
7680
Args:
77-
path(string) : path to store report file.
81+
path (str) : path to store report file.
7882
"""
7983
with open(path, "w") as report:
8084
report.write(self.title_str)

pytest_splunk_addon/cim_compliance/markdown_table.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020

2121

2222
class MarkdownTable(BaseTable):
23+
"""
24+
Generate table in markdown format
25+
26+
Args:
27+
table_title (str): Title of the table
28+
header_list (list(str)): List of header names
29+
"""
30+
2331
def __init__(self, table_title, header_list):
2432
self.table_title = self.__set_title(table_title)
2533
self.table_headers = self.__set_headers(header_list)
@@ -32,7 +40,7 @@ def __set_title(self, title):
3240
Adds Title string to the table
3341
3442
Args:
35-
title(str): Title string.
43+
title (str): Title string.
3644
"""
3745
return "### {}".format(title) if title else ""
3846

@@ -41,7 +49,7 @@ def __set_headers(self, header_list):
4149
Sets the header column for the table.
4250
4351
Args:
44-
header_list(list): Contains list of column headers.
52+
header_list (list): Contains list of column headers.
4553
"""
4654
header_str = "\n"
4755
helper_str = ""
@@ -55,7 +63,7 @@ def set_description(self, description):
5563
Adds description string to the table
5664
5765
Args:
58-
description(str): Description string.
66+
description (str): Description string.
5967
"""
6068
self.table_description = "\n {} \n".format(description)
6169

@@ -64,7 +72,7 @@ def add_row(self, value_list):
6472
Expects a list of row values to be added in the table
6573
6674
Args:
67-
value_list(list): Contains list of row values
75+
value_list (list): Contains list of row values
6876
"""
6977
row_element = ""
7078
for each_value in value_list:
@@ -76,7 +84,7 @@ def set_note(self, note_str):
7684
It adds the note at the end of the table
7785
7886
Args:
79-
note_str(str): Note string to be added.
87+
note_str (str): Note string to be added.
8088
"""
8189
self.table_note = "\n*NOTE: {} *\n ".format(note_str)
8290

pytest_splunk_addon/cim_compliance/plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def pytest_sessionfinish(self, session):
3838
def pytest_runtest_logreport(self, report):
3939
"""
4040
Collect the data to be added into the report.
41+
42+
Args:
43+
report (TestReport): test report object
4144
"""
4245
if report.when == "call" and "test_cim_required_fields" in report.nodeid:
4346
data_dict = {}

pytest_splunk_addon/cim_tests/data_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def _get_mapped_datasets(self, addon_tags, data_sets, mapped_datasets=[]):
4242
If the parent data_set is mapped, check the child data_sets too
4343
4444
Args:
45-
addon_tags(list): Contains tags mapped to a stanza
46-
data_sets(list): list of data sets to check with
45+
addon_tags (list): Contains tags mapped to a stanza
46+
data_sets (list): list of data sets to check with
4747
4848
Yields:
4949
data_set.DataSet: data set object mapped with the tags
@@ -62,7 +62,7 @@ def get_mapped_datasets(self, addon_tags):
6262
Get all mapped dataSets for an Add-on's tags stanza
6363
6464
Args:
65-
addon_tags(list): Contains tags mapped to a stanza
65+
addon_tags (list): Contains tags mapped to a stanza
6666
6767
Yields:
6868
data_set.DataSet: data set object mapped with the tags

pytest_splunk_addon/cim_tests/data_model_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def load_data_models(self, data_model_path):
7979
"""
8080
Parse all the data model JSON files one by one
8181
82+
Args:
83+
data_model_path (str): path to the datamodel schema json file
84+
8285
Yields:
8386
(cim_tests.data_model.DataModel): parsed data model object
8487
"""

pytest_splunk_addon/cim_tests/data_set.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class DataSet(object):
2525
Handles a single data set
2626
2727
Args:
28-
data_set_json(dict): Json of a single DataSet
28+
data_set_json (dict): Json of a single DataSet
29+
data_model (str): Name of the data model
2930
"""
3031

3132
def __init__(self, data_set_json, data_model):
@@ -55,8 +56,8 @@ def load_dataset(cls, dataset_list, data_model):
5556
Parse all the fields from the data_model_json
5657
5758
Args:
58-
dataset_list(list): Contains list of datasets
59-
data_model: Name of the data model
59+
dataset_list (list): Contains list of datasets
60+
data_model (str): Name of the data model
6061
6162
Yields:
6263
data_set.DataSet: Dataset object for the given list
@@ -77,6 +78,9 @@ def _parse_constraint(cls, constraint_search):
7778
def _parse_fields_cluster(self, fields_clusters):
7879
"""
7980
Parse all the fields from the data_model_json
81+
82+
Args:
83+
fields_clusters (list(list(str))): list of field clusters, each field cluster contains list of field names which are expected to be together
8084
"""
8185
parsed_fields_clusters = []
8286
for each_cluster in fields_clusters:
@@ -90,6 +94,9 @@ def _parse_fields_cluster(self, fields_clusters):
9094
def match_tags(self, addon_tag_list):
9195
"""
9296
Check if the tags are mapped with this data set
97+
98+
Args:
99+
addon_tag_list (list): list of tags defined in the addon
93100
"""
94101
for each_tag_group in self.tags:
95102
if set(each_tag_group).issubset(set(addon_tag_list)):

0 commit comments

Comments
 (0)