Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __str__(self):
target = []
for (header, filter_name, terms) in self.ciscoasa_policies:
target.append('clear configure access-list %s' % filter_name)
# add the p4 tags
target.extend(aclgenerator.AddRepositoryTags('access-list %s remark '
% filter_name))
# add a header comment if one exists
for comment in header.comment:
for line in comment.split('\n'):
target.append('access-list %s remark %s' % (filter_name, line))
# now add the terms
for term in terms:
target.append(str(term))
# end for header, filter_name, filter_type...
return '\n'.join(target)
for filter_type in filter_list:
target.extend(self._AppendTargetByFilterType(filter_name, filter_type))
if filter_type == 'object-group':
obj_target.AddName(filter_name)
# Add the Perforce Id/Date tags, these must come after
# remove/re-create of the filter, otherwise config mode doesn't
# know where to place these remarks in the configuration.
if self.verbose:
if filter_type == 'standard' and filter_name.isdigit():
target.extend(
aclgenerator.AddRepositoryTags(
'access-list %s remark ' % filter_name,
date=False, revision=False))
else:
target.extend(aclgenerator.AddRepositoryTags(
' remark ', date=False, revision=False))
# add a header comment if one exists
for comment in header.comment:
for line in comment.split('\n'):
if (self._PLATFORM == 'cisco' and filter_type == 'standard' and
filter_name.isdigit()):
target.append('access-list %s remark %s' % (filter_name, line))
else:
target.append(' remark %s' % line)
# now add the terms
for term in terms:
term_str = str(term)
if term_str:
target.append(term_str)
def __str__(self):
config = Config()
for (header, filter_name, filter_type, interface_specific, terms
) in self.juniper_policies:
# add the header information
config.Append('firewall {')
config.Append('family %s {' % filter_type)
config.Append('replace:')
config.Append('/*')
# we want the acl to contain id and date tags, but p4 will expand
# the tags here when we submit the generator, so we have to trick
# p4 into not knowing these words. like taking c-a-n-d-y from a
# baby.
for line in aclgenerator.AddRepositoryTags('** '):
config.Append(line)
config.Append('**')
for comment in header.comment:
for line in comment.split('\n'):
config.Append('** ' + line)
config.Append('*/')
config.Append('filter %s {' % filter_name)
if interface_specific:
config.Append('interface-specific;')
for term in terms:
term_str = str(term)
if term_str:
config.Append(term_str, verbatim=True)
for (header, filter_name, filter_type, default_action, terms
) in self.windows_policies:
# Add comments for this filter
target.append(': %s %s Policy' % (pretty_platform,
header.FilterName(self._PLATFORM)))
self._HandlePolicyHeader(header, target)
# reformat long text comments, if needed
comments = aclgenerator.WrapWords(header.comment, 70)
if comments and comments[0]:
for line in comments:
target.append(': %s' % line)
target.append(':')
# add the p4 tags
target.extend(aclgenerator.AddRepositoryTags(': '))
target.append(': ' + filter_type)
if default_action:
target.append(self._DEFAULTACTION_FORMAT % (filter_name,
default_action))
# add the terms
for term in terms:
term_str = str(term)
if term_str:
target.append(term_str)
self._HandleTermFooter(header, term, target)
target.append('')
return '\n'.join(target)
def __str__(self):
"""Render the output of the Nsxv policy."""
target_header = []
target = []
# add the p4 tags
target.append('')
for (_, _, _, terms) in self.nsxv_policies:
section_name = self._FILTER_OPTIONS_DICT['section_name']
# check section id value
section_id = self._FILTER_OPTIONS_DICT['section_id']
if not section_id or section_id == 0:
logging.warn('WARNING: Section-id is 0. A new Section is created for%s.'
' If there is any existing section, it will remain '
'unreferenced and should be removed manually.',
section_name)
target.append('<section name="%s">' % (section_name.strip(' \t\n\r')))
else:
target.append('<section name="%s" id="%s">' %
(section_id, section_name.strip(' \t\n\r')))</section></section>
def __str__(self):
"""Render the output of the JuniperSRX policy into config."""
target = IndentList(self.INDENT)
target.append('security {')
# ADDRESSBOOK
target.extend(self._GenerateAddressBook())
# POLICIES
target.IndentAppend(1, '/*')
target.extend(aclgenerator.AddRepositoryTags(self.INDENT * 1))
target.IndentAppend(1, '*/')
target.IndentAppend(1, 'replace: policies {')
for (header, terms, filter_options) in self.srx_policies:
if self._NOVERBOSE not in filter_options[4:]:
target.IndentAppend(2, '/*')
target.extend([self.INDENT * 2 + line for line in
aclgenerator.WrapWords(header.comment,
self._MAX_HEADER_COMMENT_LENGTH)])
target.IndentAppend(2, '*/')
# ZONE DIRECTION
if filter_options[1] == 'all' and filter_options[3] == 'all':
target.IndentAppend(2, 'global {')
else:
def __str__(self):
target = []
target.extend(aclgenerator.AddRepositoryTags('%s ' % _COMMENT_MARKER))
for filter_name, terms, _ in self.aruba_policies:
netdestinations = []
term_strings = []
for term in terms:
term_strings.append(str(term))
netdestinations.extend(term.netdestinations)
target.extend(netdestinations)
target.append('%s %s' % (self._ACL_LINE_HEADER, filter_name))
target.extend(term_strings)
target.extend(_TERMINATOR_MARKER)
if target:
target.append('')
sorted(self.address_book[name], key=int))
target.append('table <%s> {%s}' % (name, entries))
# pylint: disable=unused-variable
for (header, filter_name, filter_type, terms) in self.pf_policies:
# Add comments for this filter
target.append('# %s %s Policy' % (pretty_platform,
header.FilterName(self._PLATFORM)))
# reformat long text comments, if needed
comments = aclgenerator.WrapWords(header.comment, 70)
if comments and comments[0]:
for line in comments:
target.append('# %s' % line)
target.append('#')
# add the p4 tags
target.extend(aclgenerator.AddRepositoryTags('# '))
target.append('# ' + filter_type)
# add the terms
for term in terms:
term_str = str(term)
if term_str:
target.append(term_str)
target.append('')
return '\n'.join(target)