Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to revisions class #14

Merged
merged 4 commits into from
Nov 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions pytos/securetrack/xml_objects/rest/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,16 @@ def from_xml_node(cls, xml_node):


class Device_Revision(XML_Object_Base):
AUTHORIZED_STATUSES = ("AUTOMATICALLY_AUTHORIZED", "MANUALLY_AUTHORIZED")
UNAUTHORIZED_STATUSES = ("AUTOMATICALLY_UNAUTHORIZED", "MANUALLY_UNAUTHORIZED")

AUTHORIZED_STATUSES = ("AUTOMATICALLY_AUTHORIZED", "MANUALLY_AUTHORIZED","authorized")
UNAUTHORIZED_STATUSES = ("AUTOMATICALLY_UNAUTHORIZED", "MANUALLY_UNAUTHORIZED","unauthorized")
OTHER_STATUSES = ("N_A", "CALCULATING", "ERROR", "PENDING")

REVISION_DATE_FORMAT_STRING = "%Y-%m-%d"
REVISION_TIME_FORMAT_STRING = "%H:%M:%S.%f"

def __init__(self, action, num_id, admin, auditLog, authorizationStatus, revision_date, revision_time, gui_client,
revision_id, modules_and_policy, policy_package, ready):
revision_id, modules_and_policy, policy_package, ready, tickets=None):
self.action = action
self.admin = admin
self.auditLog = auditLog
Expand All @@ -235,6 +237,7 @@ def __init__(self, action, num_id, admin, auditLog, authorizationStatus, revisio
self.revisionId = revision_id
self.time = revision_time
self.ready = ready
self.tickets = tickets
super().__init__(xml_tags.Elements.REVISION)

@classmethod
Expand Down Expand Up @@ -262,8 +265,14 @@ def from_xml_node(cls, xml_node):
revision_id = get_xml_int_value(xml_node, xml_tags.Elements.REVISIONID)
revision_time = get_xml_text_value(xml_node, xml_tags.Elements.TIME)
ready = get_xml_text_value(xml_node, xml_tags.Elements.READY)
ticket = []
for ticket_node in xml_node.iter(tag=xml_tags.Elements.TICKET):
ticket_obj = Device_Revision_Ticket.from_xml_node(ticket_node)
ticket.append(ticket_obj)


return cls(action, num_id, admin, auditLog, authorizationStatus, revision_date, revision_time, gui_client,
revision_id, modules_and_policy, policy_package, ready)
revision_id, modules_and_policy, policy_package, ready,ticket)

def is_authorized(self):
return self.authorizationStatus in Device_Revision.AUTHORIZED_STATUSES
Expand All @@ -290,7 +299,18 @@ def get_revision_datetime(self):
logger.error("Could not parse date time '{}' using format string '{}'".format(datetime_str, datetime_frmt))
raise error


class Device_Revision_Ticket (XML_Object_Base):
""" Ticket object for device revision"""
def __init__(self, ticket_id, source):
self.id = ticket_id
self.source = source
super().__init__(xml_tags.Elements.TICKET)

@classmethod
def from_xml_node(cls,xml_node):
ticket_id = get_xml_int_value(xml_node,xml_tags.Elements.ID)
source = get_xml_text_value(xml_node,xml_tags.Elements.SOURCE)
return cls(ticket_id,source)

class RuleSearchDevice(XML_Object_Base):
"""Device object that return from rule_search API based on the rule documentation"""
Expand Down