We are not able to load external configs through AWS S3.
On 2.5.1:
def resource = resolver.getResource(location.toString())
if(resource.exists()) {
InputStream stream = null
try {
stream = resource.getInputStream()
if (resource.filename.endsWith('.groovy')) {
def newConfig = configSlurper.parse(stream.getText("UTF-8"))
config.merge(newConfig)
}
else if (resource.filename.endsWith('.properties')) {
def props = new Properties()
props.load(stream)
def newConfig = configSlurper.parse(props)
config.merge(newConfig)
}
else if (resource.filename.endsWith('.class')) {
def configClass = new GroovyClassLoader(configSlurper.classLoader).defineClass( (String)null, stream.getBytes())
def newConfig = configSlurper.parse(configClass)
config.merge(newConfig)
}
}
finally {
stream?.close()
}
} else {
LOG.warn "Unable to load specified config location $location : File does not exist."
}
On 2.3.9:
def resource = resolver.getResource(location.toString())
InputStream stream = null
try {
stream = resource.getInputStream()
if (resource.filename.endsWith('.groovy')) {
def newConfig = configSlurper.parse(stream.getText("UTF-8"))
config.merge(newConfig)
}
else if (resource.filename.endsWith('.properties')) {
def props = new Properties()
props.load(stream)
def newConfig = configSlurper.parse(props)
config.merge(newConfig)
}
else if (resource.filename.endsWith('.class')) {
def configClass = new GroovyClassLoader(configSlurper.classLoader).defineClass( (String)null, stream.getBytes())
def newConfig = configSlurper.parse(configClass)
config.merge(newConfig)
}
}
finally {
stream?.close()
}
The main difference is 2.5.1
checks for .exists()
which fires up a HEAD
request with the same URL and 2.3.9
only checks if the steam is readable.
Now that shouldn't be a problem but AWS Signed URLs are valid only for a specific HTTP Verb.
There are a couple of things we can do:
- Change
org.codehaus.groovy.grails.commons.cfg.ConfigurationHelper
to not use.exists()
but I'm not sure how to override a grails-core class. - Change
org.springframework.core.io.URLResource
to use a different code for.exists()
but I'm not sure how to do that either. - Download the s3 config and save as a temporary file on the server and use that for a config location.
Can you guys give me guidance on how to do this? I'm not that intimate with Spring nor overriding grails core classes. I can also try #3 though.