Skip to content

Commit

Permalink
Adding useSSL option (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
benicalidon authored and ctoestreich committed May 14, 2018
1 parent 12a646a commit 512341f
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 195 deletions.
202 changes: 101 additions & 101 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
}
}

plugins {
id "io.spring.dependency-management" version "0.4.0.RELEASE"
id "com.jfrog.bintray" version "1.1"
}

apply plugin: 'maven-publish'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "spring-boot"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"

apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/grailsCentralPublishing.gradle'

ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}

version "2.0.5"
group "org.grails.plugins"
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://repo.spring.io/milestone/" }
maven { url "http://oss.sonatype.org/content/repositories/snapshots" }
}

dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}

dependencies {

provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"

provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'

testCompile "org.grails:grails-plugin-testing"

console "org.grails:grails-console"

compile 'redis.clients:jedis:2.9.0'
compile 'com.google.code.gson:gson:2.6.1'
}

task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}

jar {
exclude "application.groovy"
exclude "src/test/projects/**"
}

bintray {
user = System.getenv("BINTRAY_USER") ?: project.hasProperty("bintrayUser") ? project.bintrayUser : ''
key = System.getenv("BINTRAY_KEY") ?: project.hasProperty("bintrayKey") ? project.bintrayKey : ''
publications = ['maven']
pkg {
repo = 'grails-plugins'
userOrg = 'ctoestreich'
name = "redis"
desc = "Grails Redis plugin"
websiteUrl = "http://grails.org/plugin/redis"
issueTrackerUrl = "https://github.com/grails-plugins/grails-redis/issues"
vcsUrl = "https://github.com/grails-plugins/grails-redis"
licenses = ['Apache-2.0']
publicDownloadNumbers = true
}
}


bintrayUpload.dependsOn sourcesJar, javadocJar

buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
}
}

plugins {
id "io.spring.dependency-management" version "0.6.1.RELEASE"
id "com.jfrog.bintray" version "1.1"
}

apply plugin: 'maven-publish'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "spring-boot"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"

apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/grailsCentralPublishing.gradle'

ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}

version "2.0.5"
group "org.grails.plugins"
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://repo.spring.io/milestone/" }
maven { url "http://oss.sonatype.org/content/repositories/snapshots" }
}

dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}

dependencies {

provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"

provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'

testCompile "org.grails:grails-plugin-testing"

console "org.grails:grails-console"

compile 'redis.clients:jedis:2.9.0'
compile 'com.google.code.gson:gson:2.6.1'
}

task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}

jar {
exclude "application.groovy"
exclude "src/test/projects/**"
}

bintray {
user = System.getenv("BINTRAY_USER") ?: project.hasProperty("bintrayUser") ? project.bintrayUser : ''
key = System.getenv("BINTRAY_KEY") ?: project.hasProperty("bintrayKey") ? project.bintrayKey : ''
publications = ['maven']
pkg {
repo = 'grails-plugins'
userOrg = 'ctoestreich'
name = "redis"
desc = "Grails Redis plugin"
websiteUrl = "http://grails.org/plugin/redis"
issueTrackerUrl = "https://github.com/grails-plugins/grails-redis/issues"
vcsUrl = "https://github.com/grails-plugins/grails-redis"
licenses = ['Apache-2.0']
publicDownloadNumbers = true
}
}


bintrayUpload.dependsOn sourcesJar, javadocJar

Original file line number Diff line number Diff line change
@@ -1,94 +1,95 @@
package grails.plugins.redis.util

import groovy.util.logging.Commons
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.JedisSentinelPool
import redis.clients.jedis.Protocol

