本文整理汇总了Python中couchbase.cluster.Cluster.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.authenticate方法的具体用法?Python Cluster.authenticate怎么用?Python Cluster.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchbase.cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.authenticate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_xattr_data
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
def create_xattr_data(self, type="system"):
cluster = Cluster('couchbase://'+str(self.master.ip))
authenticator = PasswordAuthenticator(self.username, self.password)
cluster.authenticate(authenticator)
cb = cluster.open_bucket('default')
docs = self.get_meta_ids()
self.log.info("Docs: " + str(docs[0:5]))
xattr_data = []
self.log.info("Adding xattrs to data")
val = 0
for doc in docs:
if type == "system":
rv = cb.mutate_in(doc["id"], SD.upsert('_system1', val, xattr=True, create_parents=True))
xattr_data.append({'_system1': val})
rv = cb.mutate_in(doc["id"], SD.upsert('_system2', {'field1': val, 'field2': val*val}, xattr=True, create_parents=True))
xattr_data.append({'_system2': {'field1': val, 'field2': val*val}})
rv = cb.mutate_in(doc["id"], SD.upsert('_system3', {'field1': {'sub_field1a': val, 'sub_field1b': val*val}, 'field2': {'sub_field2a': 2*val, 'sub_field2b': 2*val*val}}, xattr=True, create_parents=True))
xattr_data.append({'_system3': {'field1': {'sub_field1a': val, 'sub_field1b': val*val}, 'field2': {'sub_field2a': 2*val, 'sub_field2b': 2*val*val}}})
if type == "user":
rv = cb.mutate_in(doc["id"], SD.upsert('user1', val, xattr=True, create_parents=True))
xattr_data.append({'user1': val})
rv = cb.mutate_in(doc["id"], SD.upsert('user2', {'field1': val, 'field2': val*val}, xattr=True, create_parents=True))
xattr_data.append({'user2': {'field1': val, 'field2': val*val}})
rv = cb.mutate_in(doc["id"], SD.upsert('user3', {'field1': {'sub_field1a': val, 'sub_field1b': val*val}, 'field2': {'sub_field2a': 2*val, 'sub_field2b': 2*val*val}}, xattr=True, create_parents=True))
xattr_data.append({'user3': {'field1': {'sub_field1a': val, 'sub_field1b': val*val}, 'field2': {'sub_field2a': 2*val, 'sub_field2b': 2*val*val}}})
val = val + 1
self.log.info("Completed adding " + type + "xattrs to data to " + str(val) + " docs")
return xattr_data
示例2: _createConn
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
def _createConn(self):
try:
cluster = Cluster(self.connection_string, bucket_class=CouchbaseBucket)
cluster.authenticate(PasswordAuthenticator(self.bucket, 'password'))
self.cb = cluster.open_bucket(self.bucket)
except BucketNotFoundError:
raise
示例3: _create_cluster
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
def _create_cluster(self):
connargs = self.make_connargs()
connstr = ConnectionString.parse(str(connargs.pop('connection_string')))
connstr.clear_option('username')
bucket = connstr.bucket
connstr.bucket = None
password = connargs.get('password', '')
# Can I open a new bucket via open_bucket?
cluster = Cluster(connstr, bucket_class=self.factory)
cluster.authenticate(ClassicAuthenticator(buckets={bucket: password},cluster_password=self.cluster_info.admin_password, cluster_username=self.cluster_info.admin_username))
return cluster, bucket
示例4: _create_cluster_clean
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
def _create_cluster_clean(self, authenticator):
connargs = self.make_connargs()
connstr = ConnectionString.parse(str(connargs.pop('connection_string')))
connstr.clear_option('username')
bucket = connstr.bucket
connstr.bucket = None
password = connargs.get('password', None)
keys_to_skip = authenticator.get_credentials(bucket)['options'].keys()
for entry in keys_to_skip:
connstr.clear_option(entry)
cluster = Cluster(connstr, bucket_class=self.factory)
cluster.authenticate(ClassicAuthenticator(buckets={bucket: password}))
return cluster, bucket
示例5: _createConn
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
def _createConn(self):
try:
cluster = Cluster(self.connection_string, bucket_class=CouchbaseBucket)
cluster.authenticate(PasswordAuthenticator(self.bucket, 'password'))
self.cb = cluster.open_bucket(self.bucket)
except BucketNotFoundError:
raise
except AuthError:
# Try using default user created by the tests, if any, in case there is no user with bucket name in the
# cluster.
try:
cluster = Cluster(self.connection_string, bucket_class=CouchbaseBucket)
cluster.authenticate(PasswordAuthenticator("cbadminbucket", 'password'))
self.cb = cluster.open_bucket(self.bucket)
except AuthError:
raise
示例6: create_connections
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
def create_connections(self):
"""
Create bucket connections. 5 bucket connections are created per instance.
:return: Nothing
"""
for i in range(0, self.threads):
if self.cb_version > '5':
cluster = Cluster(self.spec)
auth = PasswordAuthenticator(self.user, self.password)
cluster.authenticate(auth)
bucket = cluster.open_bucket(self.bucket_name, lockmode=LOCKMODE_WAIT)
bucket.timeout = self.timeout
self.connections.append(bucket)
else:
bucket = Bucket('{0}/{1}'.format(self.spec, self.bucket_name), lockmode=LOCKMODE_WAIT)
bucket.timeout = self.timeout
self.connections.append(bucket)
示例7: _connect
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
def _connect(self):
"""Establish a connection to the Couchbase cluster."""
cluster = Cluster('http://{}:{}'.format(self.host, self.port))
authenticator = PasswordAuthenticator('Administrator', self.password)
cluster.authenticate(authenticator)
self.client = cluster.open_bucket(self.bucket)
示例8: tst
# 需要导入模块: from couchbase.cluster import Cluster [as 别名]
# 或者: from couchbase.cluster.Cluster import authenticate [as 别名]
#!/usr/bin/env python
from couchbase.cluster import Cluster, PasswordAuthenticator
from couchbase.exceptions import NotFoundError
def tst(cb, key):
try:
cb.remove(key)
except NotFoundError:
print ('Nothing to delete')
rv = cb.upsert(key, {'hello': 'world'})
cas = rv.cas
print(rv)
item = cb.get(key)
print(item)
cluster = Cluster('couchbase://localhost:12000')
cluster.authenticate(PasswordAuthenticator('Administrator', 'asdasd'))
cb = cluster.open_bucket('test')
tst(cb, 'blah')