Skip to content
This repository has been archived by the owner on Dec 21, 2018. It is now read-only.

Remote configuration for Play Framework 2

License

Notifications You must be signed in to change notification settings

payintech/play-remote-configuration

Repository files navigation

Play Remote Configuration

Latest release JitPack Build GitHub license

Remote configuration for Play Framework 2


About this project

In production, it is not always easy to manage the configuration files of a Play Framework application, especially when it running on multiple servers. The purpose of this project is to provide a simple way to use a remote configuration with a Play Framework application.

By default, the following providers are provided:

Short name Name Basic authentication
CONSUL HashiCorp Consul
ETCD CoreOS etcd
HTTP_BASIC HTTP (Basic Implementation)

Add play-remote-configuration to your project

build.sbt

resolvers += "jitpack" at "https://jitpack.io"

libraryDependencies += "com.github.payintech" % "play-remote-configuration" % "release~YY.MM"

How to use

You can use this project in two ways. The first is to simply set the right application loader in your configuration file. The second, if you have an existing application loader, is to extend it with the class provided in this project : com.payintech.play.remoteconfiguration.PlayApplicationLoader.

application.conf (first way)

play {
  application {

    ## Application Loader
    # https://www.playframework.com/documentation/latest/JavaDependencyInjection
    # ~~~~~
    loader = "com.payintech.play.remoteconfiguration.PlayApplicationLoader"
  }
}

ApplicationLoader.java (second way)

import com.payintech.play.remoteconfiguration.PlayApplicationLoader;

public class ApplicationLoader extends PlayApplicationLoader {

    @Override
    public GuiceApplicationBuilder builder(final Context context) {
        final GuiceApplicationBuilder newInitialBuilder = super.builder(context);
        // Your custom code
        return newInitialBuilder;
    }
}

Configuration

remote-configuration {

  ## Provider to use
  # Short name of the provider to use to retrieve remote
  # configuration. Built-in available providers are:
  #  - CONSUL        (HashiCorp Consul)
  #  - ETCD          (CoreOS etcd)
  #  - HTTP_BASIC    (HTTP - Basic Implementation)
  # ~~~~~
  provider = ""
  provider = ${?RCONF_PROVIDER}

  ## HashiCorp Consul
  # ~~~~~
  consul {

    # API endpoint. HTTPS endpoint could be used,
    # but the SSL certificate must be valid
    endpoint = "http://127.0.0.1:8500/"
    endpoint = ${?RCONF_CONSUL_ENDPOINT}

    # Authentication token. If ACL are anabled on
    # your Consul cluster, this variable allow you
    # to set the token to use with each API calls
    authToken = ""
    authToken = ${?RCONF_CONSUL_AUTHTOKEN}

    # Prefix. Get only values with key beginning
    # with the configured prefix
    prefix = "/"
    prefix = ${?RCONF_CONSUL_PREFIX}
  }

  ## CoreOS etcd
  # ~~~~~
  etcd {
    # API endpoint. HTTPS endpoint could be used,
    # but the SSL certificate must be valid
    endpoint = "http://127.0.0.1:2379/"
    endpoint = ${?RCONF_ETCD_ENDPOINT}

    # Authentication username
    username = ""
    username = ${?RCONF_ETCD_USERNAME}

    # Authentication password
    password = ""
    password = ${?RCONF_ETCD_PASSWORD}

    # Prefix. Get only values with key beginning
    # with the configured prefix. With etcd, it
    # must be a directory.
    prefix = "/"
    prefix = ${?RCONF_ETCD_PREFIX}
  }


  ## HTTP
  # ~~~~~
  http {

    # URL of the configuration file to retrieve. HTTPS
    # endpoint could be used, but the SSL certificate
    # must be valid
    url = "http://127.0.0.1/playcfg/application.conf"
    url = ${?RCONF_HTTP_ENDPOINT}
  }
}