Beispiel #1
0
    def __init__(self, dbName, broker, username, password, options):
        """Constructor for the Connection class.
        
        Arguments:
        dbName -- Name of database you are accessing.
        broker -- Address of the broker you are connecting too.
        username -- NuoDB username.
        password -- NuoDB password.
        options -- A dictionary of NuoDB connection options
            Some common options include:
            "schema"
        
        Returns:
        a Connection instance
        """
        (host, port) = getCloudEntry(broker, dbName)
        self.__session = EncodedSession(host, port)
        self._trans_id = None

        cp = ClientPassword()
        
        parameters = {'user' : username, 'timezone' : time.strftime('%Z')}
        if options:
            parameters.update(options)

        self.__session.putMessageId(protocol.OPENDATABASE).putInt(protocol.EXECUTEPREPAREDUPDATE).putString(dbName).putInt(len(parameters))
        for (k, v) in parameters.iteritems():
            self.__session.putString(k).putString(v)
        self.__session.putNull().putString(cp.genClientKey())

        self.__session.exchangeMessages()

        version = self.__session.getInt()
        serverKey = self.__session.getString()
        salt = self.__session.getString()

        sessionKey = cp.computeSessionKey(string.upper(username), password, salt, serverKey)
        self.__session.setCiphers(RC4Cipher(sessionKey), RC4Cipher(sessionKey))

        # check auth
        try:
            self.__session.putMessageId(protocol.AUTHENTICATION).putString('Success!')
            self.__session.exchangeMessages()
        except SessionException:
            raise ProgrammingError('Invalid database username or password')
            
        
        # set auto commit to false by default
        self.__session.putMessageId(protocol.SETAUTOCOMMIT).putInt(0)
        
        self.__session.exchangeMessages(False)
Beispiel #2
0
    def __init__(self, dbName, broker, username, password, options):
        """Constructor for the Connection class.
        
        Arguments:
        dbName -- Name of database you are accessing.
        broker -- Address of the broker you are connecting too.
        username -- NuoDB username.
        password -- NuoDB password.
        options -- A dictionary of NuoDB connection options
            Some common options include:
            "schema"
        
        Returns:
        a Connection instance

        @type dbName str
        @type broker str
        @type username str
        @type password str
        @type options dict[str,str]
        """
        (host, port) = getCloudEntry(broker, dbName)
        self.__session = EncodedSession(host, port)
        self._trans_id = None

        cp = ClientPassword()

        parameters = {'user': username, 'timezone': time.strftime('%Z')}
        if options:
            parameters.update(options)

        version, serverKey, salt = self.__session.open_database(
            dbName, parameters, cp)

        sessionKey = cp.computeSessionKey(string.upper(username), password,
                                          salt, serverKey)
        self.__session.setCiphers(RC4Cipher(sessionKey), RC4Cipher(sessionKey))

        self.__session.check_auth()

        # set auto commit to false by default per PEP
        self.__session.set_autocommit(0)
Beispiel #3
0
    def __init__(self, dbName, broker, username, password, options):
        """Constructor for the Connection class.
        
        Arguments:
        dbName -- Name of database you are accessing.
        broker -- Address of the broker you are connecting too.
        username -- NuoDB username.
        password -- NuoDB password.
        options -- A dictionary of NuoDB connection options
            Some common options include:
            "schema"
        
        Returns:
        a Connection instance

        @type dbName str
        @type broker str
        @type username str
        @type password str
        @type options dict[str,str]
        """
        (host, port) = getCloudEntry(broker, dbName)
        self.__session = EncodedSession(host, port)
        self._trans_id = None

        cp = ClientPassword()
        
        parameters = {'user' : username, 'timezone' : time.strftime('%Z')}
        if options:
            parameters.update(options)

        version, serverKey, salt = self.__session.open_database(dbName, parameters, cp)

        sessionKey = cp.computeSessionKey(string.upper(username), password, salt, serverKey)
        self.__session.setCiphers(RC4Cipher(sessionKey), RC4Cipher(sessionKey))

        self.__session.check_auth()

        # set auto commit to false by default per PEP
        self.__session.set_autocommit(0)