Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DSaaS Adding Global Rule with Python

Trying to use the automation API example to add a global rule to DSaaS. I have no idea how to populate the hash,description pairs in the globalrules = deepsecurity.ApplicationControlGlobalRules().

Tried using JSON but don't know how to do that.

from __future__ import print_function
import sys, warnings
import deepsecurity
from deepsecurity.rest import ApiException
from pprint import pprint

# Setup
if not sys.warnoptions:
    warnings.simplefilter("ignore")
configuration = deepsecurity.Configuration()
configuration.host = 'YOUR_HOST'

# Authentication
configuration.api_key['api-secret-key'] = 'YOUR_API_KEY'

# Initialization
# Set Any Required Values
api_instance = deepsecurity.GlobalRulesApi(deepsecurity.ApiClient(configuration))
globalrules = deepsecurity.ApplicationControlGlobalRules()
api_version = 'YOUR VERSION'

try:
    api_response = api_instance.add_global_rules(globalrules, api_version)
    pprint(api_response)
except ApiException as e:
    print("An exception occurred when calling GlobalRulesApi.add_global_rules: %s\n" % e)

I'd like to know how to populate the hash,description pair in the object that is passed to the add_global_rules method.

like image 229
tboyers Avatar asked Jan 21 '26 02:01

tboyers


1 Answers

I'm assuming you would like to add some Global Application Control Rules to your DSaaS account using the Python SDK. In order to do this, first create the rules like so

rules = []
rules.append(deepsecurity.ApplicationControlGlobalRule(sha256="YOUR_SHA256_HERE", description="YOUR_DESCRIPTION_HERE"))
...

appending more rules as required. Then add them to the ApplicationControlGlobalRules object

globalrules = deepsecurity.ApplicationControlGlobalRules(application_control_global_rules = rules)

In general your code sample will be as follows

from __future__ import print_function
import sys, warnings
import deepsecurity
from deepsecurity.rest import ApiException
from pprint import pprint

# Setup
if not sys.warnoptions:
    warnings.simplefilter("ignore")
configuration = deepsecurity.Configuration()
configuration.host = 'YOUR_HOST'

# Authentication
configuration.api_key['api-secret-key'] = 'YOUR_API_KEY'

# Initialization
# Set Any Required Values
api_instance = deepsecurity.GlobalRulesApi(deepsecurity.ApiClient(configuration))
api_version = 'YOUR VERSION'

# Create empty list for Global Application Control Rules
rules = []
rules.append(deepsecurity.ApplicationControlGlobalRule(sha256="YOUR_SHA256_HERE", description="YOUR_DESCRIPTION_HERE"))
# ... Add more Global Application Control Rules as required here

# Create ApplicationControlGlobalRules object with the rules
globalrules = deepsecurity.ApplicationControlGlobalRules(application_control_global_rules = rules)

try:
    api_response = api_instance.add_global_rules(globalrules, api_version)
    pprint(api_response)
except ApiException as e:
    print("An exception occurred when calling GlobalRulesApi.add_global_rules: %s\n" % e)

P.S. I work for Trend Micro on the Deep Security team.

like image 90
Rouzbeh Avatar answered Jan 22 '26 14:01

Rouzbeh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!