Skip to content

Commit

Permalink
Implemented as per mark's review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Neetin committed Dec 20, 2018
1 parent 82bd97e commit fc822ad
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 143 deletions.
4 changes: 0 additions & 4 deletions fn_query_tar_network/MANIFEST.in

This file was deleted.

99 changes: 0 additions & 99 deletions fn_query_tar_network/fn_query_tar_network/util/customize.py

This file was deleted.

4 changes: 4 additions & 0 deletions fn_query_tor_network/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include README.md
include fn_query_tor_network/util/*
include fn_query_tor_network/LICENSE
include fn_query_tor_network/doc/*
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ Replace this with your own readme.

This template project was generated by

resilient-circuits codegen -p fn_query_tar_network [-f query_tor_network] [-w ]
resilient-circuits codegen -p fn_query_tor_network [-f fn_tor] [-w ]


You must edit the `setup.py` before distribution;
it should contain your actual contact and license information.

To install in "development mode"

pip install -e ./fn_query_tar_network/
pip install -e ./fn_query_tor_network/

After installation, the package will be loaded by `resilient-circuits run`.


To uninstall,

pip uninstall fn_query_tar_network
pip uninstall fn_query_tor_network


To package for distribution,

python ./fn_query_tar_network/setup.py sdist
python ./fn_query_tor_network/setup.py sdist

The resulting .tar.gz file can be installed using

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@

import logging
from resilient_circuits import ResilientComponent, function, handler, StatusMessage, FunctionResult, FunctionError
import fn_query_tar_network.util.selftest as selftest
import fn_query_tor_network.util.selftest as selftest
import requests

class FunctionComponent(ResilientComponent):
"""Component that implements Resilient function 'query_tor_network"""
"""Component that implements Resilient function 'fn_tor"""

def __init__(self, opts):
"""constructor provides access to the configuration options"""
super(FunctionComponent, self).__init__(opts)
self.options = opts.get("fn_query_tar_network", {})
self.options = opts.get("fn_query_tor_network", {})
selftest.selftest_function(opts)

@handler("reload")
def _reload(self, event, opts):
"""Configuration options have changed, save new values"""
self.options = opts.get("fn_query_tar_network", {})
self.options = opts.get("fn_query_tor_network", {})

@function("query_tor_network")
def _query_tor_network_function(self, event, *args, **kwargs):
"""Function: This Function to Search for Given Parameter in TOR Relay Exit Node"""
@function("fn_tor")
def _fn_tor_function(self, event, *args, **kwargs):
"""Function: This TOR function searches for the given IP Address or host names in TOR exit node Network by using RESTful API"""
try:
# Get the function parameters:
search_data = kwargs.get("search_data") # text
tor_search_data = kwargs.get("tor_search_data") # text

log = logging.getLogger(__name__)
log.info("search_data: %s", search_data)
log.info("tor_search_data: %s", tor_search_data)

# PUT YOUR FUNCTION IMPLEMENTATION CODE HERE
yield StatusMessage("starting...")

__params_data = {'flag': self.options.get('flag'), 'fields': self.options.get('data_fields'),
'search': search_data}
'search': tor_search_data}

__response_data = requests.get(self.options.get('base_url'), params=__params_data)

__response_data = __response_data.text
if __response_data.find(search_data) != -1:
if __response_data.find(tor_search_data) != -1:
results = {'status': 'success', 'data': __response_data, 'value': True}
else:
log.info("No Data found for given search element...!")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (c) Copyright IBM Corp. 2010, 2018. All Rights Reserved.
# -*- coding: utf-8 -*-

"""Generate a default configuration-file section for fn_query_tar_network"""
"""Generate a default configuration-file section for fn_query_tor_network"""

from __future__ import print_function

Expand All @@ -10,9 +10,9 @@ def config_section_data():
"""Produce the default configuration section for app.config,
when called by `resilient-circuits config [-c|-u]`
"""
config_data = u"""[fn_query_tar_network]
config_data = u"""[fn_query_tor_network]
base_url = https://onionoo.torproject.org/details
flag = Exit
data_fields = exit_addresses,or_addresses,host_name
"""
data_fields = exit_addresses,or_addresses,host_name"""

return config_data
98 changes: 98 additions & 0 deletions fn_query_tor_network/fn_query_tor_network/util/customize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# (c) Copyright IBM Corp. 2010, 2018. All Rights Reserved.
# -*- coding: utf-8 -*-

"""Generate the Resilient customizations required for fn_query_tor_network"""

from __future__ import print_function
from resilient_circuits.util import *

def codegen_reload_data():
"""Parameters to codegen used to generate the fn_query_tor_network package"""
reload_params = {"package": u"fn_query_tor_network",
"incident_fields": [],
"action_fields": [],
"function_params": [u"tor_search_data"],
"datatables": [],
"message_destinations": [u"fn_tor"],
"functions": [u"fn_tor"],
"phases": [],
"automatic_tasks": [],
"scripts": [],
"workflows": [],
"actions": []
}
return reload_params


def customization_data(client=None):
"""Produce any customization definitions (types, fields, message destinations, etc)
that should be installed by `resilient-circuits customize`
"""

# This import data contains:
# Function inputs:
# tor_search_data
# Message Destinations:
# fn_tor
# Functions:
# fn_tor


yield ImportDefinition(u"""
eyJ0YXNrX29yZGVyIjogW10sICJ3b3JrZmxvd3MiOiBbXSwgImFjdGlvbnMiOiBbXSwgImxheW91
dHMiOiBbXSwgImV4cG9ydF9mb3JtYXRfdmVyc2lvbiI6IDIsICJpZCI6IDI1LCAiaW5kdXN0cmll
cyI6IG51bGwsICJwaGFzZXMiOiBbXSwgImFjdGlvbl9vcmRlciI6IFtdLCAiZ2VvcyI6IG51bGws
ICJzZXJ2ZXJfdmVyc2lvbiI6IHsibWFqb3IiOiAzMCwgInZlcnNpb24iOiAiMzAuNC4yMzciLCAi
YnVpbGRfbnVtYmVyIjogMjM3LCAibWlub3IiOiA0fSwgInRpbWVmcmFtZXMiOiBudWxsLCAid29y
a3NwYWNlcyI6IFtdLCAiYXV0b21hdGljX3Rhc2tzIjogW10sICJmdW5jdGlvbnMiOiBbeyJkaXNw
bGF5X25hbWUiOiAiVE9SIiwgImRlc2NyaXB0aW9uIjogeyJjb250ZW50IjogIlRoaXMgVE9SIGZ1
bmN0aW9uIHNlYXJjaGVzIGZvciB0aGUgZ2l2ZW4gSVAgQWRkcmVzcyBvciBob3N0IG5hbWVzIGlu
IFRPUiBleGl0IG5vZGUgTmV0d29yayBieSB1c2luZyBSRVNUZnVsIEFQSSIsICJmb3JtYXQiOiAi
dGV4dCJ9LCAiY3JlYXRvciI6IHsiZGlzcGxheV9uYW1lIjogIk5pdGluIE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F0
aW9uIjogZmFsc2UsICJwbGFjZWhvbGRlciI6ICIiLCAibmFtZSI6ICJ0b3Jfc2VhcmNoX2RhdGEi
LCAiZGVmYXVsdF9jaG9zZW5fYnlfc2VydmVyIjogZmFsc2UsICJ2YWx1ZXMiOiBbXX1dLCAib3Zl
cnJpZGVzIjogW10sICJleHBvcnRfZGF0ZSI6IDE1NDUzMTg4NjEzNjZ9
"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# pragma pylint: disable=unused-argument, no-self-use
"""Function implementation
test with: resilient-circuits selftest -l fn_query_tar_network
test with: resilient-circuits selftest -l fn_query_tor_network
"""

import logging
Expand All @@ -18,7 +18,7 @@ def selftest_function(opts):
Placeholder for selftest function. An example use would be to test package api connectivity.
Suggested return values are be unimplemented, success, or failure.
"""
options = opts.get("fn_query_tar_network", {})
options = opts.get("fn_query_tor_network", {})
try:
connection_status = requests.get(options.get('base_url'))
if not connection_status.status_code == 200:
Expand Down
16 changes: 8 additions & 8 deletions fn_query_tar_network/setup.py → fn_query_tor_network/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
from setuptools import setup, find_packages

setup(
name='fn_query_tar_network',
name='fn_query_tor_network',
version='1.0.0',
license='MIT',
author='Resilient Labs',
author_email='[email protected]',
url='https://github.com/ibmresilient/resilient-community-apps',
description="Resilient Circuits Components for 'fn_query_tar_network'",
long_description="""The Query TOR Network API is RESTful web service allowing query tar network customer
search for IP Addresses or host names in tor relay exit node database.and results
will be updated on the Dashboard.
""",
search for IP Addresses or host names in tor relay exit node database.and results
will be updated on the Incidents Notes Dashboard.
""",
install_requires=[
'resilient_circuits>=30.0.0'
],
Expand All @@ -27,10 +27,10 @@
],
entry_points={
"resilient.circuits.components": [
"QueryTorNetworkFunctionComponent = fn_query_tar_network.components.query_tor_network:FunctionComponent"
"FnTorFunctionComponent = fn_query_tor_network.components.fn_tor:FunctionComponent"
],
"resilient.circuits.configsection": ["gen_config = fn_query_tar_network.util.config:config_section_data"],
"resilient.circuits.customize": ["customize = fn_query_tar_network.util.customize:customization_data"],
"resilient.circuits.selftest": ["selftest = fn_query_tar_network.util.selftest:selftest_function"]
"resilient.circuits.configsection": ["gen_config = fn_query_tor_network.util.config:config_section_data"],
"resilient.circuits.customize": ["customize = fn_query_tor_network.util.customize:customization_data"],
"resilient.circuits.selftest": ["selftest = fn_query_tor_network.util.selftest:selftest_function"]
}
)
Loading

0 comments on commit fc822ad

Please sign in to comment.