def test_get_couchbase_password_from_file(monkeypatch, tmpdir, gmanager):
    from jans.pycloudlib.persistence.couchbase import get_couchbase_password

    passwd_file = tmpdir.join("couchbase_password")
    passwd_file.write("secret")
    monkeypatch.setenv("CN_COUCHBASE_PASSWORD_FILE", str(passwd_file))
    assert get_couchbase_password(gmanager) == "secret"
    def __init__(self, manager):
        hostname = os.environ.get("CN_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
        self.index_num_replica = 0
Ejemplo n.º 3
0
def wait_for_couchbase_conn(manager, **kwargs):
    """Wait for readiness/availability of Couchbase server based on connection status.

    :param manager: An instance of :class:`~jans.pycloudlib.manager._Manager`.
    """
    host = os.environ.get("CN_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")
Ejemplo n.º 4
0
def wait_for_couchbase(manager, **kwargs):
    """Wait for readiness/availability of Couchbase server based on existing entry.

    :param manager: An instance of :class:`~jans.pycloudlib.manager._Manager`.
    """
    host = os.environ.get("CN_COUCHBASE_URL", "localhost")
    user = get_couchbase_user(manager)
    password = get_couchbase_password(manager)

    persistence_type = os.environ.get("CN_PERSISTENCE_TYPE", "couchbase")
    ldap_mapping = os.environ.get("CN_PERSISTENCE_LDAP_MAPPING", "default")
    bucket_prefix = os.environ.get("CN_COUCHBASE_BUCKET_PREFIX", "jans")

    # only default and user buckets buckets that may have initial data;
    # these data also affected by LDAP mapping selection;
    jca_client_id = manager.config.get("jca_client_id")
    bucket, key = bucket_prefix, f"clients_{jca_client_id}"

    # if `hybrid` is selected and default mapping is stored in LDAP,
    # the default bucket won't have data, hence we check the user bucket instead
    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 test_get_couchbase_password_from_secrets(gmanager):
    from jans.pycloudlib.persistence.couchbase import get_couchbase_password
    assert get_couchbase_password(gmanager) == "secret"
 def __init__(self, manager):
     host = os.environ.get("CN_COUCHBASE_URL", "localhost")
     user = get_couchbase_user(manager)
     password = get_couchbase_password(manager)
     self.client = CouchbaseClient(host, user, password)