Skip to content

Commit

Permalink
Support memcached and redis encrypted password.
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiamurialdo committed May 30, 2024
1 parent 7e691f1 commit f8d462e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Enyim.Caching;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached;
using GeneXus.Encryption;
using GeneXus.Services;
using GeneXus.Utils;

Expand All @@ -26,13 +27,21 @@ public Memcached()
MemcachedClient InitCache()
{
GXServices services = ServiceFactory.GetGXServices();
String address = string.Empty;
string address = string.Empty;
string password = string.Empty;
string username = string.Empty;
if (services != null)
{
GXService providerService = ServiceFactory.GetGXServices()?.Get(GXServices.CACHE_SERVICE);
if (providerService != null)
{
address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");
username = providerService.Properties.Get("CACHE_PROVIDER_USER");
password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD");
if (!string.IsNullOrEmpty(password))
{
password = CryptoImpl.Decrypt(password);
}
}
}

Expand All @@ -42,6 +51,12 @@ MemcachedClient InitCache()
#else
MemcachedClientConfiguration config = new MemcachedClientConfiguration();
#endif
if (!String.IsNullOrEmpty(username) || !String.IsNullOrEmpty(password))
{
config.Authentication.Type = typeof(PlainTextAuthenticator);
config.Authentication.Parameters["userName"] = username;
config.Authentication.Parameters["password"] = password;
}
if (!String.IsNullOrEmpty(address))
{
foreach (string host in address.Split(',', ';', ' ')) {
Expand Down
5 changes: 5 additions & 0 deletions dotnet/src/dotnetframework/Providers/Cache/GxRedis/GxRedis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using GeneXus.Encryption;
using GeneXus.Services;
using GeneXus.Utils;
using StackExchange.Redis;
Expand Down Expand Up @@ -38,6 +39,10 @@ public Redis()
string address, password;
address = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");
password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD");
if (!string.IsNullOrEmpty(password))
{
password = CryptoImpl.Decrypt(password);
}

if (string.IsNullOrEmpty(address))
address = String.Format("localhost:{0}", REDIS_DEFAULT_PORT);
Expand Down

0 comments on commit f8d462e

Please sign in to comment.