/**
* This class provides a closure that can (and must) be used within the context of a BeanBuilder.
* To wire all redisServices using a custom class do the following
*
* def configureService = RedisConfigurationUtil.configureService
* def redisConfigMap = application.config.grails.redis ?: [:]
*
* configureService.delegate = delegate
* configureService(redisConfigMap, "", MyRedisService)
* redisConfigMap?.connections?.each { connection ->
* configureService(connection.value, connection?.key?.capitalize(), MyRedisService)
*}*
*/
@Commons
class RedisConfigurationUtil {

/**
* delegate to wire up the required beans.
*/
static def configureService = { delegate, redisConfigMap, key, serviceClass ->

def poolBean = "redisPoolConfig${key}"
def validPoolProperties = findValidPoolProperties(redisConfigMap.poolConfig)

//todo: fix the validPoolProperty eval or just add them inline
delegate."${poolBean}"(JedisPoolConfig) {
validPoolProperties.each { configKey, value ->
delegate.setProperty(configKey, value)
}
}
// delegate."${poolBean}"(JedisPoolConfig) { bean ->
// validPoolProperties.each { configKey, value ->
// bean.setProperty(configKey, value)
//// bean[configKey] = value
// if(bean.class.)
// bean."${configKey}" = value
// }
// }

delegate.with {
def host = redisConfigMap?.host ?: 'localhost'
def port = redisConfigMap.containsKey("port") ? "${redisConfigMap.port}" as Integer : Protocol.DEFAULT_PORT
def timeout = redisConfigMap.containsKey("timeout") ? "${redisConfigMap?.timeout}" as Integer : Protocol.DEFAULT_TIMEOUT
def password = redisConfigMap?.password ?: null
def database = redisConfigMap?.database ?: Protocol.DEFAULT_DATABASE
def sentinels = redisConfigMap?.sentinels ?: null
def masterName = redisConfigMap?.masterName ?: null

// If sentinels and a masterName is present, using different pool implementation
if (sentinels && masterName) {
if (sentinels instanceof String) {
sentinels = Eval.me(sentinels.toString())
}

if (sentinels instanceof Collection) {
"redisPool${key}"(JedisSentinelPool, masterName, sentinels as Set, ref(poolBean), timeout, password, database) { bean ->
bean.destroyMethod = 'destroy'
}
} else {
throw new RuntimeException('Redis configuraiton property [sentinels] does not appear to be a valid collection.')
}
} else {
"redisPool${key}"(JedisPool, ref(poolBean), host, port, timeout, password, database) { bean ->
bean.destroyMethod = 'destroy'
}
}

"redisService${key}"(serviceClass) {
redisPool = ref("redisPool${key}")
}
}
}

static def findValidPoolProperties(def properties) {
def fakeJedisPoolConfig = new JedisPoolConfig()
properties?.findAll { configKey, value ->
try {
fakeJedisPoolConfig[configKey] = value
return true
} catch (Exception exception) {
log.warn "Redis pool configuration parameter (${configKey}) does not exist on JedisPoolConfig or value is the wrong type"
return false
}
}
}
}
package grails.plugins.redis.util

import groovy.util.logging.Commons
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.JedisSentinelPool
import redis.clients.jedis.Protocol

/**
* This class provides a closure that can (and must) be used within the context of a BeanBuilder.
* To wire all redisServices using a custom class do the following
*
* def configureService = RedisConfigurationUtil.configureService
* def redisConfigMap = application.config.grails.redis ?: [:]
*
* configureService.delegate = delegate
* configureService(redisConfigMap, "", MyRedisService)
* redisConfigMap?.connections?.each { connection ->
* configureService(connection.value, connection?.key?.capitalize(), MyRedisService)
*}*
*/
@Commons
class RedisConfigurationUtil {

/**
* delegate to wire up the required beans.
*/
static def configureService = { delegate, redisConfigMap, key, serviceClass ->

def poolBean = "redisPoolConfig${key}"
def validPoolProperties = findValidPoolProperties(redisConfigMap.poolConfig)

//todo: fix the validPoolProperty eval or just add them inline
delegate."${poolBean}"(JedisPoolConfig) {
validPoolProperties.each { configKey, value ->
delegate.setProperty(configKey, value)
}
}
// delegate."${poolBean}"(JedisPoolConfig) { bean ->
// validPoolProperties.each { configKey, value ->
// bean.setProperty(configKey, value)
//// bean[configKey] = value
// if(bean.class.)
// bean."${configKey}" = value
// }
// }

delegate.with {
def host = redisConfigMap?.host ?: 'localhost'
def port = redisConfigMap.containsKey("port") ? "${redisConfigMap.port}" as Integer : Protocol.DEFAULT_PORT
def timeout = redisConfigMap.containsKey("timeout") ? "${redisConfigMap?.timeout}" as Integer : Protocol.DEFAULT_TIMEOUT
def password = redisConfigMap?.password ?: null
def database = redisConfigMap?.database ?: Protocol.DEFAULT_DATABASE
def sentinels = redisConfigMap?.sentinels ?: null
def masterName = redisConfigMap?.masterName ?: null
def useSSL = redisConfigMap?.useSSL ?: false

// If sentinels and a masterName is present, using different pool implementation
if (sentinels && masterName) {
if (sentinels instanceof String) {
sentinels = Eval.me(sentinels.toString())
}

if (sentinels instanceof Collection) {
"redisPool${key}"(JedisSentinelPool, masterName, sentinels as Set, ref(poolBean), timeout, password, database, useSSL) { bean ->
bean.destroyMethod = 'destroy'
}
} else {
throw new RuntimeException('Redis configuraiton property [sentinels] does not appear to be a valid collection.')
}
} else {
"redisPool${key}"(JedisPool, ref(poolBean), host, port, timeout, password, database, useSSL) { bean ->
bean.destroyMethod = 'destroy'
}
}

"redisService${key}"(serviceClass) {
redisPool = ref("redisPool${key}")
}
}
}

static def findValidPoolProperties(def properties) {
def fakeJedisPoolConfig = new JedisPoolConfig()
properties?.findAll { configKey, value ->
try {
fakeJedisPoolConfig[configKey] = value
return true
} catch (Exception exception) {
log.warn "Redis pool configuration parameter (${configKey}) does not exist on JedisPoolConfig or value is the wrong type"
return false
}
}
}
}

0 comments on commit 512341f

Please sign in to comment.