Skip to content

Instantly share code, notes, and snippets.

@radeinla
Last active September 15, 2015 11:45
Show Gist options
  • Save radeinla/7cdbed52d91c85d45f72 to your computer and use it in GitHub Desktop.
Save radeinla/7cdbed52d91c85d45f72 to your computer and use it in GitHub Desktop.
grails 2.5.1 upgrade problem: external configs

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:

  1. Change org.codehaus.groovy.grails.commons.cfg.ConfigurationHelper to not use .exists() but I'm not sure how to override a grails-core class.
  2. Change org.springframework.core.io.URLResource to use a different code for .exists() but I'm not sure how to do that either.
  3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment