Skip to content

Latest commit

 

History

History
119 lines (87 loc) · 2.04 KB

README.md

File metadata and controls

119 lines (87 loc) · 2.04 KB

go-kmsconfig

JSON config with KMS encryption support.

Setup

go-kmsconfig expects the following config structure:

- config
-- staging.json
-- qa.json
-- live.json

An example of a config file looks like:

{
  "app": {
    "endpoint_url": {
      "value": "http://0.0.0.0:4569",
      "secure": false
    }
  }
}

Encrypted Values

Values can be encrypted with KMS and stored base64 encoded in the config. The consuming service needs to have Decrypt permissions on the KMS key used to encrypt the value.

If the secure node is set to true for a child node then go-kmsconfg will attempt to decrypt the value on load.

Usage

glide get github.com/vidsy/go-kmsconfig

Environment

By default, go-kmsconfig looks for development.json in the config folder provided to .NewConfig.

For other environments, the following environment variable can be set:

AWS_ENV=staging

and go-kmsconfig will attempt to load path_to_config/staging.json.

Simple Example

package main

import (
  "log"

  "github.com/vidsy/go-kmsconfig/kmsconfig"
)

func main() {
  parsedConfig := kmsconfig.NewConfig("./path_to_config_folder")

  err := parsedConfig.Load()
	if err != nil {
		log.Fatal(err)
	}

  configValue, err = parsedConfig.String("app", "some_config_node")
	if err != nil {
		return nil, err
	}

  log.Println("Config value for 'development.json' is: %s", configValue)
}

Advanced Example

package main

import (
  "log"
  "time"
  "github.com/vidsy/go-kmsconfig/kmsconfig"
)

type (
  Config struct {
    App `config:"app"`
  }

  App struct {
    Counter          int64         `config:"counter"`
    Flag             bool          `config:"flag"`
    SleepDuration    time.Duration `config:"sleep_duration" config_duration_type:"seconds"`
  }
)

func main() {
  var config Config
  err := config.Populate(&config)
  if err != nil {
		log.Fatal(err)
  }

  log.Println("SleepDuration value for 'development.json' is: %s", config.App.SleepDuration)
}