cfn-toml 1.0.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 00bd39e7cbec125d8539fd5abc41160bf5888ea787c4d44c5871920805c9245f
4
+ data.tar.gz: 877e8e6de0dc303fd53b8b4c667a712367553872980f141328feb0d12544964c
5
+ SHA512:
6
+ metadata.gz: a16742d4e1e9ba72e94b55e831350408bd30493bd99ab1564ad8a2287821f73eae8d19c5ec25cd9ea34eb34af7d611629b9fc6a484c91627c71e5c249fcf6485
7
+ data.tar.gz: c83583d1c01b241ce8d07c4bf4a3be297cd51fa3b352fe5ed4827a064c6f437e17dbf7e162e09e4c528989acafcee9504d02b263668f5d9b11247f5e4928807a
@@ -0,0 +1,83 @@
1
+ ### What is Cfn-Toml?
2
+
3
+ cfn-toml will read a toml file that is designed to be used with CloudFormation CLI commands within a bash script.
4
+
5
+ ### How to use
6
+
7
+ Cfn-Toml automatically looks for a file called `conf.toml` in the working directory.
8
+
9
+ You can then use the following CLI commands to copy configuration variables into enviroment variables.
10
+
11
+ ### Toml file example
12
+ ```
13
+ [deploy]
14
+ profile = 'myprofile'
15
+ bucket = 'mybucket'
16
+ region = 'us-east-1'
17
+ stack_name = 'stack_name'
18
+
19
+ [parameters]
20
+ ArtifactName = 'myartifact'
21
+ InstanceType = 't2.micro'
22
+ ```
23
+
24
+ ### Bash sciprt example
25
+ ```
26
+ #!/usr/bin/env bash
27
+
28
+ PROFILE=$(cfn-toml key deploy.profile)
29
+ BUCKET=$(cfn-toml key deploy.bucket)
30
+ REGION=$(cfn-toml key deploy.region)
31
+ STACK_NAME=$(cfn-toml key deploy.stack_name)
32
+ PARAMETERS=$(cfn-toml params v2)
33
+
34
+
35
+ # deploying stack
36
+ echo "== Deploying stack..."
37
+ # -----------------
38
+ aws cloudformation deploy \
39
+ --profile $PROFILE \
40
+ --region $REGION \
41
+ --stack-name $STACK_NAME \
42
+ --s3-bucket $BUCKET \
43
+ --template-file template.yaml" \
44
+ --parameter-overrides $PARAMETERS \
45
+ --capabilities CAPABILITY_NAMED_IAM
46
+ ```
47
+
48
+ ## Parameters Versions
49
+
50
+ There are two versions of parameters based on the AWS CLI syntax
51
+
52
+ ### Version1
53
+
54
+ When you are using commands like `aws cloudformation create-stack`
55
+
56
+ ```
57
+ cfn-toml parameters v1
58
+ ```
59
+
60
+ It will output as such:
61
+
62
+ ```
63
+ ParameterKey=MyKey,ParameterValue=MyValue ParameterKey=MyKey2,ParameterValue=MyValue2
64
+ ```
65
+
66
+ ### Version2
67
+
68
+ When you are using commands like `aws cloudformation deploy`
69
+
70
+ ```
71
+ cfn-toml parameters v2
72
+ ```
73
+
74
+ It will output as such:
75
+
76
+ ```
77
+ MyKey1=MyValue1 MyKey2=MyValue2
78
+ ```
79
+
80
+ ## Specify Toml Filepath
81
+
82
+ You can override the default path for toml
83
+ cfn-toml parameters v1 --toml /path/to/myconfig.dev.toml
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.expand_path('lib')
3
+
4
+ require 'optparse'
5
+ require 'cfn_toml'
6
+
7
+ def show_version
8
+ puts "CfnToml v#{CfnToml::VERSION}"
9
+ exit 0
10
+ end
11
+
12
+ def show_help
13
+ puts <<~HELP
14
+ Usage: toml-conf [options]
15
+ Options:
16
+ -t, --toml path to toml file
17
+ -v, --version show version
18
+ HELP
19
+
20
+ exit 0
21
+ end
22
+
23
+ options = {}
24
+
25
+ arg1 = ARGV[0]
26
+ arg2 = ARGV[1]
27
+
28
+ parser = OptionParser.new do|opts|
29
+ opts.on('--toml PATH') do |path|
30
+ options[:toml_filepath] = path
31
+ end
32
+
33
+ opts.on('-h', '--help') do
34
+ show_help
35
+ end
36
+ end
37
+
38
+
39
+ begin
40
+ parser.parse!
41
+
42
+ show_help if options.empty?
43
+
44
+ # Defaults
45
+ options[:toml_filepath] ||= 'config.toml'
46
+
47
+ result =
48
+ if arg1 == 'key'
49
+ CfnToml.key options[:toml_filepath], arg2
50
+ elsif arg1 == 'params'
51
+ CfnToml.params options[:toml_filepath], arg2
52
+ end
53
+
54
+ STDOUT.puts result
55
+
56
+ exit 0
57
+ rescue => e
58
+ STDERR.puts "ERROR: #{e.message}"
59
+
60
+ if options[:debug]
61
+ STDERR.puts
62
+ STDERR.puts e.backtrace
63
+ end
64
+
65
+ exit 1
66
+ end
@@ -0,0 +1,22 @@
1
+ require 'toml-rb'
2
+
3
+ module CfnToml
4
+ def self.key toml_filepath, key
5
+ data = TomlRB.load_file(toml_filepath)
6
+ namespace, key = key.split('.')
7
+ data[namespace][key]
8
+ end
9
+
10
+ def self.params toml_filepath, params_version
11
+ data = TomlRB.load_file(toml_filepath)
12
+ if params_version == 'v1'
13
+ data['parameters'].map do |k,v|
14
+ "ParameterKey=#{k},ParameterValue=#{v}"
15
+ end.join(' ')
16
+ elsif params_version == 'v2'
17
+ data['parameters'].map do |k,v|
18
+ "#{k}=#{v}"
19
+ end.join(' ')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module CfnToml
2
+ VERSION = '1.0.3'
3
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cfn-toml
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Brown
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: toml-rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.4
41
+ description: Configuration file parsing for CFN Bash scripting
42
+ email:
43
+ - andrew@teacherseat.com
44
+ executables:
45
+ - cfn-toml
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - bin/cfn-toml
51
+ - lib/cfn_toml.rb
52
+ - lib/cfn_toml/version.rb
53
+ homepage: https://github.com/teacherseat/cfn-toml
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '2.4'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.1.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Configuration file parsing for CFN Bash scripting
76
+ test_files: []