Beispiel #1
0
def engine_list(p_engine, p_username, p_format):
    """
    List Masking engines from configuration file
    param1: p_engine: name of Masking engine
    param2: p_username: username
    param3: p_format: output format
    return None if OK or integer with error, ex. no rows found
    """
    data = DataFormatter()
    data_header = [("Engine name", 30), ("IP", 30), ("username", 30),
                   ("protocol", 8), ("port", 5), ("default", 7),
                   ("proxy URL", 30), ("proxy user", 30)]
    data.create_header(data_header)
    data.format_type = p_format

    config = DxConfig()
    config.init_metadata()
    if p_engine is None:
        p_engine = 'all'
    rows = config.get_engine_info(p_engine, p_username)

    if rows is None:
        return -1

    for row in rows:
        data.data_insert(row[0], row[1], row[2], row[4], row[5], row[6],
                         row[8], row[9])
    print("")
    print(data.data_output(False))
    print("")
    return None
Beispiel #2
0
 def save(self, apikey):
     """
     Save session to file or database
     param1: apikey: Authorization key
     """
     # binary_file = open('engine.bin', mode='wb')
     # pickle.dump(apikey, binary_file)
     # binary_file.close()
     config = DxConfig()
     config.set_key(self.__name, self.__username, apikey)
Beispiel #3
0
def engine_add(p_engine, p_ip, p_username, p_password, p_protocol, p_port,
               p_default, p_proxyurl, p_proxyuser, p_proxypassword):
    """
    Add engine to a configuration
    param1: p_engine: name of Masking engine
    param2: p_ip: IP of Masking engine
    param3: p_username: username
    param4: p_password: password
    param5: p_protocol: protocol (http/https)
    param6: p_port: port
    param7: p_default: is engine default - Y/N - default value N
    param8: p_proxyurl: Proxy URL
    param9: p_proxyuser: proxy username
    param10: p_proxypassword: proxy password

    return None if OK or integer with error
    """
    config = DxConfig()
    config.init_metadata()
    if config.insert_engine_info(p_engine, p_ip, p_username, p_password,
                                 p_protocol, p_port, p_default, p_proxyurl,
                                 p_proxyuser, p_proxypassword):
        print_error("Problem with adding engine to database")
        config.close()
        return -1
    else:
        print_message("Engine added to configuration")
        config.close()
        return None
Beispiel #4
0
    def __init__(self, engine_tuple):
        """
        Constructor
        :param address: Engine addess
        :param username: username
        :param password: password
        :param port: masking port (default 8282)
        :param protocol: connection protocol (default http)
        :returns: this is a description of what is returned
        :raises keyError: raises an exception
        tuple:
        engine_name,ip_address,username,password, protocol,port, defengine, auth_id
        """

        self.__address = engine_tuple[1]
        self.__name = engine_tuple[0]
        self.__username = engine_tuple[2]
        self.__password = engine_tuple[3]
        self.__port = engine_tuple[5]
        self.__protocol = engine_tuple[4]
        self.__version = None

        self.__logger = logging.getLogger()
        self.__logger.debug("creating DxMaskingEngine object")
        self.__logger.debug(("parameters: %s %s %s %s %s" %
                             (self.__address, self.__username, self.__password,
                              self.__port, self.__protocol)))
        self.__base_url = self.__protocol + "://" + self.__address + ":" \
            + str(self.__port) + "/masking/api"

        self.config = Configuration()
        self.config.host = self.__base_url
        self.config.debug = False
        self.config.client_side_validation = False

        if engine_tuple[8]:
            #proxy settings
            dxconfig = DxConfig()
            self.config.proxy = engine_tuple[8]
            if engine_tuple[9]:
                self.config.proxyuser = engine_tuple[9]
                self.config.proxypass = dxconfig.get_proxy_password(
                    engine_tuple[9])
            else:
                self.config.proxyuser = None
                self.config.proxypass = None

        # to disable certs
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        self.config.verify_ssl = False

        if self.__logger.getEffectiveLevel() == logging.DEBUG:
            for name, logger in self.config.logger.items():
                logger.setLevel(logging.DEBUG)
                logger.removeHandler(self.config.logger_stream_handler)
Beispiel #5
0
def get_list_of_engines(p_engine):
    logger = logging.getLogger()
    # read engine from config or read all and put into list
    config = DxConfig()
    enginelist = config.get_engine_info(p_engine, None)
    logger.debug("p_engine %s enginelist %s" % (p_engine, enginelist))

    if enginelist is None or len(enginelist) == 0:
        print_error("Engine name %s not found in configuration" % p_engine)
        logger.error("Engine name %s not found in configuration" % p_engine)
        return None
    else:
        return enginelist
