Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Feature/waf policy groups (#37)
Browse files Browse the repository at this point in the history
* improved documentation

* waf policy groups and policies handling
  • Loading branch information
sandromodarelli authored Dec 4, 2019
1 parent 3aec8db commit 021f28b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pystackpath/stacks/wafsites/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pystackpath.util import BaseSite
from pystackpath.stacks.wafsites.ddos import Ddos
from pystackpath.stacks.wafsites.policy_groups import PolicyGroups
from pystackpath.stacks.wafsites.rules import Rules


Expand All @@ -9,3 +10,6 @@ def rules(self):

def ddos(self):
return Ddos(self._client, f"{self._base_api}/sites/{self.id}")

def policy_groups(self):
return PolicyGroups(self._client, f"{self._base_api}/sites/{self.id}")
37 changes: 37 additions & 0 deletions pystackpath/stacks/wafsites/policy_groups/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pystackpath.util import BaseObject
from pystackpath.stacks.wafsites.policy_groups.policies import Policies


class PolicyGroups(BaseObject):
def index(self):
"""
Retrieve all WAF policy groups
:return: a list of policy groups on a site
"""
response = self._client.get(f"{self._base_api}/policy_groups")
items = [self.loaddict(item) for item in response.json()["policyGroups"]]

return items

def get(self, policy_group_id):
"""
Retrieve an individual WAF policy group
:param policy_group_id: The ID of the WAF policy group to retrieve
"""
response = self._client.get(f"{self._base_api}/policy_groups/{policy_group_id}")
return self.loaddict(response.json()["policyGroup"])

def enable(self):
"""
Enable all policies in a WAF policy group
"""
response = self._client.post(f"{self._base_api}/policy_groups/{self.id}/enable")

def disable(self):
"""
Disable all policies in a WAF policy group
"""
response = self._client.post(f"{self._base_api}/policy_groups/{self.id}/disable")

def policies(self):
return Policies(self._client, f"{self._base_api}/policy_groups/{self.id}")
33 changes: 33 additions & 0 deletions pystackpath/stacks/wafsites/policy_groups/policies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pystackpath.util import BaseObject


class Policies(BaseObject):
def index(self):
"""
Retrieve all policies in a WAF policy group
:return: a list of policies in a WAF policy group
"""
response = self._client.get(f"{self._base_api}/policies")
items = [self.loaddict(item) for item in response.json()["policies"]]

return items

def get(self, policy_id):
"""
Retrieve an individual WAF policy
:param policy_id: The ID of the WAF policy to retrieve
"""
response = self._client.get(f"{self._base_api}/policies/{policy_id}")
return self.loaddict(response.json()["policyGroup"])

def enable(self):
"""
Enable a WAF policy
"""
response = self._client.post(f"{self._base_api}/policies/{self.id}/enable")

def disable(self):
"""
Disable a WAF policy
"""
response = self._client.post(f"{self._base_api}/policies/{self.id}/disable")
2 changes: 0 additions & 2 deletions pystackpath/stacks/wafsites/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ def bulk_delete(self, ruleIds: list):
def enable(self):
"""
Enable a WAF rule
:param rule_id: The ID of the rule to enable
"""
response = self._client.post(f"{self._base_api}/rules/{self.id}/enable")

def disable(self):
"""
Disable a WAF rule
:param rule_id: The ID of the rule to disable
"""
response = self._client.post(f"{self._base_api}/rules/{self.id}/disable")

0 comments on commit 021f28b

Please sign in to comment.