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

Commit

Permalink
v0.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gabstopper committed Dec 26, 2017
1 parent 09d36a2 commit bf7511b
Show file tree
Hide file tree
Showing 55 changed files with 1,523 additions and 1,969 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ exclude_lines =
if recursive and is_pkg
string_types
super
unicode = str
unicode = unicode
8 changes: 4 additions & 4 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ Release History
- Sending empty payload on POST request with parameters might cause validation error. Do not submit empty
dict with POST requests.

0.5.7
0.5.8
-----

**Improvements**

- Support for SMC version 6.3.0, 6.3.1 and 6.3.2
- Add ``case_sensitive`` key word to filtered queries. This requires SMC 6.3+. Set this as a kwarg when making
the query: Host.objects.filter('myhost', case_sensitive=False). Default: case_sensitive=True.
- Optimize retrieval of nodes by serializing engine node data versus making a call to the engine links. This eliminates
Expand Down Expand Up @@ -88,11 +89,10 @@ Release History
- remove_vlan on interface no longer requires the interface reference, however now requires the interface context to run. Before:
engine.physical_interface.remove_vlan(interface_id=100, vlan_id=1), now you need to load the interface, then delete the
vlan: interface = engine.interface.get(100); interface.remove_vlan(1)
- history property on Element added



**Bugfixes**

- If a search is provided in format: Host.objects.filter(address='1.1.1.1').first(), and the search returns meta, but the
- If a search is provided in format: Host.objects.filter(address='1.1.1.1').first(), and the search returns meta but the
filtered results do not return a match, the method tries to pop from an empty list. Return None instead.

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Python 3.4, 3.5

Requests >= 2.12.0

Security Management Center version 6.0, 6.1, 6.1.1, 6.1.2, 6.2, 6.2.1, 6.3.0
Security Management Center version 6.0, 6.1, 6.1.1, 6.1.2, 6.2, 6.2.1, 6.3.0, 6.3.1, 6.3.2

Getting Started
---------------
Expand All @@ -52,7 +52,7 @@ Use pip to get latest released version:

Specific version:

``pip install smc-python>=0.5.5``
``pip install smc-python>=0.5.8``

If you are installing directly from git or tarball, you will be installing
the latest dev branch. The dev branch does undergo unittest prior to push,
Expand Down
6 changes: 3 additions & 3 deletions smc-monitoring/smc_monitoring/models/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def within_ipv4_network(self, field, values):
This filter adds specified networks to a filter to check
for inclusion.
:param str name of field to filter on. Taken from 'Show Filter
:param str field: name of field to filter on. Taken from 'Show Filter
Expression' within SMC.
:param list values: network definitions, in cidr format, i.e: 1.1.1.0/24.
"""
Expand All @@ -279,7 +279,7 @@ def within_ipv4_range(self, field, values):
Add an IP range network filter for relevant address fields.
Range (between) filters allow only one range be provided.
:param str name of field to filter on. Taken from 'Show Filter
:param str field: name of field to filter on. Taken from 'Show Filter
Expression' within SMC.
:param list values: IP range values. Values would be a list of IP's
separated by a '-', i.e. ['1.1.1.1-1.1.1.254']
Expand All @@ -295,7 +295,7 @@ def exact_ipv4_match(self, field, values):
"""
An exact IPv4 address match on relevant address fields.
:param str name of field to filter on. Taken from 'Show Filter
:param str field: name of field to filter on. Taken from 'Show Filter
Expression' within SMC.
:param list values: value/s to add. If more than a single value is
provided, the query is modified to use UNION vs. ==
Expand Down
62 changes: 23 additions & 39 deletions smc/administration/access_rights.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
access permissions to either Engines, Policies or Domains.
"""

from smc.base.model import Element, ElementCreator
from smc.base.model import Element, ElementCreator, SubDict
from smc.base.util import element_resolver
from smc.administration.system import AdminDomain

Expand All @@ -22,9 +22,6 @@ class AccessControlList(Element):
"""
typeof = 'access_control_list'

def __init__(self, name, **meta):
super(AccessControlList, self).__init__(name, **meta)

