BBC::Cosmos::Tools::Config
This gem provides functionality to generate and push config to the cosmos platform.
Installation
Add this line to your application's Gemfile:
gem 'bbc-cosmos-tools-config'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bbc-cosmos-tools-config
Usage
The gem expects a certain folder structure for the config files:
Folder structure
├── configs
│ ├── {env_name (int/test/stage/live)}
│ │ ├── {project_name}.yaml
│ ├── app_config.yaml
an example of this would be:
├── configs
│ ├── int
│ │ ├── my_project.yaml
│ ├── test
│ │ ├── my_project.yaml
│ ├── stage
│ │ ├── my_project.yaml
│ ├── live
│ │ ├── my_project.yaml
│ ├── app_config.yaml
Project Config structure
All of the configs are in yaml format, the project yaml has the following format:
components:
"component_id":
a_config_key: "it's value"
another_key: "Another value"
shared:
shared_key: "shared_value"
The config has a number of components under a project, and the shared key allows you to
have shared config for the components. The config is built up from the shared data with
the component config merged in afterwards.
Application config
There's also an application config that stores data used by the app, at the moment this
is only the api endpoints.
bbc:
cosmos:
api: "https://www.my.api.com"
endpoint: "/some/restful/endpoint"
The gem is a cli application and currently has two functions:
Generating config
bbc-cosmos-tools-config generate {project_name} [{component_id = nil, environment = 'int' --cosmos_format]
project_name
The project name is required, the other parameters are optional.
component_id
This is the id of the component in the components block of the project config. If you omit the component id then all components for the project are output.
environment
This maps to the folder underneath the configs directory, is omitted int
is chosen as default.
--cosmos_output
As the cosmos API requires a slightly different JSON structure, you can have it formatted this way by passing this flag.
Pushing config
bbc-cosmos-tools-config push {project_name} [{cert_path = nil, component_id = nil, environment = 'int' --force]
project_name
The project name is required, the other parameters are optional.
cert_path
This is the path to a valid client cert that can authenticate with the supplied API.
component_id
This is the id of the component in the components block of the project config. If you omit the component id then all components for the project have their configs updated.
environment
This maps to the folder underneath the configs directory, is omitted int
is chosen as default.
--force
By default, before pushing changes to the API you're asked to confirm the action - This flag removes that confirmation.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request