Send the AUTH command with the specified master password if needed. * Note that for slaves the password set for the master is used. * * In case this Sentinel requires a password as well, via the "requirepass" * configuration directive, we assume we should use the local password in * order to authenticate when connecting with the other Sentinels as well. * So basically all the Sentinels share
| 2339 | * to the instance as if it fails Sentinel will detect the instance down, |
| 2340 | * will disconnect and reconnect the link and so forth. */ |
| 2341 | void sentinelSendAuthIfNeeded(sentinelRedisInstance *ri, redisAsyncContext *c) { |
| 2342 | char *auth_pass = NULL; |
| 2343 | char *auth_user = NULL; |
| 2344 | |
| 2345 | if (ri->flags & SRI_MASTER) { |
| 2346 | auth_pass = ri->auth_pass; |
| 2347 | auth_user = ri->auth_user; |
| 2348 | } else if (ri->flags & SRI_SLAVE) { |
| 2349 | auth_pass = ri->master->auth_pass; |
| 2350 | auth_user = ri->master->auth_user; |
| 2351 | } else if (ri->flags & SRI_SENTINEL) { |
| 2352 | /* If sentinel_auth_user is NULL, AUTH will use default user |
| 2353 | with sentinel_auth_pass to authenticate */ |
| 2354 | if (sentinel.sentinel_auth_pass) { |
| 2355 | auth_pass = sentinel.sentinel_auth_pass; |
| 2356 | auth_user = sentinel.sentinel_auth_user; |
| 2357 | } else { |
| 2358 | /* Compatibility with old configs. requirepass is used |
| 2359 | * for both incoming and outgoing authentication. */ |
| 2360 | auth_pass = server.requirepass; |
| 2361 | auth_user = NULL; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | if (auth_pass && auth_user == NULL) { |
| 2366 | if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, "%s %s", |
| 2367 | sentinelInstanceMapCommand(ri,"AUTH"), |
| 2368 | auth_pass) == C_OK) ri->link->pending_commands++; |
| 2369 | } else if (auth_pass && auth_user) { |
| 2370 | /* If we also have an username, use the ACL-style AUTH command |
| 2371 | * with two arguments, username and password. */ |
| 2372 | if (redisAsyncCommand(c, sentinelDiscardReplyCallback, ri, "%s %s %s", |
| 2373 | sentinelInstanceMapCommand(ri,"AUTH"), |
| 2374 | auth_user, auth_pass) == C_OK) ri->link->pending_commands++; |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | /* Use CLIENT SETNAME to name the connection in the Redis instance as |
| 2379 | * sentinel-<first_8_chars_of_runid>-<connection_type> |
no test coverage detected