@@ -727,6 +727,80 @@ connection_handle::bucket_close(const zend_string* name) -> core_error_info
727727 return impl_->bucket_close (cb_string_new (name));
728728}
729729
730+ COUCHBASE_API
731+ auto
732+ connection_handle::authenticator_set (const zval* auth) -> core_error_info
733+ {
734+ if (auth == nullptr || Z_TYPE_P (auth) != IS_ARRAY) {
735+ return { errc::common::invalid_argument, ERROR_LOCATION, " expected array for authenticator" };
736+ }
737+
738+ const zval* auth_type = zend_symtable_str_find (Z_ARRVAL_P (auth), ZEND_STRL (" type" ));
739+ if (auth_type == nullptr || Z_TYPE_P (auth_type) != IS_STRING) {
740+ return { errc::common::invalid_argument,
741+ ERROR_LOCATION,
742+ " unexpected type of the authenticator" };
743+ }
744+ if (zend_binary_strcmp (Z_STRVAL_P (auth_type), Z_STRLEN_P (auth_type), ZEND_STRL (" password" )) ==
745+ 0 ) {
746+ const zval* username = zend_symtable_str_find (Z_ARRVAL_P (auth), ZEND_STRL (" username" ));
747+ if (username == nullptr || Z_TYPE_P (username) != IS_STRING) {
748+ return { errc::common::invalid_argument,
749+ ERROR_LOCATION,
750+ " expected username to be a string in the authenticator" };
751+ }
752+ const zval* password = zend_symtable_str_find (Z_ARRVAL_P (auth), ZEND_STRL (" password" ));
753+ if (password == nullptr || Z_TYPE_P (password) != IS_STRING) {
754+ return { errc::common::invalid_argument,
755+ ERROR_LOCATION,
756+ " expected password to be a string in the authenticator" };
757+ }
758+ couchbase::password_authenticator password_auth{
759+ Z_STRVAL_P (username),
760+ Z_STRVAL_P (password),
761+ };
762+
763+ auto ctx = impl_->public_api ().set_authenticator (password_auth);
764+
765+ if (ctx.ec ()) {
766+ return { ctx.ec (), ERROR_LOCATION, " unable to set authenticator" , build_error_context (ctx) };
767+ }
768+ return {};
769+ }
770+
771+ if (zend_binary_strcmp (Z_STRVAL_P (auth_type), Z_STRLEN_P (auth_type), ZEND_STRL (" certificate" )) ==
772+ 0 ) {
773+ const zval* certificate_path =
774+ zend_symtable_str_find (Z_ARRVAL_P (auth), ZEND_STRL (" certificatePath" ));
775+ if (certificate_path == nullptr || Z_TYPE_P (certificate_path) != IS_STRING) {
776+ return { errc::common::invalid_argument,
777+ ERROR_LOCATION,
778+ " expected certificate path to be a string in the authenticator" };
779+ }
780+ const zval* key_path = zend_symtable_str_find (Z_ARRVAL_P (auth), ZEND_STRL (" keyPath" ));
781+ if (key_path == nullptr || Z_TYPE_P (key_path) != IS_STRING) {
782+ return { errc::common::invalid_argument,
783+ ERROR_LOCATION,
784+ " expected key path to be a string in the authenticator" };
785+ }
786+
787+ couchbase::certificate_authenticator certificate_auth{
788+ Z_STRVAL_P (certificate_path),
789+ Z_STRVAL_P (key_path),
790+ };
791+
792+ auto ctx = impl_->public_api ().set_authenticator (certificate_auth);
793+ if (ctx.ec ()) {
794+ return { ctx.ec (), ERROR_LOCATION, " unable to set authenticator" , build_error_context (ctx) };
795+ }
796+ return {};
797+ }
798+ return { errc::common::invalid_argument,
799+ ERROR_LOCATION,
800+ fmt::format (" unknown type of the authenticator: {}" ,
801+ std::string (Z_STRVAL_P (auth_type), Z_STRLEN_P (auth_type))) };
802+ }
803+
730804namespace
731805{
732806template <typename Request>
0 commit comments