def __init__(self, manager, persistence_type, ldap_mapping="default"): if persistence_type in ("ldap", "couchbase"): backend_type = persistence_type else: # persistence_type is hybrid if ldap_mapping == "default": backend_type = "ldap" else: backend_type = "couchbase" # resolve backend if backend_type == "ldap": host = os.environ.get("GLUU_LDAP_URL", "localhost:1636") user = manager.config.get("ldap_binddn") password = decode_text( manager.secret.get("encoded_ox_ldap_pw"), manager.secret.get("encoded_salt"), ) backend_cls = LDAPBackend else: host = os.environ.get("GLUU_COUCHBASE_URL", "localhost") user = get_couchbase_user(manager) password = get_couchbase_password(manager) backend_cls = CouchbaseBackend self.backend = backend_cls(host, user, password) self.manager = manager
def __init__(self, manager): hostname = os.environ.get("GLUU_COUCHBASE_URL", "localhost") user = get_couchbase_superuser(manager) or get_couchbase_user(manager) password = "" with contextlib.suppress(FileNotFoundError): password = get_couchbase_superuser_password(manager) password = password or get_couchbase_password(manager) self.client = CouchbaseClient(hostname, user, password) self.manager = manager
def wait_for_couchbase_conn(manager, **kwargs): """Wait for readiness/availability of Couchbase server based on connection status. :param manager: An instance of :class:`~pygluu.containerlib.manager._Manager`. """ host = os.environ.get("GLUU_COUCHBASE_URL", "localhost") user = get_couchbase_user(manager) password = get_couchbase_password(manager) cb_client = CouchbaseClient(host, user, password) req = cb_client.get_buckets() if not req.ok: raise WaitError(f"Unable to connect to host in {host} list")
def wait_for_couchbase(manager, **kwargs): """Wait for readiness/availability of Couchbase server based on existing entry. :param manager: An instance of :class:`~pygluu.containerlib.manager._Manager`. """ host = os.environ.get("GLUU_COUCHBASE_URL", "localhost") user = get_couchbase_user(manager) password = get_couchbase_password(manager) persistence_type = os.environ.get("GLUU_PERSISTENCE_TYPE", "couchbase") ldap_mapping = os.environ.get("GLUU_PERSISTENCE_LDAP_MAPPING", "default") bucket_prefix = os.environ.get("GLUU_COUCHBASE_BUCKET_PREFIX", "gluu") # only _base_ and _user_ buckets that may have initial data; # these data also affected by LDAP mapping selection; # by default we will choose the _base_ bucket bucket, key = bucket_prefix, "configuration_oxtrust" # if `hybrid` is selected and default mapping is stored in LDAP, # the _base_ bucket won't have data, hence we check the _user_ bucket if persistence_type == "hybrid" and ldap_mapping == "default": bucket, key = f"{bucket_prefix}_user", "groups_60B7" cb_client = CouchbaseClient(host, user, password) req = cb_client.exec_query( f"SELECT objectClass FROM {bucket} USE KEYS $key", key=key, ) if not req.ok: try: data = json.loads(req.text) err = data["errors"][0]["msg"] except (ValueError, KeyError, IndexError): err = req.reason raise WaitError(err) # request is OK, but result is not found data = req.json() if not data["results"]: raise WaitError(f"Missing document {key} in bucket {bucket}")
def __init__(self, manager, persistence_type, ldap_mapping="default", rotation_interval=48): if persistence_type in ("ldap", "couchbase"): backend_type = persistence_type else: # persistence_type is hybrid if ldap_mapping == "default": backend_type = "ldap" else: backend_type = "couchbase" # resolve backend if backend_type == "ldap": host = os.environ.get("GLUU_LDAP_URL", "localhost:1636") user = manager.config.get("ldap_binddn") password = decode_text( manager.secret.get("encoded_ox_ldap_pw"), manager.secret.get("encoded_salt"), ) backend_cls = LDAPBackend else: host = os.environ.get("GLUU_COUCHBASE_URL", "localhost") user = get_couchbase_user(manager) password = get_couchbase_password(manager) backend_cls = CouchbaseBackend self.backend = backend_cls(host, user, password) self.manager = manager self.rotation_interval = rotation_interval metadata = os.environ.get("GLUU_CONTAINER_METADATA", "docker") if metadata == "kubernetes": self.meta_client = KubernetesClient() else: self.meta_client = DockerClient()
def test_get_couchbase_user(gmanager): from pygluu.containerlib.persistence.couchbase import get_couchbase_user os.environ["GLUU_COUCHBASE_USER"] = "******" assert get_couchbase_user(gmanager) == "root" os.environ.pop("GLUU_COUCHBASE_USER", None)
def __init__(self, manager): hosts = os.environ.get("GLUU_COUCHBASE_URL", "localhost") user = get_couchbase_user(manager) password = get_couchbase_password(manager) self.client = CouchbaseClient(hosts, user, password)
def __init__(self, manager): hostname = GLUU_COUCHBASE_URL user = get_couchbase_user(manager) password = get_couchbase_password(manager) self.client = CouchbaseClient(hostname, user, password) self.manager = manager