#Stormpath is Joining Okta We are incredibly excited to announce that Stormpath is joining forces with Okta. Please visit the Migration FAQs for a detailed look at what this means for Stormpath users.
We're available to answer all questions at [email protected].
Stormpath configuration loader.
This library is responsible for loading the Stormpath configuration. It is an internal module used by stormpath-node-sdk, and express-stormpath, and is not meant for general consumption.
To install this library, just run:
$ npm install stormpath-config --save
First, start by including the library:
var stormpathConfig = require('stormpath-config');
Once the library is loaded, you'll need to initialize a new Loader
object using the library like so:
var configLoader = new stormpathConfig.Loader([/* strategies */]);
Notice how the first argument is commented out. This needs to be an array of one or many strategies. See strategies for a list of all supported strategies and on how to create your own.
E.g. below demonstrates how the Stormpath configuration can be created and loaded from only the environment.
var strategy = stormpathConfig.strategy;
var configLoader = new StormpathConfig.Loader([
new strategy.LoadEnvConfigStrategy(),
new strategy.LoadFileConfigStrategy('~/stormpath.yml')
]);
Now, once you got your new Loader
object all you need to do is call the configLoader.load(callback)
method to load the configuration data.
You can do this like so:
configLoader.load(function (err, config) {
if (err) {
console.error(err);
} else {
console.log("Configuration loaded:", config);
}
});
A strategy is simply a prototype that implements a method named process
that takes the parameters config
and callback
. All it expects is that the callback is called with the first argument as an error (null if none) and the second containing the modified/processed config. E.g. as shown below:
function MyConfigStrategy () {
}
MyConfigStrategy.prototype.process = function (config, callback) {
// Apply strategy to config and return result in callback
config.someNewField = "abc"; // Append someNewField to our config
callback(null, config);
};
Some default strategies for loading a configuration has been included. These are accessible through the strategy
export. I.e. require('stormpath-config').strategy
.
Loads configuration from the system environment.
Loads client API key configuration from a .properties file.
Loads a configuration from either a JSON or YAML file.
Extend a the configuration with an existing object.
Enriches the configuration with client config resolved at runtime.
Enriches the configuration with client config resolved from the Stormpath API.
Enriches the configuration with integration config resolved at runtime.
Enriches the configuration with integration config resolved from the Stormpath API.
Validates the client configuration.
Below are some resources you might find useful:
- Write unit tests.
You can make your own contributions by forking this repository, making your
changes in a feature branch, and then issuing a pull request back to this
repository on the master
branch.
Here's how you might do this if you wanted to contribute something:
$ git clone https://github.com/stormpath/stormpath-node-config.git
$ cd stormpath-node-config
$ git checkout -b feature-somthing-something
$ # make changes
$ git commit -m "This was easy!"
$ # submit a pull request
We regularly maintain this repository, and are quick to review pull requests and accept changes!
We <333 contributions!
Copyright ©2015 Stormpath, Inc. and contributors.
This project is open-source via the Apache 2.0 License.