|
11 | 11 |
|
12 | 12 | from CommonServerUserPython import * # noqa
|
13 | 13 |
|
| 14 | +import requests |
14 | 15 | import urllib3
|
15 | 16 | from typing import Any
|
16 | 17 |
|
@@ -119,6 +120,20 @@ def list_domain_information(self, domain: str) -> dict:
|
119 | 120 | url_suffix = f'explore/domain/domaininfo/{domain}'
|
120 | 121 | return self._http_request('GET', url_suffix)
|
121 | 122 |
|
| 123 | + def get_domain_certificates(self, domain: str) -> dict: |
| 124 | + """ |
| 125 | + Fetches SSL/TLS certificate data for a given domain. |
| 126 | + |
| 127 | + Args: |
| 128 | + domain (str): The domain to fetch certificate information for. |
| 129 | + |
| 130 | + Returns: |
| 131 | + dict: A dictionary containing certificate information fetched from the API. |
| 132 | + """ |
| 133 | + demisto.debug(f'Fetching certificate information for domain: {domain}') |
| 134 | + url_suffix = f'explore/domain/certificates/{domain}' |
| 135 | + return self._http_request('GET', url_suffix) |
| 136 | + |
122 | 137 |
|
123 | 138 | def test_module(client: Client) -> str:
|
124 | 139 | """
|
@@ -179,6 +194,30 @@ def list_domain_information_command(client: Client, args: dict) -> CommandResult
|
179 | 194 | )
|
180 | 195 |
|
181 | 196 |
|
| 197 | +def get_domain_certificates_command(client: Client, args: dict) -> CommandResults: |
| 198 | + """ |
| 199 | + Command handler for fetching domain certificate information. |
| 200 | + """ |
| 201 | + domain = args.get('domain', 'silentpush.com') |
| 202 | + demisto.debug(f'Processing certificates for domain: {domain}') |
| 203 | + |
| 204 | + |
| 205 | + demisto.debug('Entering get_domain_certificates_command function') |
| 206 | + |
| 207 | + raw_response = client.get_domain_certificates(domain) |
| 208 | + demisto.debug(f'Response from API: {raw_response}') |
| 209 | + |
| 210 | + readable_output = tableToMarkdown('Domain Certificates', raw_response) |
| 211 | + |
| 212 | + return CommandResults( |
| 213 | + outputs_prefix='SilentPush.Certificates', |
| 214 | + outputs_key_field='domain', |
| 215 | + outputs=raw_response, |
| 216 | + readable_output=readable_output, |
| 217 | + raw_response=raw_response |
| 218 | + ) |
| 219 | + |
| 220 | + |
182 | 221 | ''' MAIN FUNCTION '''
|
183 | 222 |
|
184 | 223 |
|
@@ -213,13 +252,19 @@ def main():
|
213 | 252 | command = demisto.command()
|
214 | 253 | demisto.debug(f'Command being called is {command}')
|
215 | 254 |
|
216 |
| - if command == 'test-module': |
217 |
| - result = test_module(client) |
218 |
| - return_results(result) |
219 |
| - |
220 |
| - elif command == 'silentpush-list-domain-information': |
221 |
| - return_results(list_domain_information_command(client, demisto.args())) |
222 |
| - |
| 255 | + command_handlers = { |
| 256 | + |
| 257 | + 'test-module': test_module, |
| 258 | + 'silentpush-list-domain-information': list_domain_information_command, |
| 259 | + 'silentpush-get-domain-certificates': get_domain_certificates_command, |
| 260 | + } |
| 261 | + |
| 262 | + if command in command_handlers: |
| 263 | + if command == 'test-module': |
| 264 | + result = command_handlers[command](client) |
| 265 | + return_results(result) |
| 266 | + else: |
| 267 | + return_results(command_handlers[command](client, demisto.args())) |
223 | 268 | else:
|
224 | 269 | raise DemistoException(f'Unsupported command: {command}')
|
225 | 270 |
|
|
0 commit comments