@classmethod
def create(cls, name, granted_element=None):
"""
Expand Down Expand Up @@ -86,7 +83,7 @@ def remove_permission(self, elements):
self.update()


class Permission(object):
class Permission(SubDict):
"""
Permissions are added to admin users that do not have super user access
rights. An Admin User can also have multiple permissions. There are three
Expand All @@ -99,15 +96,18 @@ class Permission(object):
A permission might be used to grant read-only access to specific policies
or firewalls (read-only vs read write). It can also be specific to the
Admin Domain.
.. seealso:: :py:mod:`smc.elements.user`
"""
def __init__(self, granted_elements=None, role_ref=None,
granted_domain_ref=None):
self._domain = granted_domain_ref
self._role = role_ref
self._elements = granted_elements

def __init__(self, granted_elements=None, role_ref=None, granted_domain_ref=None):
data = dict(
granted_domain_ref=element_resolver(granted_domain_ref),
role_ref=element_resolver(role_ref),
granted_elements=element_resolver(granted_elements))
super(Permission, self).__init__(data=data)

@classmethod
def create(cls, granted_elements, role, domain=None):
def create(cls, elements, role, domain=None):
"""
Create a permission.
Expand All @@ -120,12 +120,9 @@ def create(cls, granted_elements, role, domain=None):
"""
if not domain:
domain = AdminDomain('Shared Domain')
json = {
'granted_domain_ref': element_resolver(domain),
'role_ref': element_resolver(role),
'granted_elements': element_resolver(granted_elements)}

return Permission(**json)

return Permission(
granted_elements=elements, role_ref=role, granted_domain_ref=domain)

@property
def granted_elements(self):
Expand All @@ -135,41 +132,28 @@ def granted_elements(self):
:rtype: list(Element)
"""
return [Element.from_href(element) for element in self._elements]
return [Element.from_href(element) for element in self.get('granted_elements')]

@property
def role_ref(self):
def role(self):
"""
Specific Role assigned to this permission. A role is what allows read/write
access to specific operations on the granted elements
:rtype: Role
"""
return Element.from_href(self._role)
return Element.from_href(self.get('role_ref'))

@property
def granted_domain_ref(self):
def domain(self):
"""
Domain this permission applies to. Shared Domain if unspecified.
:rtype: AdminDomain
"""
return Element.from_href(self._domain)

def _as_dict(self):
"""
Internal representation in dict format. Used when adding permission
to AdminUser.
"""
return {'granted_domain_ref': self._domain,
'role_ref': self._role,
'granted_elements': self._elements}
return Element.from_href(self.get('granted_domain_ref', 'Shared Domain'))

def __repr__(self):
return "{0}(granted_elements={1},role_ref='{2}',granted_domain_ref='{3}')"\
.format(
self.__class__.__name__,
self.granted_elements,
self.role_ref,
self.granted_domain_ref
)
return "Permission(elements={}, role={}, domain={})"\
.format(self.granted_elements, self.role, self.domain)

