Beispiel #1
0
def createSshUnixSocket(remoteUnixSocketPath, username, host, port, sshKey):
  if not validate.filepath(remoteUnixSocketPath):
    raise ValueError( "sql.query.createSshUnixSocket"
                    , "File path not permitted: '{path}'".format(path=remoteUnixSocketPath))
  if not validate.linuxUsername(username):
    raise ValueError( "sql.query.createSshUnixSocket"
                    , "Invalid ssh username: '******'".format(user=username))
  if not validate.hostname(host):
    raise ValueError( "sql.query.createSshUnixSocket"
                    , "Invalid ssh hostname: '{host}'".format(host=host))

  port                = int(port)
  localUnixSocketPath = getNewTempFilePath()
  sshKeyPath          = getNewTempFilePath()

  # 0600 permissions required by ssh
  with os.fdopen(os.open(sshKeyPath, os.O_WRONLY | os.O_CREAT, 0600), 'w') as f:
    f.write(sshKey)
Beispiel #2
0
def createSshUnixSocket(remoteUnixSocketPath, username, host, port, sshKey):
    if not validate.filepath(remoteUnixSocketPath):
        raise ValueError(
            "sql.query.createSshUnixSocket",
            "File path not permitted: '{path}'".format(
                path=remoteUnixSocketPath))
    if not validate.linuxUsername(username):
        raise ValueError(
            "sql.query.createSshUnixSocket",
            "Invalid ssh username: '******'".format(user=username))
    if not validate.hostname(host):
        raise ValueError("sql.query.createSshUnixSocket",
                         "Invalid ssh hostname: '{host}'".format(host=host))

    port = int(port)
    localUnixSocketPath = getNewTempFilePath()
    sshKeyPath = getNewTempFilePath()

    # 0600 permissions required by ssh
    with os.fdopen(os.open(sshKeyPath, os.O_WRONLY | os.O_CREAT, 0600),
                   'w') as f:
        f.write(sshKey)
Beispiel #3
0
  def __init__(self,  **kwargs):
    super(SqlConn, self).__init__()
    self.opened = False

    sslCert = kwargs.get('db_ssl_cert')
    if sslCert is not None:
      # Write certificate to temp file for MySQL to access
      # Yeah, this sucks.
      certFilePath = getNewTempFilePath()
      with open(certFilePath, 'w') as f:
        f.write(sslCert)

      kwargs['db_ssl_cert_path'] = certFilePath

    self.db        = self._connect(**kwargs)
    self.dbName    = kwargs['db_name']
    self.opened    = True
    self.queryType = SqlQuery

    if sslCert is not None:
      os.remove(certFilePath)