Skip to content

GetConfigurationMethod

Michael J. Ryan edited this page May 21, 2015 · 1 revision

azureUtil.config()

The azure-config-util object instance presents a config() method that returns a promise, that will resolve to a cached configuration object.

This configuration comes with an Configuration Table (Azure Storage Table) whose name/configuration is passed into function that creates the instance (or via Environment Variables)

The resulting configuration lookup is the core to all other extension methods on an instance.

// ES7 async/await
var cfg = await azureUtil.config();
// Promise/Thenable
azureUtil.config().then(function(cfg){
  ...
});

Configuration Table Keys

Namespace

The Namespace field represents the namespace of the application itself. All results subject to a given configuration object will be within the same namespace.

Environment

The environment field represents one of the following runtime environments, or the hostname of a machine for configuration values.

When a given environment is selected, a set of values for Environment are queried and the most relevant response is returned, as follows. hostname refers to the given hostname for the runtime environment (require('os').hostname()), other values are literal strings.

  • local (default)
    • priority: [hostname, local, development, dev, default]
  • development or dev
    • priority: [hostname, development, dev, default]
  • testing or test
    • priority: [hostname, testing, test, default]
  • qa
    • priority: [hostname, qa, default]
  • staging or stage
    • priority: [hostname, staging, stage, default]
  • production or prod
    • priority: [hostname, production, prod, default]

Section

The Section field represents a collection of configuration keys, and is a hierarchal structure/value. In the configuration object, this value is lowercased, and trimmed for easier lookup.

Key

The Key field represents a single value under a Section. The value is deconstructed from the JsonValue field.

Example

For example, you have the following records

Namespace Environment Section Key JsonValue
default development table mytable {"storage":"mytest"}
default mydesktop table mytable {"storage":"mydev"}

When running this example from a host with a name of "mydesktop" you will get an object with the following structure.

expect(cfg).to.deep.equal({
  "table": {
    "mytable": {
      "storage": "mytest"
    }
  }
}); //true

When running under a CONFIG_ENV or NODE_ENV of either "dev" or "development" from another hostname, you'll get the reflected value in the configuration.

Clone this wiki locally