perl-Couchbase-Client icon indicating copy to clipboard operation
perl-Couchbase-Client copied to clipboard

Help : how to pass credentials to the connection

Open LFranck opened this issue 6 years ago • 2 comments

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 avatar Mar 05 '18 16:03 LFranck

@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:

  1. create a new bucket from the gui
  2. create a user with the same name of the bucket
  3. 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

annibale-x avatar Apr 16 '18 21:04 annibale-x

@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

annibale-x avatar Jul 24 '18 19:07 annibale-x