perl-Couchbase-Client
perl-Couchbase-Client copied to clipboard
Help : how to pass credentials to the connection
Hi,
On my couchbase plateform, the connection credentials is on the cluster not on the bucket. So how to use this where the password is for bucket :
# Create a new connection
my $cb = Couchbase::Bucket->new("couchbases://anynode/bucket", { password => "secret" });
In the previous version, Couchbase::Client, we used to have :
my $client = Couchbase::Client->new({
server => 'localhost:8091',
username => 'some_user',
password => 'secret',
bucket => 'my_bucket'
});
Can you give me the equivalent?
Thanks LF
@LFranck I took a look to this (unofficial) sdk, and the RBAC logic of libcouchbase seems not yet implemented here.
A trick you can do is to:
- create a new bucket from the gui
- create a user with the same name of the bucket
- grant the user to read/write the bucket
Now you can access using the password of the user with the same name of the bucket:
my $cb = Couchbase::Bucket->new("couchbase://server/bucket", { password => "pwd" });
ps: when connected, you can access data in any allowed bucket using N1QL queries. eg:
my $res = $cb->query_slurp(qq{ SELECT * FROM `another_bucket` })->rows ;
Cheers AM
@LFranck I published a pull request with the patch for passing the username
option to the constructor.
Please refer to the pull request https://github.com/mnunberg/perl-Couchbase-Client/pull/49 or clone/download the patched release from the repo https://github.com/annibale-x/perl-Couchbase-Client
Usage example:
use Couchbase::Bucket ;
my $bucket = Couchbase::Bucket->new(
"couchbase://127.0.0.1/bucket-name",
{
username => "myUserName" , # <== new option
password => 'myPassword'
}
) ;
Hope this helps.
Cheers AM