Beispiel #6
0
    def load(self):
        """
        Load session from file or database
        """
        # try:
        #     binary_file = open('engine.bin', mode='rb')
        #     apikey = pickle.load(binary_file)
        #     binary_file.close()
        #     return apikey
        # except IOError:
        #     print_error("Session file not found")
        #     self.__logger.error("Session file not found")

        config = DxConfig()
        auth_key = config.get_key(self.__name, self.__username)
        return auth_key
Beispiel #7
0
def engine_delete(p_engine, p_engineuser):
    """
    Delete Masking engines from configuration file
    param1: p_engine: name of Masking engine
    param2: p_username: username
    return None if OK or integer with error, ex. no rows found
    """
    config = DxConfig()
    config.init_metadata()
    if config.check_uniqness(p_engine, p_engineuser) == -1:
        return -1
    if config.delete_engine_info(p_engine, p_engineuser):
        print_error("Problem with deleting engine from database")
        config.close()
        return -1
    else:
        print_message("Engine deleted from configuration")
        config.close()
        return None
Beispiel #8
0
def get_list_of_engines(p_engine, p_username):
    logger = logging.getLogger()
    # read engine from config or read all and put into list
    config = DxConfig()

    enginelist = config.get_engine_info(p_engine, p_username)
    logger.debug("p_engine %s enginelist %s" % (p_engine, enginelist))

    if enginelist is None or len(enginelist) == 0:
        print_error("Engine name %s not found in configuration" % p_engine)
        logger.error("Engine name %s not found in configuration" % p_engine)
        return None

    if p_engine is not None and p_engine.lower() != 'all' and len(
            enginelist) != 1:
        print_error("Engine name %s is not unique - add username parameter" %
                    p_engine)
        logger.error("Engine name %s is not unique - add username parameter" %
                     p_engine)
        return None
    else:
        return enginelist
Beispiel #9
0
def engine_logout(p_engine):
    """
    logout engine in configuration
    param1: p_engine: name of Masking engine
    return None if OK or integer with error
    """
    config = DxConfig()
    config.init_metadata()
    config.set_key(p_engine, None, '')
Beispiel #10
0
def engine_logout(p_engine, p_engineuser):
    """
    logout engine in configuration
    param1: p_engine: name of Masking engine
    return None if OK or integer with error
    """
    config = DxConfig()
    config.init_metadata()
    if config.check_uniqness(p_engine, p_engineuser) == -1:
        return -1
    config.set_key(p_engine, p_engineuser, '')
    print_message("Session logged out - auth key deleted")
    return 0
Beispiel #11
0
def engine_update(p_engine, p_ip, p_username, p_password, p_protocol, p_port,
                  p_default):
    """
    Update engine in configuration
    param1: p_engine: name of Masking engine
    param2: p_ip: IP of Masking engine
    param3: p_username: username
    param4: p_password: password
    param5: p_protocol: protocol (http/https)
    param6: p_port: port
    param7: p_default: is engine default - Y/N - default value N
    return None if OK or integer with error
    """
    config = DxConfig()
    config.init_metadata()
    config.update_engine(p_engine, p_ip, p_username, p_password, p_protocol,
                         p_port, p_default)
Beispiel #12
0
    def get_session(self):
        """
        Create a session with a Masking engine
        :return autorization key for a session
        """

        self.api_client = ApiClient(self.config)
        #set number of retries to one
        # set timeout on request level as it is overwritten anyway
        # to do
        # change all requests to add timeout
        self.api_client.rest_client.pool_manager.connection_pool_kw[
            'retries'] = 0
        apikey = self.load()

        try:
            self.__logger.debug("Check if old session is valid")
            if apikey is not None:
                self.api_client.set_default_header(header_name='authorization',
                                                   header_value=apikey)
            app = ApplicationApi(self.api_client)
            app.get_all_applications(_request_timeout=self.get_timeout())

        except ApiException as e:
            if e.status == 401:
                password = DxConfig().decrypt_password(self.__password)
                if password is None:
                    print_error(
                        "Problem with password decryption. Can't connect to engine"
                    )
                    return 1
                self.__logger.debug("Logging into Delphix Masking")
                login_api = LoginApi(self.api_client)
                login = {"username": self.__username, "password": password}
                try:
                    self.__logger.debug("sending a login request. "
                                        "Username {}".format(self.__username))
                    login_response = login_api.login(
                        login, _request_timeout=self.get_timeout())
                    self.__logger.debug("login response %s" % login_response)
                    self.api_client.set_default_header(
                        header_name='authorization',
                        header_value=login_response.authorization)
                    self.save(login_response.authorization)
                    return None
                except ApiException as e:
                    print_error("Can't login to engine %s (IP: %s)" %
                                (self.__name, self.__address))
                    print_error(e.body)
                    return 1
            else:
                print_error("Something went wrong %s" % e)
                self.__logger.error("Something went wrong %s" % e)
                return 1

        except Exception as e:
            # if engine is down this one should kick off
            print_error("Can't login to engine %s (IP: %s)" %
                        (self.__name, self.__address))
            self.__logger.debug(str(e))
            return 1