def _admin(self): self._check_for_shutdown() if not self.__admin: c = ConnectionString.parse(self.connstr) if not c.bucket: c.bucket = self._adminopts.pop('bucket', None) self.__admin = Admin(connection_string=str(c), **self._adminopts) return self.__admin
def make_admin_connection(self, is_mock): return Admin(self.admin_username, self.admin_password, self.host, self.port, ipv6=self.ipv6, **self.mock_hack_options(is_mock).kwargs)
def decode(cls, param): if isinstance(param, str): param = Admin._str_to_role(param) if isinstance(param, dict): args = list(map(param.get, ('role', 'bucket'))) else: args = param return cls.factory(*args)
def test_bucket_param(self): admin = Admin('Administrator', 'password', host=self.cluster_info.host, port=self.cluster_info.port, bucket='default') self.assertIsNotNone(admin)
def _authenticate(self, authenticator=None, # type: SDK2Authenticator username=None, # type: str password=None # type: str ): self._cluster.authenticate(authenticator, username, password) credentials = authenticator.get_credentials() self._clusteropts = credentials.get('options', {}) self._clusteropts['bucket'] = "default" self._clusterclient=None auth=credentials.get('options') self.admin = Admin(auth.get('username'), auth.get('password'), connstr=str(self.connstr))
def test_connection_string_param(self): # if using mock, we need a bucket in the connstr. Note the admin # constructor just adds a bucket (if given) when it constructs the # connection string. If you give it one, you need to put it in yourself. # But, only for the mock if self.is_mock: conn_str = 'http://{0}:{1}/{2}'.format(self.cluster_info.host, self.cluster_info.port, 'default') else: conn_str = 'http://{0}:{1}'.format(self.cluster_info.host, self.cluster_info.port) admin = Admin('Administrator', 'password', connection_string=conn_str) self.assertIsNotNone(admin)
from couchbase.cluster import Cluster from couchbase.cluster import ClusterOptions from couchbase.auth import PasswordAuthenticator from couchbase.management.admin import Admin from settings import BASE_DIR, get_config from db import register_user from model import CreateUser adm = Admin('Administrator', 'password', host='couchbase', port=8091) USER_CONFIG_PATH = BASE_DIR / 'config' / 'users.yaml' USER_CONFIG = get_config(['-c', '../config/users.yaml']) TEST_CONFIG_PATH = BASE_DIR / 'config' / 'users_test.yaml' TEST_CONFIG = get_config(['-c', TEST_CONFIG_PATH.as_posix()]) def setup_db(conf): adm.bucket_create(conf['bucket'], bucket_type='couchbase', ram_quota=100) adm.wait_ready(conf['bucket'], timeout=30) def teardown_db(conf): adm.bucket_remove(conf['bucket']) def get_bucket(conf): cluster = Cluster("{host}:{port}".format(host=conf['host'], port=conf['port']), options=ClusterOptions(
def __str__(self): return Admin.role_to_str(self)
def make_admin_connection(self): return Admin(self.admin_username, self.admin_password, self.host, self.port, ipv6=self.ipv6)
def test_connection_string_param(self): conn_str = 'http://{0}:{1}'.format(self.cluster_info.host, self.cluster_info.port) admin = Admin('Administrator', 'password', connection_string=conn_str) self.assertIsNotNone(admin)