cfn-toml 1.0.4 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae9bc1c1b290518289f35114d0bcb93699f1b36c782efe0bcf5774d562e75a00
4
- data.tar.gz: b37be42117520546fcf181d85dbb245420a49f8f9ce9d709d20c4519084f8e58
3
+ metadata.gz: 35b41b356e026ef8b7597a74a5dc56a3ae1eeb45e5fb222500eb7d0d9846a6b4
4
+ data.tar.gz: 1b58334686de2ed7c1b25c5a9cd79db33f484ef00d37828ef9720e0a15be8727
5
5
  SHA512:
6
- metadata.gz: 40a1f5c6b1569b58e360bfba8e06df90549f852f32205af9ba14d4a6b587d2a2c0df343d3baf1b56db9c571264eec1cad0c3deb4b560ade655509f0fd8994bc2
7
- data.tar.gz: a86cd3a80aee41f5f74fca6db84995cf49de56978cca04160beeb13956c8b9cdaca525ba1eb02a7cd19783c4e89c5d92510acd2e636ae33b25e02790d938945a
6
+ metadata.gz: 2bd730055d08800f0ef9e927bfcd3751b2837688428e28a45dfb7d84ab088cdee05c7cad3f2e7c8a1e18929afda4622726b91386bf7b8094cc3291d00b319b0d
7
+ data.tar.gz: dfbf00132a62886dac073e01c7cffc2be21b9fcad0093fe6c21676dc04512d3eca0a00c3495e7419ff9dbb2a4dff1034fc64e654d7aff9c331d8efa8efd66c30
data/README.md CHANGED
File without changes
data/bin/cfn-toml CHANGED
@@ -3,7 +3,6 @@ $LOAD_PATH << File.expand_path('lib')
3
3
 
4
4
  require 'optparse'
5
5
  require 'cfn_toml'
6
- require 'pry'
7
6
  require 'pathname'
8
7
 
9
8
  def show_version
@@ -15,9 +14,10 @@ def show_help
15
14
  puts <<~HELP
16
15
  Usage: cfn-toml [options]
17
16
  Options:
18
- -t, --toml path to toml file
17
+ -t, --toml path to toml file
19
18
  -p, --profile profile name (only used with cfn-toml init)
20
- -v, --version show version
19
+ -f, --cloudformation-template populate toml parameters (only used with cfn-toml init)
20
+ -v, --version show version
21
21
 
22
22
  Initialize:
23
23
  cfn-toml init mystack --profile myprofile
@@ -26,7 +26,7 @@ def show_help
26
26
  REGION=$(cfn-toml key deploy.region)
27
27
  PARAMETERS=$(cfn-toml params v1)
28
28
  OVERRIDE_PARAMETERS=$(cfn-toml params v2)
29
- BUCKET=$(cfn-toml key bucket --tom /path/to/conf.prod.toml)
29
+ BUCKET=$(cfn-toml key bucket --toml /path/to/conf.prod.toml)
30
30
  HELP
31
31
  exit 0
32
32
  end
@@ -42,6 +42,10 @@ parser = OptionParser.new do|opts|
42
42
  options[:profile] = name
43
43
  end
44
44
 
45
+ opts.on('-f PATH', '--cloudformation-template PATH') do |path|
46
+ options[:cfn_filepath] = path
47
+ end
48
+
45
49
  opts.on('-h', '--help') do
46
50
  show_help
47
51
  end
@@ -59,6 +63,16 @@ begin
59
63
  options[:toml_filepath] = File.expand_path options[:toml_filepath]
60
64
  options[:profile] ||= 'default'
61
65
 
66
+ if options[:cfn_filepath].nil?
67
+ if File.exists?(File.expand_path('template.yaml'))
68
+ options[:cfn_filepath] = "template.yaml"
69
+ elsif File.exists?(File.expand_path('template.yml'))
70
+ options[:cfn_filepath] = "template.yml"
71
+ end
72
+ options[:cfn_filepath] ||= "template.yaml"
73
+ end
74
+ options[:cfn_filepath] = File.expand_path options[:cfn_filepath]
75
+
62
76
  if arg1 == 'key'
