本文整理汇总了Python中cassandra.auth.PlainTextAuthProvider方法的典型用法代码示例。如果您正苦于以下问题:Python auth.PlainTextAuthProvider方法的具体用法?Python auth.PlainTextAuthProvider怎么用?Python auth.PlainTextAuthProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.auth
的用法示例。
在下文中一共展示了auth.PlainTextAuthProvider方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self, ip_addresses, cassandra_config):
self._ip_addresses = ip_addresses
self._auth_provider = None
self._ssl_context = None
self._cassandra_config = cassandra_config
if cassandra_config.cql_username is not None and cassandra_config.cql_password is not None:
auth_provider = PlainTextAuthProvider(username=cassandra_config.cql_username,
password=cassandra_config.cql_password)
self._auth_provider = auth_provider
if cassandra_config.certfile is not None and cassandra_config.usercert is not None and \
cassandra_config.userkey is not None:
ssl_context = SSLContext(PROTOCOL_TLSv1)
ssl_context.load_verify_locations(cassandra_config.certfile)
ssl_context.verify_mode = CERT_REQUIRED
ssl_context.load_cert_chain(
certfile=cassandra_config.usercert,
keyfile=cassandra_config.userkey)
self._ssl_context = ssl_context
load_balancing_policy = WhiteListRoundRobinPolicy(ip_addresses)
self._execution_profiles = {
'local': ExecutionProfile(load_balancing_policy=load_balancing_policy)
}
示例2: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self):
self.MORPHL_SERVER_IP_ADDRESS = getenv('MORPHL_SERVER_IP_ADDRESS')
self.MORPHL_CASSANDRA_USERNAME = getenv('MORPHL_CASSANDRA_USERNAME')
self.MORPHL_CASSANDRA_PASSWORD = getenv('MORPHL_CASSANDRA_PASSWORD')
self.MORPHL_CASSANDRA_KEYSPACE = getenv('MORPHL_CASSANDRA_KEYSPACE')
self.prep_stmt = {}
template_for_prediction = 'INSERT INTO ga_chp_bq_predictions (client_id,prediction) VALUES (?,?)'
template_for_predictions_by_date = 'INSERT INTO ga_chp_bq_predictions_by_prediction_date (prediction_date, client_id, prediction) VALUES (?,?,?)'
template_for_predictions_statistics = 'UPDATE ga_chp_bq_predictions_statistics SET loyal=loyal+?, neutral=neutral+?, churning=churning+?, lost=lost+? WHERE prediction_date=?'
self.CASS_REQ_TIMEOUT = 3600.0
self.auth_provider = PlainTextAuthProvider(
username=self.MORPHL_CASSANDRA_USERNAME,
password=self.MORPHL_CASSANDRA_PASSWORD)
self.cluster = Cluster(
[self.MORPHL_SERVER_IP_ADDRESS], auth_provider=self.auth_provider)
self.session = self.cluster.connect(self.MORPHL_CASSANDRA_KEYSPACE)
self.prep_stmt['prediction'] = self.session.prepare(template_for_prediction)
self.prep_stmt['predictions_by_date'] = self.session.prepare(template_for_predictions_by_date)
self.prep_stmt['predictions_statistics'] = self.session.prepare(template_for_predictions_statistics)
示例3: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self):
self.MORPHL_SERVER_IP_ADDRESS = getenv('MORPHL_SERVER_IP_ADDRESS')
self.MORPHL_CASSANDRA_USERNAME = getenv('MORPHL_CASSANDRA_USERNAME')
self.MORPHL_CASSANDRA_PASSWORD = getenv('MORPHL_CASSANDRA_PASSWORD')
self.MORPHL_CASSANDRA_KEYSPACE = getenv('MORPHL_CASSANDRA_KEYSPACE')
self.QUERY = 'SELECT * FROM ga_chp_bq_predictions WHERE client_id = ? LIMIT 1'
self.CASS_REQ_TIMEOUT = 3600.0
self.auth_provider = PlainTextAuthProvider(
username=self.MORPHL_CASSANDRA_USERNAME,
password=self.MORPHL_CASSANDRA_PASSWORD)
self.cluster = Cluster(
[self.MORPHL_SERVER_IP_ADDRESS], auth_provider=self.auth_provider)
self.session = self.cluster.connect(self.MORPHL_CASSANDRA_KEYSPACE)
self.session.row_factory = dict_factory
self.session.default_fetch_size = 100
self.prepare_statements()
示例4: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self):
self.MORPHL_SERVER_IP_ADDRESS = getenv('MORPHL_SERVER_IP_ADDRESS')
self.MORPHL_CASSANDRA_USERNAME = getenv('MORPHL_CASSANDRA_USERNAME')
self.MORPHL_CASSANDRA_PASSWORD = getenv('MORPHL_CASSANDRA_PASSWORD')
self.MORPHL_CASSANDRA_KEYSPACE = getenv('MORPHL_CASSANDRA_KEYSPACE')
self.CASS_REQ_TIMEOUT = 3600.0
self.auth_provider = PlainTextAuthProvider(
username=self.MORPHL_CASSANDRA_USERNAME,
password=self.MORPHL_CASSANDRA_PASSWORD)
self.cluster = Cluster(
[self.MORPHL_SERVER_IP_ADDRESS], auth_provider=self.auth_provider)
self.session = self.cluster.connect(self.MORPHL_CASSANDRA_KEYSPACE)
self.session.row_factory = dict_factory
self.session.default_fetch_size = 100
self.prepare_statements()
示例5: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self, config, profile='dev', hosts=['127.0.0.1'], port=9042,
user=None, password=None, host_cert_path=None,
client_key_path=None, client_cert_path=None):
self.config = config
try:
self.current_profile = self.config.profiles[profile]
except KeyError:
raise ValueError("Invalid profile name '{}'".format(profile))
if user:
auth_provider = PlainTextAuthProvider(user, password)
else:
auth_provider = None
if host_cert_path:
ssl_options = self._build_ssl_options(
host_cert_path,
client_key_path,
client_cert_path)
else:
ssl_options = None
self.cluster = Cluster(
contact_points=hosts,
port=port,
auth_provider=auth_provider,
max_schema_agreement_wait=300,
control_connection_timeout=10,
connect_timeout=30,
ssl_options=ssl_options)
self._session = None
示例6: get_auth_provider
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def get_auth_provider(user, password):
return PlainTextAuthProvider(username=user, password=password)
示例7: setup_connection
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def setup_connection(self):
assert isinstance(self.settings, CassandraSettings), self.settings
# Optionally construct an "auth provider" object.
if self.settings.username and self.settings.password:
auth_provider = PlainTextAuthProvider(
username=self.settings.username, password=self.settings.password
)
else:
auth_provider = None
# Resolve the consistency level to a driver object.
try:
consistency_level_name = self.settings.consistency.upper()
consistency_level = ConsistencyLevel.name_to_value[consistency_level_name]
except KeyError:
msg = "Cassandra consistency level name '{}' not found." "".format(
self.settings.consistency
)
raise DatasourceSettingsError(msg)
# Use the other self.settings directly.
cassandra.cqlengine.connection.setup(
hosts=self.settings.hosts,
consistency=consistency_level,
default_keyspace=self.settings.default_keyspace,
port=self.settings.port,
auth_provider=auth_provider,
protocol_version=self.settings.protocol_version,
lazy_connect=True,
retry_connect=True,
)
示例8: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self, cassandra_conn_id: str = 'cassandra_default'):
super().__init__()
conn = self.get_connection(cassandra_conn_id)
conn_config = {}
if conn.host:
conn_config['contact_points'] = conn.host.split(',')
if conn.port:
conn_config['port'] = int(conn.port)
if conn.login:
conn_config['auth_provider'] = PlainTextAuthProvider(
username=conn.login, password=conn.password)
policy_name = conn.extra_dejson.get('load_balancing_policy', None)
policy_args = conn.extra_dejson.get('load_balancing_policy_args', {})
lb_policy = self.get_lb_policy(policy_name, policy_args)
if lb_policy:
conn_config['load_balancing_policy'] = lb_policy
cql_version = conn.extra_dejson.get('cql_version', None)
if cql_version:
conn_config['cql_version'] = cql_version
ssl_options = conn.extra_dejson.get('ssl_options', None)
if ssl_options:
conn_config['ssl_options'] = ssl_options
self.cluster = Cluster(**conn_config)
self.keyspace = conn.schema
self.session = None
示例9: auth_provider_if_configured
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
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
示例10: test_init
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def test_init(self, cassandra_connect_mock):
repo = cassandra_repo.MetricsRepository()
self.assertIsNone(
repo.cluster.auth_provider,
'cassandra cluster auth provider is expected to None'
)
repo.conf.cassandra.user = 'cassandra'
repo.conf.cassandra.password = 'cassandra'
repo = cassandra_repo.MetricsRepository()
self.assertIsInstance(
repo.cluster.auth_provider,
PlainTextAuthProvider,
'cassandra cluster auth provider is expected to be PlainTextAuthProvider'
)
示例11: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self):
self.DAY_OF_DATA_CAPTURE = getenv('DAY_OF_DATA_CAPTURE')
self.MORPHL_SERVER_IP_ADDRESS = getenv('MORPHL_SERVER_IP_ADDRESS')
self.MORPHL_CASSANDRA_USERNAME = getenv('MORPHL_CASSANDRA_USERNAME')
self.MORPHL_CASSANDRA_PASSWORD = getenv('MORPHL_CASSANDRA_PASSWORD')
self.MORPHL_CASSANDRA_KEYSPACE = getenv('MORPHL_CASSANDRA_KEYSPACE')
self.CASS_REQ_TIMEOUT = 3600.0
self.auth_provider = PlainTextAuthProvider(
username=self.MORPHL_CASSANDRA_USERNAME, password=self.MORPHL_CASSANDRA_PASSWORD)
self.cluster = Cluster(
contact_points=[self.MORPHL_SERVER_IP_ADDRESS], auth_provider=self.auth_provider)
self.session = self.cluster.connect(self.MORPHL_CASSANDRA_KEYSPACE)
self.prepare_statements()
示例12: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self):
self.MORPHL_SERVER_IP_ADDRESS = getenv('MORPHL_SERVER_IP_ADDRESS')
self.MORPHL_CASSANDRA_USERNAME = getenv('MORPHL_CASSANDRA_USERNAME')
self.MORPHL_CASSANDRA_PASSWORD = getenv('MORPHL_CASSANDRA_PASSWORD')
self.MORPHL_CASSANDRA_KEYSPACE = getenv('MORPHL_CASSANDRA_KEYSPACE')
self.prep_stmt = {}
template_for_prediction = 'INSERT INTO ga_chp_predictions (client_id,prediction) VALUES (?,?)'
template_for_predictions_by_date = 'INSERT INTO ga_chp_predictions_by_prediction_date (prediction_date, client_id, prediction) VALUES (?,?,?)'
template_for_predictions_statistics = 'UPDATE ga_chp_predictions_statistics SET loyal=loyal+?, neutral=neutral+?, churning=churning+?, lost=lost+? WHERE prediction_date=?'
self.CASS_REQ_TIMEOUT = 3600.0
self.auth_provider = PlainTextAuthProvider(
username=self.MORPHL_CASSANDRA_USERNAME,
password=self.MORPHL_CASSANDRA_PASSWORD)
self.cluster = Cluster(
[self.MORPHL_SERVER_IP_ADDRESS], auth_provider=self.auth_provider)
self.session = self.cluster.connect(self.MORPHL_CASSANDRA_KEYSPACE)
self.prep_stmt['prediction'] = self.session.prepare(
template_for_prediction)
self.prep_stmt['predictions_by_date'] = self.session.prepare(
template_for_predictions_by_date)
self.prep_stmt['predictions_statistics'] = self.session.prepare(
template_for_predictions_statistics)
示例13: __init__
# 需要导入模块: from cassandra import auth [as 别名]
# 或者: from cassandra.auth import PlainTextAuthProvider [as 别名]
def __init__(self):
try:
self.conf = cfg.CONF
if self.conf.cassandra.user:
auth_provider = PlainTextAuthProvider(username=self.conf.cassandra.user,
password=self.conf.cassandra.password)
else:
auth_provider = None
self.cluster = Cluster(self.conf.cassandra.contact_points,
port=self.conf.cassandra.port,
auth_provider=auth_provider,
connect_timeout=self.conf.cassandra.connection_timeout,
load_balancing_policy=TokenAwarePolicy(
DCAwareRoundRobinPolicy(
local_dc=self.conf.cassandra.local_data_center))
)
self.session = self.cluster.connect(self.conf.cassandra.keyspace)
self.dim_val_by_metric_stmt = self.session.prepare(DIMENSION_VALUE_BY_METRIC_CQL)
self.dim_val_stmt = self.session.prepare(DIMENSION_VALUE_CQL)
self.dim_name_by_metric_stmt = self.session.prepare(DIMENSION_NAME_BY_METRIC_CQL)
self.dim_name_stmt = self.session.prepare(DIMENSION_NAME_CQL)
self.metric_name_by_dimension_stmt = self.session.prepare(METRIC_NAME_BY_DIMENSION_CQL)
self.metric_name_by_dimension_offset_stmt = self.session.prepare(
METRIC_NAME_BY_DIMENSION_OFFSET_CQL)
self.metric_name_stmt = self.session.prepare(METRIC_NAME_CQL)
self.metric_name_offset_stmt = self.session.prepare(METRIC_NAME_OFFSET_CQL)
self.metric_by_id_stmt = self.session.prepare(METRIC_BY_ID_CQL)
except Exception as ex:
LOG.exception(ex)
raise exceptions.RepositoryException(ex)
self.epoch = datetime.utcfromtimestamp(0)