cassandra.auth.PlainTextAuthProvider

Here are the examples of the python api cassandra.auth.PlainTextAuthProvider taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

11 Examples 7

Example 1

    def get_authentication_provider(self, username, password):
        """
        Return correct authentication provider based on protocol version.
        There is a difference in the semantics of authentication provider argument with protocol versions 1 and 2
        For protocol version 2 and higher it should be a PlainTextAuthProvider object.
        For protocol version 1 it should be a function taking hostname as an argument and returning a dictionary
        containing username and password.
        :param username: authentication username
        :param password: authentication password
        :return: authentication object suitable for Cluster.connect()
        """
        if PROTOCOL_VERSION < 2:
            return lambda hostname: dict(username=username, password=password)
        else:
            return PlainTextAuthProvider(username=username, password=password)

Example 2

Project: trireme
License: View license
Source File: cassandra.py
def connect(migration_keyspace):
    global cluster, session

    # Setup the auth provider
    auth_provider = PlainTextAuthProvider(username=username, password=password)

    # Contact to Cassandra
    cluster = Cluster(contact_points, auth_provider=auth_provider)
    session = cluster.connect(migration_keyspace)

Example 3

Project: django-cassandra-engine
License: View license
Source File: connection.py
Function: init
    def __init__(self, **options):

        self.hosts = options.get('HOST').split(',')
        self.keyspace = options.get('NAME')
        self.user = options.get('USER')
        self.password = options.get('PASSWORD')
        self.options = options.get('OPTIONS', {})
        self.connection_options = self.options.get('connection', {})
        self.session_options = self.options.get('session', {})

        if self.user and self.password and \
                'auth_provider' not in self.connection_options:
            self.connection_options['auth_provider'] = \
                PlainTextAuthProvider(username=self.user,
                                      password=self.password)

        self.lock = Lock()
        self.session = None
        self.cluster = None
        self.setup()

Example 4

Project: cassandra-dtest
License: View license
Source File: dtest.py
Function: get_auth_provider
def get_auth_provider(user, password):
    return PlainTextAuthProvider(username=user, password=password)

Example 5

Project: cyanite-utils
License: View license
Source File: CyaniteCassandra.py
    def __init__(self, config):
        self.config = config
        auth_provider = None
        if config.clusteruser():
            auth_provider = PlainTextAuthProvider(
                    username=config.clusteruser(),
                    password=config.clusterpass()
                    )
        self.cluster = Cluster(
                config.cluster(),
                auth_provider=auth_provider
                )
        self.session = self.cluster.connect(config.keyspace())
        self.deletequery = self.session.prepare(
            """
            DELETE FROM metric
            WHERE tenant=''
                AND period=?
                AND rollup=?
                AND path=?
            """)

Example 6

Project: cstar_perf
License: View license
Source File: util.py
def auth_provider_if_configured(config):
    if config.has_option('server', 'cassandra_user') and config.has_option('server', 'cassandra_password'):
        from cassandra.auth import PlainTextAuthProvider
        return PlainTextAuthProvider(username=config.get('server', 'cassandra_user'), password=config.get('server', 'cassandra_password'))
    return None

Example 7

Project: redash
License: View license
Source File: cass.py
    def run_query(self, query, user):
        from cassandra.cluster import Cluster
        connection = None
        try:
            if self.configuration.get('username', '') and self.configuration.get('password', ''):
                from cassandra.auth import PlainTextAuthProvider
                auth_provider = PlainTextAuthProvider(username='{}'.format(self.configuration.get('username', '')),
                                                      password='{}'.format(self.configuration.get('password', '')))
                connection = Cluster([self.configuration.get('host', '')], auth_provider=auth_provider)
            else:
                connection = Cluster([self.configuration.get('host', '')])

            session = connection.connect()
            logger.debug("Cassandra running query: %s", query)
            result = session.execute(query)

            column_names = result.column_names

            columns = self.fetch_columns(map(lambda c: (c, 'string'), column_names))

            rows = [dict(zip(column_names, row)) for row in result]

            data = {'columns': columns, 'rows': rows}
            json_data = json.dumps(data, cls=JSONEncoder)

            error = None

        except cassandra.cluster.Error, e:
            error = e.args[1]
        except KeyboardInterrupt:
            error = "Query cancelled by user."

        return json_data, error

Example 8

Project: cassandradump
License: View license
Source File: cassandradump.py
def setup_cluster():
    if args.host is None:
        nodes = ['localhost']
    else:
        nodes = [args.host]

    if args.port is None:
        port = 9042
    else:
        port = args.port

    cluster = None

    if args.protocol_version is not None:
        auth = None

        if args.username is not None and args.password is not None:
            if args.protocol_version == 1:
                auth = get_credentials
            elif args.protocol_version > 1:
                auth = PlainTextAuthProvider(username=args.username, password=args.password)

        cluster = Cluster(contact_points=nodes, port=port, protocol_version=args.protocol_version, auth_provider=auth, load_balancing_policy=cassandra.policies.WhiteListRoundRobinPolicy(nodes))
    else:
        cluster = Cluster(contact_points=nodes, port=port, load_balancing_policy=cassandra.policies.WhiteListRoundRobinPolicy(nodes))

    session = cluster.connect()

    session.default_timeout = TIMEOUT
    session.default_fetch_size = FETCH_SIZE
    session.row_factory = cassandra.query.ordered_dict_factory
    return session