63
77
  result = CfnToml.key options[:toml_filepath], arg2
64
78
  STDOUT.puts result
@@ -70,7 +84,7 @@ begin
70
84
  # arg3 - profile
71
85
  stackname = nil
72
86
  stackname = arg2 if !arg2.nil? || !arg2 == ''
73
- CfnToml.init options[:toml_filepath], arg2, options[:profile]
87
+ CfnToml.init options[:toml_filepath], options[:cfn_filepath], arg2, options[:profile]
74
88
  STDOUT.puts options[:toml_filepath]
75
89
  end
76
90
 
@@ -1,3 +1,3 @@
1
1
  module CfnToml
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.7'
3
3
  end
data/lib/cfn_toml.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'toml-rb'
2
2
  require 'fileutils'
3
+ require 'yaml'
3
4
 
4
5
  module CfnToml
5
- def self.init toml_filepath, stackname, profile
6
+ def self.init toml_filepath, cfn_filepath, stackname, profile
6
7
  region = `aws configure get region --profile #{profile}`
7
- region ||= 'us-east-1'
8
+ region = 'us-east-1' if region.nil? || region == ''
8
9
  stackname ||= 'stackname'
9
10
 
10
11
  toml_path = File.dirname toml_filepath
@@ -16,6 +17,28 @@ module CfnToml
16
17
  f.write "stack_name = '#{stackname}'\n"
17
18
  f.write "region = '#{region.chomp}'\n\n"
18
19
  f.write "[parameters]\n"
20
+ self.init_parameters f, cfn_filepath
21
+ end
22
+ end
23
+
24
+ def self.init_parameters f, cfn_filepath
25
+ return unless File.exists?(cfn_filepath)
26
+ contents = File.open(cfn_filepath).read
27
+ hash = YAML.load(contents)
28
+ return unless hash.key?('Parameters')
29
+
30
+ hash['Parameters'].each do |name, values|
31
+ if values.key?('Description')
32
+ lines = values['Description'].split("\n")
33
+ lines.each do |line|
34
+ f.write "# #{line} \n"
35
+ end
36
+ end
37
+ if values.key?('Default')
38
+ f.write "##{name} = '#{values['Default']}' # #{values['Type']}\n"
39
+ else
40
+ f.write "#{name} = '' # #{values['Type']}\n"
41
+ end
19
42
  end
20
43
  end
21
44
 
@@ -25,14 +48,14 @@ module CfnToml
25
48
  data[namespace][key]
26
49
  end
27
50
 
28
- def self.params toml_filepath, params_version
51
+ def self.params toml_filepath, params_version, parameters_name='parameters'
29
52
  data = TomlRB.load_file(toml_filepath)
30
53
  if params_version == 'v1'
31
- data['parameters'].map do |k,v|
54
+ data[parameters_name].map do |k,v|
32
55
  "ParameterKey=#{k},ParameterValue=#{v}"
33
56
  end.join(' ')
34
57
  elsif params_version == 'v2'
35
- data['parameters'].map do |k,v|
58
+ data[parameters_name].map do |k,v|
36
59
  "#{k}=#{v}"
37
60
  end.join(' ')
38
61
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfn-toml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Brown
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-15 00:00:00.000000000 Z
11
+ date: 2022-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: pry
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: toml-rb
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +54,7 @@ homepage: https://github.com/teacherseat/cfn-toml
68
54
  licenses:
69
55
  - MIT
70
56
  metadata: {}
71
- post_install_message:
57
+ post_install_message:
72
58
  rdoc_options: []
73
59
  require_paths:
74
60
  - lib
@@ -83,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
69
  - !ruby/object:Gem::Version
84
70
  version: '0'
85
71
  requirements: []
86
- rubygems_version: 3.1.2
87
- signing_key:
72
+ rubygems_version: 3.1.4
73
+ signing_key:
88
74
  specification_version: 4
89
75
  summary: Configuration file parsing for CFN Bash scripting
90
76
  test_files: []