12 changes: 2 additions & 10 deletions smc/administration/certificates/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ class TLSCertificateAuthority(ImportExportCertificate, Element):
"""
typeof = 'tls_certificate_authority'

def __init__(self, name, **meta):
super(TLSCertificateAuthority, self).__init__(name, **meta)

@classmethod
def create(cls, name, certificate):
"""
Expand Down Expand Up @@ -161,9 +158,6 @@ class TLSServerCredential(ImportExportIntermediate, ImportPrivateKey,
"""
typeof = 'tls_server_credentials'

def __init__(self, name, **meta):
super(TLSServerCredential, self).__init__(name, **meta)

@classmethod
def create(cls, name):
"""
Expand Down Expand Up @@ -359,7 +353,8 @@ def self_sign(self):
:raises ActionCommandFailed: failed to sign with reason
"""
return self.send_cmd(
return self.make_request(
method='create',
resource='self_sign')


Expand Down Expand Up @@ -387,9 +382,6 @@ class ClientProtectionCA(ImportPrivateKey, ImportExportCertificate, Element):
"""
typeof = 'tls_signing_certificate_authority'

def __init__(self, name, **meta):
super(ClientProtectionCA, self).__init__(name, **meta)

@classmethod
def import_signed(cls, name, certificate_file, private_key_file):
"""
Expand Down
25 changes: 19 additions & 6 deletions smc/administration/certificates/tls_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def load_cert_chain(chain_file):
:raises IOError: Failure to read specified file
:raises ValueError: Format issues with chain file or missing entries
:return list of cert type matches
:return: list of cert type matches
"""
with open(chain_file, 'rb') as f:
cert_chain = f.read()
Expand Down Expand Up @@ -67,8 +67,9 @@ def import_certificate(self, certificate):
"""
multi_part = 'signed_certificate' if self.typeof == 'tls_server_credentials'\
else 'certificate'
self.send_cmd(
self.make_request(
CertificateImportError,
method='create',
resource='certificate_import',
headers = {'content-type': 'multipart/form-data'},
files={
Expand All @@ -85,7 +86,7 @@ def export_certificate(self, filename=None):
:raises CertificateExportError: error exporting certificate
:rtype: str or None
"""
result = self.read_cmd(
result = self.make_request(
CertificateExportError,
raw_result=True,
resource='certificate_export')
Expand All @@ -103,8 +104,19 @@ class ImportExportIntermediate(object):
certificates
"""
def import_intermediate_certificate(self, certificate):
self.send_cmd(
"""
Import a valid certificate. Certificate can be either a file path
or a string of the certificate. If string certificate, it must include
the -----BEGIN CERTIFICATE----- string.
:param str certificate: fully qualified path or string
:raises CertificateImportError: failure to import cert with reason
:raises IOError: file not found, permissions, etc.
:return: None
"""
self.make_request(
CertificateImportError,
method='create',
resource='intermediate_certificate_import',
headers = {'content-type': 'multipart/form-data'},
files={
Expand All @@ -122,7 +134,7 @@ def export_intermediate_certificate(self, filename=None):
if no intermediate certificate is available.
:rtype: str or None
"""
result = self.read_cmd(
result = self.make_request(
CertificateExportError,
raw_result=True,
resource='intermediate_certificate_export')
Expand Down Expand Up @@ -151,8 +163,9 @@ def import_private_key(self, private_key):
:raises IOError: file not found, permissions, etc.
:return: None
"""
self.send_cmd(
self.make_request(
CertificateImportError,
method='create',
resource='private_key_import',
headers = {'content-type': 'multipart/form-data'},
files={
Expand Down
19 changes: 7 additions & 12 deletions smc/administration/certificates/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
a VPN CA and uses the default internal CA by default.
"""

from smc.base.model import Element, ElementCreator, SubElement
from smc.base.model import Element, ElementCreator, SubElement,\
SubElementCreator
from smc.administration.certificates.tls_common import ImportExportCertificate
from smc.api.exceptions import CertificateError
from smc.base.util import element_resolver
Expand All @@ -24,9 +25,6 @@ class VPNCertificateCA(ImportExportCertificate, Element):
"""
typeof = 'vpn_certificate_authority'

def __init__(self, name, **meta):
super(VPNCertificateCA, self).__init__(name, **meta)

@classmethod
def create(cls, name, certificate):
"""
Expand All @@ -53,8 +51,7 @@ class GatewayCertificate(SubElement):
renew a gateway certificate, export, check the expiration, or
find the certificate authority that signed this gateway certificate.
"""
def __init__(self, **meta):
super(GatewayCertificate, self).__init__(**meta)
typeof = 'gateway_certificate'

@staticmethod
def _create(self, common_name, public_key_algorithm='rsa',
Expand All @@ -69,19 +66,17 @@ def _create(self, common_name, public_key_algorithm='rsa',

cert_auth = element_resolver(signing_ca)

cert = self.internal_gateway.send_cmd(
return SubElementCreator(
GatewayCertificate,
CertificateError,
resource='generate_certificate',
raw_result=True,
href=self.internal_gateway.get_relation('generate_certificate'),
json={
'common_name': common_name,
'public_key_algorithm': public_key_algorithm,
'signature_algorithm': signature_algorithm,
'public_key_length': key_length,
'certificate_authority_href': cert_auth})

return GatewayCertificate(href=cert.href)


@property
def certificate_authority(self):
return Element.from_href(self.data.get('certificate_authority'))
Expand Down
Loading

0 comments on commit bf7511b

Please sign in to comment.