Example 9

Project: poppy
License: View license
Source File: driver.py
def _connection(conf, datacenter, keyspace=None):
    """connection.

    :param datacenter
    :returns session
    """
    ssl_options = None
    if conf.ssl_enabled:
        ssl_options = {
            'ca_certs': conf.ssl_ca_certs,
            'ssl_version': ssl.PROTOCOL_TLSv1
        }

    auth_provider = None
    if conf.auth_enabled:
        auth_provider = auth.PlainTextAuthProvider(
            username=conf.username,
            password=conf.password
        )

    load_balancing_policy_class = getattr(policies, conf.load_balance_strategy)
    if load_balancing_policy_class is policies.DCAwareRoundRobinPolicy:
        load_balancing_policy = load_balancing_policy_class(datacenter)
    else:
        load_balancing_policy = load_balancing_policy_class()

    cluster_connection = cluster.Cluster(
        conf.cluster,
        auth_provider=auth_provider,
        load_balancing_policy=load_balancing_policy,
        port=conf.port,
        ssl_options=ssl_options,
        max_schema_agreement_wait=conf.max_schema_agreement_wait
    )

    session = cluster_connection.connect()
    if not keyspace:
        keyspace = conf.keyspace
    try:
        session.set_keyspace(keyspace)
    except cassandra.InvalidRequest:
        _create_keyspace(session, keyspace, conf.replication_strategy)

    if conf.automatic_schema_migration:
        migration_session = copy.copy(session)
        migration_session.default_consistency_level = \
            getattr(cassandra.ConsistencyLevel,
                    conf.migrations_consistency_level)
        _run_migrations(conf.migrations_path, migration_session)

    session.row_factory = query.dict_factory

    return session

Example 10

Project: poppy
License: View license
Source File: delete_service_name_nulls.py
def cassandra_connection(env, config):
    ssl_options = None
    if config.get(env, 'ssl_enabled'):
        ssl_options = {}
        ssl_options['ca_certs'] = config.get(env, 'ssl_ca_certs')
        ssl_options['ssl_version'] = config.get(env, 'ssl_version')
        if ssl_options['ssl_version'] == 'TLSv1':
            ssl_options['ssl_version'] = ssl.PROTOCOL_TLSv1
        elif ssl_options['ssl_version'] == 'TLSv1.1':
            ssl_options['ssl_version'] = ssl.PROTOCOL_TLSv1_1
        elif ssl_options['ssl_version'] == 'TLSv1.2':
            ssl_options['ssl_version'] = ssl.PROTOCOL_TLSv1_2
        else:
            print('Unknown SSL Version')
            sys.exit(4)

    auth_provider = None
    if config.get(env, 'auth_enabled'):
        auth_provider = auth.PlainTextAuthProvider(
            username=config.get(env, 'username'),
            password=config.get(env, 'password')
        )

    cluster_connection = cluster.Cluster(
        config.get(env, 'cluster').split(","),
        auth_provider=auth_provider,
        port=config.get(env, 'port'),
        ssl_options=ssl_options,
    )

    return cluster_connection

Example 11

Project: poppy
License: View license
Source File: sync_cert_status.py
def cassandra_connection(env, config):
    ssl_options = None
    if config.getboolean(env, 'ssl_enabled'):
        ssl_options = dict()
        ssl_options['ca_certs'] = config.get(env, 'ssl_ca_certs')
        ssl_options['ssl_version'] = config.get(env, 'ssl_version')
        if ssl_options['ssl_version'] == 'TLSv1':
            ssl_options['ssl_version'] = ssl.PROTOCOL_TLSv1
        elif ssl_options['ssl_version'] == 'TLSv1.1':
            ssl_options['ssl_version'] = ssl.PROTOCOL_TLSv1_1
        elif ssl_options['ssl_version'] == 'TLSv1.2':
            ssl_options['ssl_version'] = ssl.PROTOCOL_TLSv1_2
        else:
            print('Unknown SSL Version')
            sys.exit(4)

    auth_provider = None
    if config.getboolean(env, 'auth_enabled'):
        auth_provider = auth.PlainTextAuthProvider(
            username=config.get(env, 'username'),
            password=config.get(env, 'password')
        )

    cluster_connection = cluster.Cluster(
        config.get(env, 'cluster').split(","),
        auth_provider=auth_provider,
        port=config.getint(env, 'port'),
        ssl_options=ssl_options,
    )

    return cluster_connection