Skip to content

Commit 1fa8b46

Browse files
authored
Merge pull request #19 from thc202/add-replacer
Add replacer API
2 parents e186ac0 + bf711fe commit 1fa8b46

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/zapv2/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from .params import params
4242
from .pnh import pnh
4343
from .pscan import pscan
44+
from .replacer import replacer
4445
from .reveal import reveal
4546
from .script import script
4647
from .search import search
@@ -90,6 +91,7 @@ def __init__(self, proxies=None, apikey=None):
9091
self.params = params(self)
9192
self.pnh = pnh(self)
9293
self.pscan = pscan(self)
94+
self.replacer = replacer(self)
9395
self.reveal = reveal(self)
9496
self.script = script(self)
9597
self.search = search(self)

src/zapv2/replacer.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Zed Attack Proxy (ZAP) and its related class files.
2+
#
3+
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
4+
#
5+
# Copyright 2017 the ZAP development team
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
"""
19+
This file was automatically generated.
20+
"""
21+
22+
import six
23+
24+
25+
class replacer(object):
26+
27+
def __init__(self, zap):
28+
self.zap = zap
29+
30+
@property
31+
def rules(self):
32+
"""
33+
Returns full details of all of the rules
34+
This component is optional and therefore the API will only work if it is installed
35+
"""
36+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'replacer/view/rules/')))
37+
38+
def add_rule(self, description, enabled, matchtype, matchregex, matchstring, replacement, initiators=None, apikey=''):
39+
"""
40+
Adds a replacer rule. For the parameters: desc is a user friendly description, enabled is true or false, matchType is one of [REQ_HEADER, REQ_HEADER_STR, REQ_BODY_STR, RESP_HEADER, RESP_HEADER_STR, RESP_BODY_STR], matchRegex should be true if the matchString should be treated as a regex otherwise false, matchString is the string that will be matched against, replacement is the replacement string, initiators may be blank (for all initiators) or a comma separated list of integers as defined in <a href="https://github.com/zaproxy/zaproxy/blob/develop/src/org/parosproxy/paros/network/HttpSender.java">HttpSender</a>
41+
This component is optional and therefore the API will only work if it is installed
42+
"""
43+
params = {'description': description, 'enabled': enabled, 'matchType': matchtype, 'matchRegex': matchregex, 'matchString': matchstring, 'replacement': replacement, 'apikey': apikey}
44+
if initiators is not None:
45+
params['initiators'] = initiators
46+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'replacer/action/addRule/', params)))
47+
48+
def remove_rule(self, description, apikey=''):
49+
"""
50+
Removes the rule with the given description
51+
This component is optional and therefore the API will only work if it is installed
52+
"""
53+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'replacer/action/removeRule/', {'description': description, 'apikey': apikey})))
54+
55+
def set_enabled(self, description, bool, apikey=''):
56+
"""
57+
Enables or disables the rule with the given description based on the bool parameter
58+
This component is optional and therefore the API will only work if it is installed
59+
"""
60+
return six.next(six.itervalues(self.zap._request(self.zap.base + 'replacer/action/setEnabled/', {'description': description, 'bool': bool, 'apikey': apikey})))

0 commit comments

Comments
 (0)