Skip to content

Commit

Permalink
updated the code
Browse files Browse the repository at this point in the history
  • Loading branch information
karand-metron committed Jan 9, 2025
1 parent c4baaf7 commit c7a977d
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 87 deletions.
56 changes: 40 additions & 16 deletions Packs/SilentPush/Integrations/SilentPush/SilentPush.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import demistomock as demisto
from CommonServerPython import *
from CommonServerUserPython import *
import requests
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
"""Base Integration for Cortex XSOAR (aka Demisto)
This is an integration to interact with the SilentPush API and provide functionality within XSOAR.
Developer Documentation: https://xsoar.pan.dev/docs/welcome
Code Conventions: https://xsoar.pan.dev/docs/integrations/code-conventions
Linting: https://xsoar.pan.dev/docs/integrations/linting
"""

from CommonServerUserPython import * # noqa

import urllib3
from typing import Any

# Disable insecure warnings
requests.packages.urllib3.disable_warnings()
urllib3.disable_warnings()


def mock_debug(message):
"""Print debug messages to the XSOAR logs"""
Expand All @@ -14,19 +25,20 @@ def mock_debug(message):

demisto.debug = mock_debug

class Client:
"""
Client class to interact with the SilentPush API.
''' CONSTANTS '''

DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ' # ISO8601 format with UTC, default in XSOAR

''' CLIENT CLASS '''


This Client handles all interactions with the SilentPush service. It performs API requests,
processes the responses, and provides methods to query information about domains.
class Client(BaseClient):
"""Client class to interact with the SilentPush API
Attributes:
base_url (str): The base URL for the SilentPush API.
api_key (str): API key used for authentication.
verify (bool): Flag to determine whether to verify SSL certificates.
proxy (bool): Flag to determine whether to use a proxy.
_headers (dict): HTTP headers for the requests.
This Client implements API calls and does not contain any XSOAR logic.
It should only perform requests and return data.
It inherits from BaseClient defined in CommonServerPython.
Most calls use _http_request() that handles proxy, SSL verification, etc.
"""

def __init__(self, base_url: str, api_key: str, verify: bool = True, proxy: bool = False):
Expand Down Expand Up @@ -107,6 +119,10 @@ def list_domain_information(self, domain: str) -> dict:
url_suffix = f'explore/domain/domaininfo/{domain}'
return self._http_request('GET', url_suffix)


''' COMMAND FUNCTIONS '''


def test_module(client: Client) -> str:
"""
Tests connectivity to the SilentPush API and checks the authentication status.
Expand Down Expand Up @@ -161,6 +177,10 @@ def list_domain_information_command(client: Client, args: dict) -> CommandResult
raw_response=raw_response
)


''' MAIN FUNCTION '''


def main():
"""
Main function to initialize the client and process the commands.
Expand Down Expand Up @@ -206,5 +226,9 @@ def main():
demisto.error(f'Failed to execute {demisto.command()} command. Error: {str(e)}')
return_error(f'Failed to execute {demisto.command()} command. Error: {str(e)}')


''' ENTRY POINT '''


if __name__ in ('__main__', '__builtin__', 'builtins'):
main()
162 changes: 91 additions & 71 deletions Packs/SilentPush/Integrations/SilentPush/SilentPush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,106 @@ commonfields:
name: SilentPush
type: python
subType: python3
description: Integration with the SilentPush API to fetch domain information and other related data.
description: |
This integration allows fetching domain information from the SilentPush API. It includes commands to get domain-related information such as WHOIS data, domain age, and risk scores.
tags: []
enabled: true
tags:
- "SilentPush"
- "Domain Info"
- "API"
comment: "Integration to fetch domain information from SilentPush API"

script:
type: python
id: SilentPush
file: SilentPush.py
args: []
isArray: false
manufacturer: SilentPush
comment: ''
minVersion: -1
dependencies:
- CommonServerPython
- CommonServerUserPython

scripts:
- path: SilentPush.py
comment: |
Integration for SilentPush that enables fetching domain information, including WHOIS data, domain age, and risk scores.
commands:
- name: silentpush-list-domain-information
description: Fetches domain information including WHOIS data, domain age, and risk scores.
enabled: true
hidden: false
args:
- isArray: false
name: domain
description: The domain to fetch information for (default is silentpush.com).
isOptional: false
- name: test-module
description: |
Tests the connectivity to the SilentPush API and checks the authentication status.
isArray: false
argContext:
- id: base_url
type: string
implements:
- get
comment: "Fetch domain info, including age, registrar, WHOIS data, and risk scores."
outputs:
- contextPath: SilentPush.Domain
description: "Domain information fetched from SilentPush API."
type: dict
- contextPath: SilentPush.Domain.domain
description: "The domain name."
description: The base URL for the SilentPush API.
- id: api_key
type: string
tags:
- domain
- info
- silentpush
type: python3
command: list_domain_information_command
rawResponse: true
description: The API key used to authenticate requests.
- id: verify_ssl
type: boolean
description: Flag to determine whether SSL verification is enabled.
examples: |
!test-module
- name: test-module
description: Test the connection to the SilentPush API and check API Key validity.
enabled: true
hidden: false
args: []
implements:
- test
outputs:
- contextPath: SilentPush.Test
description: "Returns 'ok' if the API connection is successful."
- name: silentpush-list-domain-information
description: |
Fetches domain information, such as WHOIS data, domain age, and risk scores.
isArray: false
argContext:
- id: domain
type: string
command: test_module
rawResponse: false
description: The domain name to fetch information for.
examples: |
!silentpush-list-domain-information domain=example.com
arguments:
args:
- id: domain
name: domain
description: The domain to fetch information for.
isArray: false
description: |
The domain to fetch information for.
type: string

outputs:
- id: SilentPush.Domain
type: complex
description: |
The domain information fetched from SilentPush API, including WHOIS data, domain age, and risk scores.
contents:
- name: domain
type: string
- name: whois_data
type: string
- name: domain_age
type: integer
- name: risk_score
type: float

tests:
- name: Test SilentPush Integration
description: Test the integration with the SilentPush API.
steps:
- script: test-module
name: Test SilentPush API Connectivity
args:
base_url: https://api.silentpush.com
api_key: 'your_api_key'

# Optional: Adding the configuration section for any configuration-related parameters
configurations:
- default: true
isArray: false
isOptional: false
default: silentpush.com
description: The configuration parameters required for connecting to SilentPush API.
context:
- id: base_url
type: string
description: The base URL for the SilentPush API.
- id: api_key
type: string
description: The API key used to authenticate requests.
- id: verify_ssl
type: boolean
description: Flag to determine whether SSL verification is enabled.
- id: proxy
type: boolean
description: Flag to determine whether to use a proxy.

integrationContext:
outputs:
SilentPush.Domain:
domain: string
age: number
age_score: number
first_seen: number
is_new: bool
is_new_score: number
last_seen: number
registrar: string
whois_age: number
whois_created_date: string
zone: string
SilentPush.Test:
status: string
errorHandling:
- errorCode: 403
description: |
If an authorization error is encountered, it could indicate an incorrect or expired API key.
- errorCode: 400
description: |
Bad Request error, likely due to incorrect input format or invalid parameters in the request.

0 comments on commit c7a977d

Please sign in to comment.