Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SSL and AUTH for redis #717

Merged
merged 32 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0866946
Added JedisUtils
munishchouhan Oct 24, 2024
c2219c3
Added license [ci skip]
munishchouhan Oct 24, 2024
9c56729
[release] bump 1.13.6-A0
munishchouhan Oct 24, 2024
3a8ab3d
removed JedisUtils
munishchouhan Oct 24, 2024
c781431
set correct timeout
munishchouhan Oct 24, 2024
9f2e6a1
added tests
munishchouhan Oct 24, 2024
452c391
refactored
munishchouhan Oct 24, 2024
3047795
removed unused code
munishchouhan Oct 24, 2024
e0dd0e1
refactored tests
munishchouhan Oct 24, 2024
f76a20d
added password in config
munishchouhan Oct 24, 2024
ad6cf86
formatted [ci skip]
munishchouhan Oct 24, 2024
ef72b19
[release] bump 1.13.6-A1
munishchouhan Oct 24, 2024
2610888
[release] bump 1.13.6-A1
munishchouhan Oct 24, 2024
f8c040c
injected Jedispool to SpillWayStorageFactory
munishchouhan Oct 24, 2024
31b889c
[release] bump 1.13.6-A2
munishchouhan Oct 24, 2024
034a7bb
reverted VERSION
munishchouhan Oct 24, 2024
e6a5f2c
Merge branch 'master' into 713-enhancement-redis-support-encryption-i…
munishchouhan Oct 28, 2024
ed3a588
Merge branch 'master' into 713-enhancement-redis-support-encryption-i…
munishchouhan Oct 28, 2024
684c556
Merge branch 'master' into 713-enhancement-redis-support-encryption-i…
munishchouhan Nov 4, 2024
d961bc9
Merge branch 'master' into 713-enhancement-redis-support-encryption-i…
munishchouhan Nov 6, 2024
71c7107
Merge branch 'master' into 713-enhancement-redis-support-encryption-i…
munishchouhan Nov 18, 2024
e69f4f4
Merge branch 'master' into 713-enhancement-redis-support-encryption-i…
pditommaso Nov 21, 2024
3f3ba4e
Minor change
pditommaso Nov 21, 2024
40d8b43
fixed tests
munishchouhan Nov 22, 2024
ec8fd68
[release] bump 1.15.2-A0
munishchouhan Nov 22, 2024
24946fe
VERSION reverted
munishchouhan Nov 22, 2024
624a87d
Merge branch 'master' into 713-enhancement-redis-support-encryption-i…
munishchouhan Nov 22, 2024
2dd4221
Update src/main/groovy/io/seqera/wave/redis/RedisFactory.groovy [ci s…
pditommaso Nov 22, 2024
73fb84a
removed redisConfig
munishchouhan Nov 22, 2024
0db73a9
added config doc
munishchouhan Nov 22, 2024
30b81dd
updated config doc
munishchouhan Nov 22, 2024
5715dfc
updated config doc
munishchouhan Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import groovy.util.logging.Slf4j
import io.micronaut.context.annotation.Factory
import io.micronaut.context.annotation.Requires
import io.seqera.wave.configuration.RedisConfig
import jakarta.inject.Inject
import jakarta.inject.Singleton
import jakarta.validation.constraints.NotNull
import redis.clients.jedis.JedisPool
Expand All @@ -51,9 +52,8 @@ class SpillWayStorageFactory {

@Singleton
@Requires(property = 'redis.uri')
LimitUsageStorage redisStorage(@NotNull RedisConfig redisConfig){
LimitUsageStorage redisStorage(@NotNull RedisConfig redisConfig, JedisPool pool){
pditommaso marked this conversation as resolved.
Show resolved Hide resolved
log.info "Using redis $redisConfig.uri as storage for rate limit"
def jedisPool = new JedisPool(redisConfig.uri)
return RedisStorage.builder().withJedisPool(jedisPool).build()
return RedisStorage.builder().withJedisPool(pool).build()
}
}
38 changes: 34 additions & 4 deletions src/main/groovy/io/seqera/wave/redis/RedisFactory.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@

package io.seqera.wave.redis


pditommaso marked this conversation as resolved.
Show resolved Hide resolved
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.micronaut.context.annotation.Factory
import io.micronaut.context.annotation.Requires
import io.micronaut.context.annotation.Value
import io.micronaut.core.annotation.Nullable
import jakarta.inject.Singleton
import redis.clients.jedis.DefaultJedisClientConfig
import redis.clients.jedis.JedisClientConfig
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.exceptions.InvalidURIException
import redis.clients.jedis.util.JedisURIHelper
/**
* Redis connection pool factory
*
Expand All @@ -39,17 +45,41 @@ class RedisFactory {

@Singleton
JedisPool createRedisPool(
@Value('${redis.uri}') String uri,
@Value('${redis.uri}') String connection,
@Value('${redis.pool.minIdle:0}') int minIdle,
@Value('${redis.pool.maxIdle:10}') int maxIdle,
@Value('${redis.pool.maxTotal:50}') int maxTotal
@Value('${redis.pool.maxTotal:50}') int maxTotal,
@Value('${redis.client.timeout:5000}') int timeout,
@Nullable @Value('${redis.password}') String password
) {
log.info "Using redis $uri as storage for rate limit - pool minIdle: ${minIdle}; maxIdle: ${maxIdle}; maxTotal: ${maxTotal}"
log.info "Using redis ${connection} as storage for rate limit - pool minIdle: ${minIdle}; maxIdle: ${maxIdle}; maxTotal: ${maxTotal}; timeout: ${timeout}"

final uri = URI.create(connection)
// pool config
final config = new JedisPoolConfig()
config.setMinIdle(minIdle)
config.setMaxIdle(maxIdle)
config.setMaxTotal(maxTotal)
return new JedisPool(config, URI.create(uri))
// client config
final clientConfig = clientConfig(uri, password, timeout)
// create the jedis pool
return new JedisPool(config, JedisURIHelper.getHostAndPort(uri), clientConfig)
}

protected JedisClientConfig clientConfig(URI uri, String password, int timeout) {
if (!JedisURIHelper.isValid(uri)) {
throw new InvalidURIException("Invalid Redis connection URI: ${uri}")
}

return DefaultJedisClientConfig.builder().connectionTimeoutMillis(timeout)
.socketTimeoutMillis(timeout)
.blockingSocketTimeoutMillis(timeout)
.user(JedisURIHelper.getUser(uri))
.password(password?:JedisURIHelper.getPassword(uri))
.database(JedisURIHelper.getDBIndex(uri))
.protocol(JedisURIHelper.getRedisProtocol(uri))
.ssl(JedisURIHelper.isRedisSSLScheme(uri))
.build()
}

}
62 changes: 62 additions & 0 deletions src/test/groovy/io/seqera/wave/redis/RedisFactoryTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Wave, containers provisioning service
* Copyright (c) 2023-2024, Seqera Labs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.seqera.wave.redis

import spock.lang.Specification

import redis.clients.jedis.exceptions.InvalidURIException
/**
*
* @author Munish Chouhan <[email protected]>
*/
class RedisFactoryTest extends Specification {
def 'should create redis pool with valid URI'() {
given:
def factory = new RedisFactory()

when:
def pool = factory.createRedisPool(URI_STRING, MIN_IDLE, MAX_IDLE, MAX_TOTAL, TIMEOUT, 'password')

then:
pool != null

where:
URI_STRING | MIN_IDLE | MAX_IDLE | MAX_TOTAL | TIMEOUT
'redis://localhost:6379' | 0 | 10 | 50 | 5000
'rediss://localhost:6379'| 1 | 5 | 20 | 3000
}

def 'should throw exception for invalid URI'() {
given:
def factory = new RedisFactory()

when:
factory.createRedisPool(URI_STRING, MIN_IDLE, MAX_IDLE, MAX_TOTAL, TIMEOUT, null)

then:
def e = thrown(InvalidURIException)
e.message.contains("Invalid Redis connection URI: $URI_STRING")

where:
URI_STRING | MIN_IDLE | MAX_IDLE | MAX_TOTAL | TIMEOUT
'redis://localhost' | 0 | 10 | 50 | 5000
'localhost:6379' | 1 | 5 | 20 | 3000
}

}