diff --git a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java index 796e17b..7a431c9 100755 --- a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java +++ b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Graylog, Inc. + * Copyright (C) 2024 johan@nosd.in * * This program is free software: you can redistribute it and/or modify * it under the terms of the Server Side Public License, version 1, @@ -36,15 +36,6 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; -/* -//To delete after clean -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; -//END To delete after clean -*/ import in.nosd.redis.dataadapters.AutoValue_RedisLookupDataAdapter_Config; import org.graylog2.plugin.lookup.LookupCachePurge; import org.graylog2.plugin.lookup.LookupDataAdapter; @@ -89,18 +80,19 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { super(dto, metricRegistry); this.config = (Config) dto.config(); - RedisURI redisUri = RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort()) - .withPort(this.config.redisPort()) - //.withAuthentication(this.config.redisUsername(), this.config.redisPassword()) - .withDatabase(this.config.redisDB()) - .build(); + RedisURI redisUri ; + redisUri = RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort()) + .withPort(this.config.redisPort()) + .withDatabase(this.config.redisDB()) + .build(); + if (this.config.redisPassword() != null && this.config.redisPassword().length() > 0) { + redisUri.setPassword(this.config.redisPassword()); + } + if (this.config.redisUsername() != null && this.config.redisUsername().length() > 0) { + redisUri.setUsername(this.config.redisUsername()); + } this.client = RedisClient.create(redisUri); - /*this.client = RedisClient.create(RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort()) - .withPort(this.config.redisPort()) - .withAuthentication(this.config.redisUsername(), this.config.redisPassword()) - .withDatabase(this.config.redisDB()) - .build()); - */ + this.redisGetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisGetRequestTime")); this.redisGetRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisGetRequestErrors")); this.redisSetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisSetRequestTime")); @@ -202,8 +194,8 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { .redisHost("127.0.0.1") .redisPort(6379) .redisDB(0) - /*.redisUsername("") - .redisPassword("")*/ + .redisUsername("") + .redisPassword("") .build(); } @@ -233,13 +225,13 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { @Min(0) public abstract int redisDB(); - /*@JsonProperty("redis_username") + @JsonProperty("redis_username") @Nullable public abstract String redisUsername(); @JsonProperty("redis_password") @Nullable - public abstract String redisPassword();*/ + public abstract String redisPassword(); public static Builder builder() { return new AutoValue_RedisLookupDataAdapter_Config.Builder(); @@ -278,11 +270,11 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { @JsonProperty("redis_database") public abstract Builder redisDB(int redisDB); - /*@JsonProperty("redis_username") + @JsonProperty("redis_username") public abstract Builder redisUsername(String redisUsername); @JsonProperty("redis_password") - public abstract Builder redisPassword(String redisPassword);*/ + public abstract Builder redisPassword(String redisPassword); public abstract Config build(); } diff --git a/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx b/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx index 07a1fc6..67b93f5 100644 --- a/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx +++ b/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Graylog, Inc. + * Copyright (C) 2024 johan@nosd.in * * This program is free software: you can redistribute it and/or modify * it under the terms of the Server Side Public License, version 1, @@ -44,38 +44,58 @@ class RedisLookupAdapterFieldSet extends React.Component { return (
); }