-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from thorstenhuhn/feature/environment_nested
Added environment_nested plugin
- Loading branch information
Showing
7 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Environment Nested Plugin | ||
If you add `environment_nested` to your list of data sources in `common.yaml`, you'll be able to create or overwrite nested configuration variables. | ||
|
||
```yaml | ||
data_sources: [ "defaults", "file", "environment_nested" ] | ||
template_sources: [ "file" ] | ||
|
||
defaults: | ||
global: | ||
restapi: | ||
server: | ||
port: 80 | ||
``` | ||
|
||
Setting environment variable `restapi_server_port=8080` will overwrite value `80` from defaults. | ||
|
||
To overwrite large structures it's probably easier to use `environment_json`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Feature: Configure tiller with nested environment variables | ||
|
||
Scenario: Import environment variable using string data type | ||
Given I use a fixture named "environment_nested" | ||
And I set the environment variables to: | ||
| variable | value | | ||
| my_nested_var | http://www.somecompany.com | | ||
When I successfully run `tiller -b . -v -n` | ||
Then a file named "test.txt" should exist | ||
And the file "test.txt" should contain "test_var: http://www.somecompany.com" | ||
|
||
Scenario: Import environment variable using numeric data type | ||
Given I use a fixture named "environment_nested" | ||
And I set the environment variables to: | ||
| variable | value | | ||
| my_nested_var | 1234 | | ||
When I successfully run `tiller -b . -v -n` | ||
Then a file named "test.txt" should exist | ||
And the file "test.txt" should contain "test_var: 1234" | ||
|
||
Scenario: Import environment variable using boolean data type | ||
Given I use a fixture named "environment_nested" | ||
And I set the environment variables to: | ||
| variable | value | | ||
| my_nested_var | true | | ||
When I successfully run `tiller -b . -v -n` | ||
Then a file named "test.txt" should exist | ||
And the file "test.txt" should contain "test_var: true" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
data_sources: [ "defaults", "environment_nested" ] | ||
template_sources: [ "file" ] | ||
|
||
defaults: | ||
|
||
test.erb: | ||
target: test.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_var: <%= my['nested']['var'] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'tiller/datasource' | ||
|
||
class EnvironmentNestedDataSource < Tiller::DataSource | ||
|
||
def global_values | ||
values = Hash.new | ||
ENV.each do |k, v| | ||
begin | ||
v = YAML.load(v) # helper to get real data type instead of string | ||
values.deep_merge!(k.split('_').reverse.inject(v) { |a, n| { n => a } }) | ||
rescue | ||
Tiller::log.debug("Environment variable #{k} with value #{v} could not be unfolded (ignored)") | ||
end | ||
end | ||
values | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters