Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
v0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gabstopper committed May 29, 2017
1 parent 3467b20 commit 0d59058
Show file tree
Hide file tree
Showing 30 changed files with 642 additions and 429 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def readme():
return f.read()

setup(name='smc-python',
version='0.5.2',
version='0.5.3',
description='Python based API to Stonesoft Security Management Center',
url='http://github.com/gabstopper/smc-python',
author='David LePage',
Expand Down
1 change: 1 addition & 0 deletions smc/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Element.get_or_create helper method
All created element calls now return an instance of themselves versus just the href
filter_key, first, last and exists options on search collection
remove attr_by_name in favor of instance attributes
config loading from environment variables



Expand Down
2 changes: 1 addition & 1 deletion smc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from smc.api.session import Session

__author__ = 'David LePage'
__version__ = '0.5.2'
__version__ = '0.5.3'

# Default SMC Session
session = Session()
Expand Down
2 changes: 1 addition & 1 deletion smc/actions/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def all_elements_by_type(name):

def all_entry_points(): # get from session cache
""" Get all SMC API entry points """
return session.cache.get_all_entry_points()
return session.entry_points.all()


def element_entry_point(name):
Expand Down
19 changes: 8 additions & 11 deletions smc/administration/access_rights.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from smc.base.model import Element, ElementCreator
from smc.base.util import element_resolver
from smc.base.decorators import autocommit
from smc.elements.other import AdminDomain


Expand Down Expand Up @@ -55,38 +54,36 @@ def permissions(self):
"""
return [Element.from_href(e) for e in self.granted_element]

@autocommit(now=False)
def add_permission(self, elements, autocommit=False):
def add_permission(self, elements):
"""
Add permission/s to this ACL.
Add permission/s to this ACL. By default this change is committed
after the method is called.
:param list elements: Elements to grant access to. Can be engines,
policies, or other ACLs
:type elements: list(str,Element)
:param bool autocommit: autocommit save after calling this function.
(default: True)
:raises UpdateElementFailed: Failed updating permissions
:return: None
"""
elements = element_resolver(elements)
self.data['granted_element'].extend(elements)
self.update()

@autocommit(now=False)
def remove_permission(self, elements, autocommit=False):
def remove_permission(self, elements):
"""
Remove permission/s to this ACL.
Remove permission/s to this ACL. Change is committed at end of
method call.
:param list elements: list of element/s to remove
:type elements: list(str,Element)
:param bool autocommit: autocommit save after calling this function.
(default: True)
:raises UpdateElementFailed: Failed modifying permissions
:return: None
"""
elements = element_resolver(elements)
for element in elements:
if element in self.granted_element:
self.data['granted_element'].remove(element)
self.update()


class Permission(object):
Expand Down
43 changes: 26 additions & 17 deletions smc/administration/license.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
"""
Module representing read-only licenses in SMC
"""
class Licenses(object):
"""
List of all available licenses for this Management Server.
"""
def __init__(self, licenses):
self.licenses = []
for lic in licenses['license']:
self.licenses.append(License(**lic))

def __iter__(self):
return iter(self.licenses)

def __len__(self):
return len(self.licenses)

def __getitem__(self, index):
return self.licenses[index]


class License(object):
Expand All @@ -25,26 +42,18 @@ class License(object):
typeof = 'licenses'

def __init__(self, **data):
self.__dict__.update(data)
for d, v in data.items():
setattr(self, d, v)

@property
def name(self):
return self.license_id

def __getitem__(self, item):
try:
return self.__dict__[item]
except KeyError: # Handle missing attributes
pass

__getattr__ = __getitem__

def __setattr__(self, name, value):
raise TypeError(
'Cannot set name %r on object of type %s' %
(name, self.__class__.__name__))

def __getattr__(self, attr):
return None

def __repr__(self):
return '{0}(id={1},binding={2})'.format(self.__class__.__name__,
self.name,
self.binding_state)
return '{0}(id={1},binding={2})'.format(
self.__class__.__name__,
self.name,
self.binding_state)
32 changes: 14 additions & 18 deletions smc/administration/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
"""
import smc.actions.search as search
from smc.elements.other import prepare_blacklist
from .tasks import task_handler, Task
from smc.base.model import prepared_request, SubElement
from smc.administration.updates import EngineUpgrade, UpdatePackage
from smc.administration.license import License
from smc.administration.license import Licenses
from smc.api.common import fetch_json_by_post
from smc.api.exceptions import ActionCommandFailed
from smc.administration.tasks import DownloadTask


class System(SubElement):
Expand Down Expand Up @@ -145,11 +145,9 @@ def licenses(self):
print(license, license.expiration_date)
.....
:return: list :py:class:`smc.administration.license.License`
:return: list :py:class:`smc.administration.license.Licenses`
"""
licenses = self._resource.get('licenses')
return [License(**lic)
for lic in licenses['license']]
return Licenses(self._resource.get('licenses'))

def license_fetch(self):
"""
Expand Down Expand Up @@ -201,8 +199,7 @@ def references_by_element(self, element_href):
else:
return []

def export_elements(self, filename='export_elements.zip', typeof='all',
wait_for_finish=False):
def export_elements(self, filename='export_elements.zip', typeof='all'):
"""
Export elements from SMC.
Expand All @@ -214,25 +211,24 @@ def export_elements(self, filename='export_elements.zip', typeof='all',
:param type: type of element
:param filename: Name of file for export
:raises TaskRunFailed: failure during export with reason
:return: generator with results (if wait_for_finish=True), else href
:return: DownloadTask
"""
valid_types = ['all', 'nw', 'ips', 'sv', 'rb', 'al', 'vpn']
if typeof not in valid_types:
typeof = 'all'

element = prepared_request(href=self._resource.export_elements,
params={'recursive': True,
'type': typeof}
).create()

return task_handler(Task(**element.json),
wait_for_finish=wait_for_finish,
filename=filename)
task = prepared_request(
href=self._resource.export_elements,
params={'recursive': True,
'type': typeof}
).create()

return DownloadTask(
filename=filename, **task.json)

def active_alerts_ack_all(self):
"""
Acknowledge all active alerts in the SMC
:raises ActionCommandFailed: Failure during acknowledge with reason
:raises ResourceNotFound: resource supported in version >= 6.2
:return: None
Expand Down
Loading

0 comments on commit 0d59058

Please sign in to comment.