Skip to content

Commit

Permalink
added OSS_GLOBAL_PASSWORD config argument (#202) (#203)
Browse files Browse the repository at this point in the history
* added OSS_GLOBAL_PASSWORD config argument

* updated readme

* Tests will also run on env with password
  • Loading branch information
MeirShpilraien authored Nov 9, 2020
1 parent a8257d3 commit 9a450b4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ cd $BUILD_DIR
ctest -V

test_args="--env oss-cluster --env-reuse -t $ROOT/src/dep/RediSearch/tests/pytests/ --clear-logs --shards-count 3 --module $ROOT/$MODULE_OSS_SO"
python -m RLTest $test_args --module-args "PARTITIONS AUTO"
python -m RLTest $test_args --module-args "PARTITIONS AUTO SAFEMODE"
python2.7 -m RLTest $test_args --module-args "PARTITIONS AUTO"
python2.7 -m RLTest $test_args --oss_password password --module-args "OSS_GLOBAL_PASSWORD password PARTITIONS AUTO"
python2.7 -m RLTest $test_args --module-args "PARTITIONS AUTO SAFEMODE"
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ loadmodule /path/to/oss-module.so
```

The module automatically discovers the Redis cluster topology and distributes the search commands accordingly.
Notice that it is possible to give a global password that will be used to connect to other shards using OSS_GLOBAL_PASSWORD module argument, i.e:

```
loadmodule /path/to/oss-module.so OSS_GLOBAL_PASSWORD <password>
```

# Commands

Expand Down
19 changes: 19 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ CONFIG_GETTER(getTimeout) {
return sdscatprintf(ss, "%d", realConfig->timeoutMS);
}

CONFIG_SETTER(setGlobalPass) {
SearchClusterConfig *realConfig = getOrCreateRealConfig(config);
int acrc = AC_GetString(ac, &realConfig->globalPass, NULL, 0);
if (acrc != AC_OK) {
QueryError_SetError(status, QUERY_EPARSEARGS, NULL);
return REDISMODULE_ERR;
}
return REDISMODULE_OK;
}

CONFIG_GETTER(getGlobalPass) {
sds ss = sdsempty();
return sdscatprintf(ss, "Password: *******");
}

static RSConfigOptions clusterOptions_g = {
.vars =
{
Expand All @@ -86,6 +101,10 @@ static RSConfigOptions clusterOptions_g = {
.helpText = "Cluster synchronization timeout",
.setValue = setTimeout,
.getValue = getTimeout},
{.name = "OSS_GLOBAL_PASSWORD",
.helpText = "Global oss cluster password that will be used to connect to other shards",
.setValue = setGlobalPass,
.getValue = getGlobalPass},
{.name = NULL}
// fin
}
Expand Down
7 changes: 4 additions & 3 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ typedef struct {
size_t numPartitions;
MRClusterType type;
int timeoutMS;
const char* globalPass;
} SearchClusterConfig;

extern SearchClusterConfig clusterConfig;

#define CLUSTER_TYPE_OSS "redis_oss"
#define CLUSTER_TYPE_RLABS "redislabs"

#define DEFAULT_CLUSTER_CONFIG \
(SearchClusterConfig) { \
.numPartitions = 0, .type = DetectClusterType(), .timeoutMS = 500, \
#define DEFAULT_CLUSTER_CONFIG \
(SearchClusterConfig) { \
.numPartitions = 0, .type = DetectClusterType(), .timeoutMS = 500, .globalPass = NULL, \
}

/* Detect the cluster type, by trying to see if we are running inside RLEC.
Expand Down
3 changes: 2 additions & 1 deletion src/dep/rmr/redis_cluster.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "../../config.h"
#include "cluster.h"
#include "conn.h"
#include <uv.h>
Expand Down Expand Up @@ -82,7 +83,7 @@ MRClusterTopology *RedisCluster_GetTopology(RedisModuleCtx *ctx) {
MRClusterNode node = {
.endpoint =
(MREndpoint){
.host = strndup(host, hostlen), .port = port, .auth = NULL, .unixSock = NULL},
.host = strndup(host, hostlen), .port = port, .auth = (clusterConfig.globalPass ? strdup(clusterConfig.globalPass) : NULL) , .unixSock = NULL},
.id = strndup(id, idlen),
.flags = MRNode_Coordinator,
};
Expand Down

0 comments on commit 9a450b4

Please sign in to comment.