@@ -315,12 +315,37 @@ origin::to_json() const -> std::string
315315
316316} // namespace couchbase::core
317317
318+ couchbase::core::origin::origin (origin&& other) noexcept
319+ : options_(std::move(other.options_))
320+ , nodes_(std::move(other.nodes_))
321+ , next_node_(std::move(other.next_node_))
322+ , exhausted_(other.exhausted_)
323+ , connection_string_(std::move(other.connection_string_))
324+ {
325+ update_credentials (other.credentials ());
326+ }
327+
328+ auto
329+ couchbase::core::origin::operator =(origin&& other) -> origin&
330+ {
331+ if (this != &other) {
332+ options_ = std::move (other.options_ );
333+ nodes_ = std::move (other.nodes_ );
334+ next_node_ = std::move (other.next_node_ );
335+ exhausted_ = other.exhausted_ ;
336+ connection_string_ = std::move (other.connection_string_ );
337+ update_credentials (other.credentials ());
338+ }
339+ return *this ;
340+ }
341+
318342couchbase::core::origin::origin (const couchbase::core::origin& other)
319343 : options_(other.options_)
320- , credentials_(other.credentials_)
321344 , nodes_(other.nodes_)
322345 , next_node_(nodes_.begin())
323346{
347+ std::shared_lock lock (other.credentials_mutex_ );
348+ credentials_ = other.credentials_ ;
324349}
325350
326351couchbase::core::origin::origin (origin other, const topology::configuration& config)
@@ -334,25 +359,26 @@ couchbase::core::origin::origin(couchbase::core::cluster_credentials auth,
334359 std::uint16_t port,
335360 couchbase::core::cluster_options options)
336361 : options_(std::move(options))
337- , credentials_(std::move(auth))
338362 , nodes_{ { hostname, std::to_string (port) } }
339363 , next_node_(nodes_.begin())
340364{
365+ std::shared_lock lock (credentials_mutex_);
366+ credentials_ = std::move (auth);
341367}
342368couchbase::core::origin::origin (couchbase::core::cluster_credentials auth,
343369 const std::string& hostname,
344370 const std::string& port,
345371 couchbase::core::cluster_options options)
346372 : options_(std::move(options))
347- , credentials_(std::move(auth))
348373 , nodes_{ { hostname, port } }
349374 , next_node_(nodes_.begin())
350375{
376+ std::shared_lock lock (credentials_mutex_);
377+ credentials_ = std::move (auth);
351378}
352379couchbase::core::origin::origin (couchbase::core::cluster_credentials auth,
353380 const couchbase::core::utils::connection_string& connstr)
354381 : options_(connstr.options)
355- , credentials_(std::move(auth))
356382 , connection_string_(connstr.input)
357383{
358384 nodes_.reserve (connstr.bootstrap_nodes .size ());
@@ -365,13 +391,16 @@ couchbase::core::origin::origin(couchbase::core::cluster_credentials auth,
365391 shuffle_nodes ();
366392 }
367393 next_node_ = nodes_.begin ();
394+
395+ std::unique_lock lock (credentials_mutex_);
396+ credentials_ = std::move (auth);
368397}
369398auto
370399couchbase::core::origin::operator =(const couchbase::core::origin& other) -> couchbase::core::origin&
371400{
372401 if (this != &other) {
373402 options_ = other.options_ ;
374- credentials_ = other.credentials_ ;
403+ update_credentials ( other.credentials ()) ;
375404 nodes_ = other.nodes_ ;
376405 next_node_ = nodes_.begin ();
377406 exhausted_ = false ;
@@ -384,23 +413,27 @@ couchbase::core::origin::connection_string() const -> const std::string&
384413 return connection_string_;
385414}
386415auto
387- couchbase::core::origin::username () const -> const std::string&
416+ couchbase::core::origin::username () const -> std::string
388417{
418+ const std::shared_lock lock (credentials_mutex_);
389419 return credentials_.username ;
390420}
391421auto
392- couchbase::core::origin::password () const -> const std::string&
422+ couchbase::core::origin::password () const -> std::string
393423{
424+ const std::shared_lock lock (credentials_mutex_);
394425 return credentials_.password ;
395426}
396427auto
397- couchbase::core::origin::certificate_path () const -> const std::string&
428+ couchbase::core::origin::certificate_path () const -> std::string
398429{
430+ const std::shared_lock lock (credentials_mutex_);
399431 return credentials_.certificate_path ;
400432}
401433auto
402- couchbase::core::origin::key_path () const -> const std::string&
434+ couchbase::core::origin::key_path () const -> std::string
403435{
436+ const std::shared_lock lock (credentials_mutex_);
404437 return credentials_.key_path ;
405438}
406439auto
@@ -471,6 +504,7 @@ couchbase::core::origin::set_nodes_from_config(const topology::configuration& co
471504void
472505couchbase::core::origin::update_credentials (cluster_credentials auth)
473506{
507+ const std::unique_lock lock (credentials_mutex_);
474508 credentials_ = std::move (auth);
475509}
476510auto
@@ -508,7 +542,8 @@ couchbase::core::origin::options() -> couchbase::core::cluster_options&
508542 return options_;
509543}
510544auto
511- couchbase::core::origin::credentials () const -> const couchbase::core::cluster_credentials&
545+ couchbase::core::origin::credentials () const -> couchbase::core::cluster_credentials
512546{
547+ const std::shared_lock lock (credentials_mutex_);
513548 return credentials_;
514549}
0 commit comments