import argparse
import logging
import shlex
import sys

from pytos.common.logging.logger import setup_loggers
from pytos.common.logging.definitions import COMMON_LOGGER_NAME
from pytos.common.functions.config import Secure_Config_Parser
from pytos.securechange.helpers import Secure_Change_Helper, Secure_Change_API_Handler

sys.path.append('/usr/local/orca/lib')
from common.secret_store import SecretDb
from common.third_party.generic.rest.template_client import JsonTemplateClient

secret_helper = SecretDb()
logger = logging.getLogger(COMMON_LOGGER_NAME)
conf = Secure_Config_Parser(config_file_path="/usr/local/orca/conf/custom.conf")
sc_cred = (secret_helper.get_username('securechange'), secret_helper.get_password('securechange'))
sc_host = conf.get("securechange", "host")
sc_helper = Secure_Change_Helper(sc_host, sc_cred)


def get_cli_args():
    parser = argparse.ArgumentParser('')
    parser.add_argument('--debug', action='store_true', help='Print out logging information to STDOUT.')
    # Workaround for SC not passing arguments to the script
    args = parser.parse_args(shlex.split(' '.join(sys.argv[1:])))
    return args

Exemple #2
0
import logging


from pytos.common.functions import Secure_Config_Parser
from pytos.common.definitions.xml_tags import Attributes
from pytos.common.logging.definitions import THIRD_PARTY_LOGGER_NAME
from pytos.securechange.xml_objects.restapi.step.access_request.designer import DesignerResult
from common.secret_store import SecretDb

conf = Secure_Config_Parser(config_file_path="/usr/local/orca/conf/custom.conf")
logger = logging.getLogger(THIRD_PARTY_LOGGER_NAME)
secret_helper = SecretDb()


def designer_commands(ticket):
    for step in ticket.steps[::-1]:
        task = step.get_last_task()
        try:
            multi_ar_field = task.get_field_list_by_type(Attributes.FIELD_TYPE_MULTI_ACCESS_REQUEST)[0]
        except IndexError:
            continue
        sc_cred = (
            secret_helper.get_username('securechangeworkflow'),
            secret_helper.get_password('securechangeworkflow')
        )
        designer_results = multi_ar_field.get_designer_results(*sc_cred)
        if not designer_results:
            return ''
        device_to_commands = {}
        for device_suggestion in designer_results.device_suggestion:
            try:
Exemple #3
0
from pytos.common.logging.definitions import COMMON_LOGGER_NAME
from pytos.common.functions.config import Secure_Config_Parser
from pytos.securetrack.helpers import Secure_Track_Helper
from pytos.securechange.helpers import Secure_Change_Helper
from pytos.common.definitions.xml_tags import Attributes
from pytos.common.rest_requests import POST_Request, GET_Request
from pytos.securetrack.xml_objects.rest.rules import Group_Network_Object, Subnet_Network_Object, \
    Host_Network_Object, Range_Network_Object
from pytos.securechange.xml_objects.rest import Ticket, Group_Change_Node, Elements, XML_List, \
    Group_Change_Member_Object, TYPE_HOST
from common.secret_store import SecretDb

logger = logging.getLogger(COMMON_LOGGER_NAME)
conf = Secure_Config_Parser(
    config_file_path="/usr/local/orca/conf/custom.conf")
secret_helper = SecretDb()
st_cred = (secret_helper.get_username('securetrack'),
           secret_helper.get_password('securetrack'))
sc_cred = (secret_helper.get_username('securechange'),
           secret_helper.get_password('securechange'))
sc_host = conf.get("securechange", "host")
st_host = conf.get("securetrack", "host")
sc_helper = Secure_Change_Helper(sc_host, sc_cred)
st_helper = Secure_Track_Helper(st_host, st_cred)

orca_host = conf.get("integration setup", "hostname")
ticket_template_path = conf.get("integration setup",
                                "change_group_ticket_template_path")
group_path_url = conf.get("integration setup", "group_path_url")
orca_update_task_url = conf.get("integration setup", "orca_update_task_url")