Skip to content

Commit 4f63010

Browse files
committed
CCBC-1618: update query error codes for dynamic authenticator
Change-Id: I84f22435403c7dce187e31e83372d299a949667e Reviewed-on: https://review.couchbase.org/c/libcouchbase/+/202863 Reviewed-by: <ankit.prabhu@couchbase.com> Reviewed-by: Rishit Chaudhary <rishit.chaudhary@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent caf79f8 commit 4f63010

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

include/libcouchbase/auth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ LIBCOUCHBASE_API lcbauth_SERVICE lcbauth_credentials_service(const lcbauth_CREDE
315315
typedef enum {
316316
LCBAUTH_REASON_NEW_OPERATION = 0,
317317
LCBAUTH_REASON_AUTHENTICATION_FAILURE,
318+
LCBAUTH_REASON_AUTHORIZATION_FAILURE,
318319
} lcbauth_REASON;
319320

320321
/**

src/n1ql/query_handle.cc

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,31 @@ lcb_RETRY_ACTION lcb_QUERY_HANDLE_::has_retriable_error(lcb_STATUS &rc)
386386
lcb_strerror_short(rc), first_error.code, first_error.message.c_str());
387387
return {1, default_backoff};
388388
}
389-
if (first_error.code == 13014 &&
390-
LCBT_SETTING(instance_, auth)->mode() == LCBAUTH_MODE_DYNAMIC) { // datastore.couchbase.insufficient_credentials
391-
auto result = request_credentials(LCBAUTH_REASON_AUTHENTICATION_FAILURE);
392-
bool credentials_found = result == LCBAUTH_RESULT_OK;
393-
lcb_log(LOGARGS(this, TRACE),
394-
LOGFMT "Invalidate credentials and retry request. creds: %s, rc: %s, code: %d, msg: %s", LOGID(this),
395-
credentials_found ? "ok" : "not_found", lcb_strerror_short(rc), first_error.code,
396-
first_error.message.c_str());
397-
return {credentials_found, default_backoff};
389+
if (LCBT_SETTING(instance_, auth)->mode() == LCBAUTH_MODE_DYNAMIC) {
390+
lcbauth_REASON reason_to_refresh_credentials{};
391+
switch (first_error.code) {
392+
case 13014: /* E_DATASTORE_INSUFFICIENT_CREDENTIALS */
393+
case 12037: /* E_ACCESS_DENIED */
394+
reason_to_refresh_credentials = LCBAUTH_REASON_AUTHORIZATION_FAILURE;
395+
break;
396+
397+
case 2120: /* E_ADMIN_AUTH */
398+
reason_to_refresh_credentials = LCBAUTH_REASON_AUTHENTICATION_FAILURE;
399+
break;
400+
401+
default:
402+
break;
403+
}
404+
405+
if (reason_to_refresh_credentials) {
406+
auto result = request_credentials(reason_to_refresh_credentials);
407+
bool credentials_found = result == LCBAUTH_RESULT_OK;
408+
lcb_log(LOGARGS(this, TRACE),
409+
LOGFMT "Invalidate credentials and retry request. creds: %s, rc: %s, code: %d, msg: %s",
410+
LOGID(this), credentials_found ? "ok" : "not_found", lcb_strerror_short(rc), first_error.code,
411+
first_error.message.c_str());
412+
return {credentials_found, default_backoff};
413+
}
398414
}
399415
if (!first_error.message.empty()) {
400416
for (const auto &magic_string : wtf_magic_strings) {

0 commit comments

Comments
 (0)