Git Product home page Git Product logo

baigan-config's Introduction

Baigan configuration

Maven CentralCircleCI

Baigan configuration is an easy to use configuration framework for Spring based applications.

What makes Baigan a rockstar configuration framework ?

  • Simple: Using Baigan configurations is as simple as annotating a Java interface.
  • Extensible: Extend configurations, create rules, define types that suit you.
  • Flexible: Baigan is a client library that can read configurations from multiple repositories:
    • Filesystem
    • Github
    • AWS S3
    • Etcd

Prerequisites

  • Java 1.8
  • Spring framework
  • AWS SDK

Getting started

To build the project run:

    mvn clean install -Pintegration-test

Integrating Baigan config

Baigan config is a spring project. The larger part of integration involves configuring beans to facilitate the spring beans.

Configuring components and Configuration interface scanning.

import org.zalando.baigan.BaiganSpringContext;

@ComponentScan(basePackageClasses = {BaiganSpringContext.class })
@ConfigurationServiceScan(basePackages = {"com.foo.configurations" })
public class Application {
}

The BaiganSpringContext class includes the Baigan-Config beans required to be loaded into the spring application context. And the @ConfigurationServiceScan annotation hints the Baigan registrar to look into the packages where the @BaiganConfig annotated interfaces could be found.

Annotate your configuration interfaces with @BaiganConfig

	@BaiganConfig
	public interface ExpressFeature {

	    public Boolean enabled();

	    public String serviceUrl();

	}

The above example code enables the application to inject ExpressFeature spring bean into any other Spring bean:

	@Component
	public class ExpressServiceImpl implements ExpressService{

		@Inject
		private ExpressFeature expressFeature;

		@Override
		public void sendShipment(final Shipment shipment){
			if (expressFeature.enabled()){
				final String serviceUrl = expressFeature.serviceUrl();
				// Use the configuration
			}
		}
	}

Creating configurations

Baigan configurations follow a specific schema and can be stored on any of the supported repositories.

Configuration schema

Configurations are stored in its simplest form as key values. A configuration is a pair of a dot(.) separated key and a value objects in JSON format.

A configuration object should conform to the following JSON Schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Configuration",
    "description": "A baigan configuration object value.",
    "type": "object",
    "properties": {
        "alias": {
            "description": "The identifier for the configuration, same as its key.",
            "type": "string"
        },
         "description": {
            "description": "Summary of the configuration.",
            "type": "string"
        },
         "defaultValue": {
            "description": "Default configuration if none of the condition is satisfied.",
            "type": {}
        },
         "conditions": {
            "description": "List of conditions to check",
            "type": "array",
            "items": {
            	"type": "object",
            	"properties": {
                    "value": {
                        "description": "Configuration value if this condition evaluates to true.",
                        "type": {}
                    },
            		"conditionType": {
                        "description": "Type of condition to evaluate. This can be custom defined, with custom defined properties.",
                        "type": "object",
                    }
                }
            }
        }
    },
    "required": ["defaultValue"]
}

Example configurations

This sample JSON defines a configuration for the key express.feature.enabled with the value true when the country_code is 3, and a default value of false.

{
  "alias": "express.feature.enabled",
  "description": "Feature toggle",
  "defaultValue": false,
  "conditions": [
    {
      "value": true,
      "conditionType": {
        "onValue": "3",
        "type": "Equals"
      },
      "paramName": "country_code"
    }
  ]
}

Pushing configuration to repositories

This step depends on the chosen repository.

Filesystem

Save a file named express-feature.json with the content above anywhere on the filesystem and bundle it as part of your application. To use it just specify the classpath in the constructor.

Github

Save a file named express-feature.json with the content above and push it to any Github repository. To use it just provide the required Github settings to the provider. Github Enterprise is also supported.

AWS S3

Save a file named express-feature.json with the content above and upload it to any S3 bucket. To use it just provide the bucket name and the object key.

Etcd

To create a key in etcd, you can either use etcdctl or the good old curl in the following way. Save a file named express-feature.json with the content above and push it to your etcd cluster:

With etcdctl v2:

etcdctl set express.feature.enabled < express-feature.json 

With curl:

curl -v -XPUT http://127.0.0.1:2379/v2/keys/express.feature.enabled -d value="$(cat express-feature.json)"

License

Copyright 2016 Zalando SE

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

baigan-config's People

Contributors

amjedonline avatar astarnell avatar lmineiro avatar lukasniemeier-zalando avatar mariadodevska avatar mostlymagic avatar rwitzel avatar sonerd avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.