sfn-parameters 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/LICENSE +13 -0
- data/README.md +107 -0
- data/lib/sfn-parameters/infrastructure.rb +70 -0
- data/lib/sfn-parameters/version.rb +3 -0
- data/lib/sfn-parameters.rb +3 -0
- data/sfn-parameters.gemspec +15 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60f94bc12df681811d673ed12d335b649d8afe34
|
4
|
+
data.tar.gz: ab2b0af5c83b21878b6414f3d94321cc56811932
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e742bb6759120d042aaf41b15beb3d834bd47a602480efcdad6e72731339fcb8559ed6c9acd81094343532436d01c3af22b983985efcea515e58b1b5bbee1737
|
7
|
+
data.tar.gz: 38afc7bef28db6ab7a29e7ca7a81a8af5a81d2d7dd9e7c74d9daaedf4fa79d481f3c11db935209328ac060b58d8e767ebd1e3189b43c8b6f424bad80a54b8c2e
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2015 Heavy Water Operations LLC.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# SparkleFormation Parameters Callback
|
2
|
+
|
3
|
+
Provides automatic assignment of stack parameter information.
|
4
|
+
Currently supported workflows:
|
5
|
+
|
6
|
+
* Infrastructure Mode
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
### Infrastructure Mode
|
11
|
+
|
12
|
+
Infrastructure mode assumes a single template which describes
|
13
|
+
an entire infrastructure (generally via nested templates). A
|
14
|
+
configuration file can provide all information required for the
|
15
|
+
root stack, as well as all descendant stacks.
|
16
|
+
|
17
|
+
#### Enable
|
18
|
+
|
19
|
+
The `sfn-parameters` callback is configured via the `.sfn`
|
20
|
+
configuration file. First the callback must be enabled:
|
21
|
+
|
22
|
+
~~~ruby
|
23
|
+
Configuration.new do
|
24
|
+
callbacks do
|
25
|
+
require ['sfn-parameters']
|
26
|
+
default ['parameters_infrastructure']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
~~~
|
30
|
+
|
31
|
+
#### Configure
|
32
|
+
|
33
|
+
Some optional configuration is available via the `.sfn` file
|
34
|
+
to control the behavior of the callback:
|
35
|
+
|
36
|
+
~~~ruby
|
37
|
+
Configuration.new do
|
38
|
+
sfn_parameters do
|
39
|
+
directory 'infrastructure'
|
40
|
+
destination 'default'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
~~~
|
44
|
+
|
45
|
+
* `directory` - Relative path from repository root to directory containing configuration files
|
46
|
+
* `destination` - Name of file holding configuration minus the extension
|
47
|
+
|
48
|
+
#### Functionality
|
49
|
+
|
50
|
+
One file will contain the configuration information required
|
51
|
+
for the stack operation (create/update). The location of this
|
52
|
+
file is generated using the configuration values provided
|
53
|
+
above. Using the default values used in the example above, the
|
54
|
+
file will be expected at:
|
55
|
+
|
56
|
+
~~~
|
57
|
+
REPO_ROOT/infrastructure/default.{rb,xml,json,yaml,yml}
|
58
|
+
~~~
|
59
|
+
|
60
|
+
The contents of the file will be processed using the bogo-config
|
61
|
+
library. This allows defining the file in a serialization format
|
62
|
+
(JSON, YAML, XML) or as a Ruby file.
|
63
|
+
|
64
|
+
#### File format
|
65
|
+
|
66
|
+
The basic structure of the file in JSON:
|
67
|
+
|
68
|
+
~~~json
|
69
|
+
{
|
70
|
+
"parameters": {},
|
71
|
+
"compile_parameters": {},
|
72
|
+
"apply_stacks": [],
|
73
|
+
"stacks": {}
|
74
|
+
}
|
75
|
+
~~~
|
76
|
+
|
77
|
+
Break down of the keys:
|
78
|
+
|
79
|
+
* `parameters` - Run time parameters sent to the orchestration API
|
80
|
+
* `compile_parameters` - Compile time parameters used to generate the template
|
81
|
+
* `apply_stacks` - List of stacks whose outputs should be applied
|
82
|
+
* `stacks`- Nested stack information
|
83
|
+
|
84
|
+
##### Example
|
85
|
+
|
86
|
+
~~~json
|
87
|
+
{
|
88
|
+
"parameters": {
|
89
|
+
"stack_creator": "chris"
|
90
|
+
},
|
91
|
+
"apply_stacks": [
|
92
|
+
"networking"
|
93
|
+
],
|
94
|
+
"stacks": {
|
95
|
+
"compute_stack": {
|
96
|
+
"parameters": {
|
97
|
+
"ssh_key": "default"
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
~~~
|
103
|
+
|
104
|
+
# Info
|
105
|
+
|
106
|
+
* Repository: https://github.com/sparkleformation/sfn-parameters
|
107
|
+
* IRC: Freenode @ #sparkleformation
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'sfn-parameters'
|
2
|
+
|
3
|
+
module Sfn
|
4
|
+
class Callback
|
5
|
+
# Auto load stack parameters for infrastructure pattern
|
6
|
+
class ParametersInfrastructure < Callback
|
7
|
+
|
8
|
+
# Valid file extensions for configuration file
|
9
|
+
VALID_EXTENSIONS = ['.rb', '.xml', '.json', '.yaml', '.yml']
|
10
|
+
|
11
|
+
# Update configuration after configuration is loaded
|
12
|
+
#
|
13
|
+
# @return [NilClass]
|
14
|
+
def after_config_update(*_)
|
15
|
+
config[:parameters] ||= Smash.new
|
16
|
+
config[:compile_parameters] ||= Smash.new
|
17
|
+
config[:apply_stack] ||= []
|
18
|
+
stack_name = arguments.first
|
19
|
+
content = load_file_for(stack_name)
|
20
|
+
process_information_hash(content, [])
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
alias_method :after_config_create, :after_config_update
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
# Load the configuration file
|
28
|
+
#
|
29
|
+
# @param stack_name [String]
|
30
|
+
# @return [Smash]
|
31
|
+
def load_file_for(stack_name)
|
32
|
+
root_path = config.fetch(:sfn_parameters, :directory, 'infrastructure')
|
33
|
+
isolation_name = config.fetch(:sfn_parameters, :destination,
|
34
|
+
ENV.fetch('SFN_PARAMETERS_DESTINATION', 'default')
|
35
|
+
)
|
36
|
+
paths = Dir.glob(File.join(root_path, "#{isolation_name}{#{VALID_EXTENSIONS.join(',')}}")).map(&:to_s)
|
37
|
+
if(paths.size > 1)
|
38
|
+
raise ArgumentError.new "Multiple parameter file matches encountered! (#{paths.join(', ')})"
|
39
|
+
elsif(paths.empty?)
|
40
|
+
raise ArgumentError.new 'No parameter file matches found!'
|
41
|
+
end
|
42
|
+
Bogo::Config.new(paths.first).data
|
43
|
+
end
|
44
|
+
|
45
|
+
# Process the given hash and set configuration values
|
46
|
+
#
|
47
|
+
# @param hash [Hash]
|
48
|
+
# @param path [Array<String>] stack name hierarchy
|
49
|
+
# @return [TrueClass]
|
50
|
+
def process_information_hash(hash, path=[])
|
51
|
+
hash.fetch(:parameters, {}).each do |key, value|
|
52
|
+
key = [*path, Bogo::Utility.camel(key)].compact.map(&:to_s).join('_')
|
53
|
+
config[:parameters][key] = value
|
54
|
+
end
|
55
|
+
hash.fetch(:compile_parameters, {}).each do |key, value|
|
56
|
+
key = [*path, Bogo::Utility.camel(key)].compact.map(&:to_s).join('_')
|
57
|
+
config[:compile_parameters][key] = value
|
58
|
+
end
|
59
|
+
hash.fetch(:stacks, {}).each do |key, value|
|
60
|
+
process_information_hash(value, [*path, Bogo::Utility.camel(key)].compact)
|
61
|
+
end
|
62
|
+
hash.fetch(:apply_stacks, []).each do |s_name|
|
63
|
+
config[:apply_stack] << s_name
|
64
|
+
end
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
|
2
|
+
require 'sfn-parameters/version'
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'sfn-parameters'
|
5
|
+
s.version = SfnParameters::VERSION.version
|
6
|
+
s.summary = 'SparkleFormation Parameters Callback'
|
7
|
+
s.author = 'Chris Roberts'
|
8
|
+
s.email = 'code@chrisroberts.org'
|
9
|
+
s.homepage = 'http://github.com/sparkleformation/sfn-parameters'
|
10
|
+
s.description = 'SparkleFormation Parameters Callback'
|
11
|
+
s.license = 'Apache-2.0'
|
12
|
+
s.require_path = 'lib'
|
13
|
+
s.add_dependency 'sfn', '>= 1.0.0', '< 2.0'
|
14
|
+
s.files = Dir['{lib,bin,docs}/**/*'] + %w(sfn-parameters.gemspec README.md CHANGELOG.md LICENSE)
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sfn-parameters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Roberts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sfn
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
description: SparkleFormation Parameters Callback
|
34
|
+
email: code@chrisroberts.org
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- CHANGELOG.md
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- lib/sfn-parameters.rb
|
43
|
+
- lib/sfn-parameters/infrastructure.rb
|
44
|
+
- lib/sfn-parameters/version.rb
|
45
|
+
- sfn-parameters.gemspec
|
46
|
+
homepage: http://github.com/sparkleformation/sfn-parameters
|
47
|
+
licenses:
|
48
|
+
- Apache-2.0
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.4.8
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: SparkleFormation Parameters Callback
|
70
|
+
test_files: []
|
71
|
+
has_rdoc:
|