autostacker24 1.0.57 → 1.0.58

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
  SHA1:
3
- metadata.gz: 6b9061f0245437aac8fb55ed942950963c637d01
4
- data.tar.gz: 2dd618bddd219ffd00c0f66e807816ce9ed6afc8
3
+ metadata.gz: 72ed7bed03a37715c22a125d72d1e487e65cb6d9
4
+ data.tar.gz: d47a4631f4686097ec39bf4e0c637729e713d401
5
5
  SHA512:
6
- metadata.gz: 37a4b4685dd4736ca2ce1ec30e784f4b827996714381e33294d64ff70b44f318ebf0228fb0ff301b031c0f2cb83d328354182195a32e0a9658338c838f7636c0
7
- data.tar.gz: dd10f37cddeebb519fb9c1ca8110e7eb5f020367661775173a38e74550e91149710f1307f2132617c16b145ff1b8958866a7cf7a0fc236019c9f180993fc363d
6
+ metadata.gz: 485b4cfe5ae6c4795279f45f81bb63a044c3a38832458728f7f7c2af2741bcc2462130fc11337e7ab79c687b9b3bb276f584d8f933bb5ce72b9654ac51cc1a20
7
+ data.tar.gz: ba631ef91ddd8dd8db70879686c9a46dbb423352ead6628f3a8e873e34f266d6cf7429ed964db560b426a54cf79b49ce22d3f888a4e3ab4464719a060050a592
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'autostacker24'
5
+
6
+ def parse_options(argv)
7
+ params = {}
8
+ parser = OptionParser.new
9
+ parser.on("--template VALUE", "template location") do |value|
10
+ params[:template] = value
11
+ end
12
+ parser.parse(argv)
13
+ return params
14
+ end
15
+
16
+ command = ARGV[0]
17
+ params = parse_options(ARGV)
18
+
19
+ if command == "validate"
20
+ Stacker.validate_template(params[:template])
21
+ elsif command == "preprocess"
22
+ puts Stacker.template_body(params[:template])
23
+ else
24
+ raise ArgumentError, "unknown command"
25
+ end
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'json'
3
+ require 'set'
3
4
 
4
5
  module AutoStacker24
5
6
 
@@ -14,53 +15,26 @@ module AutoStacker24
14
15
  template
15
16
  end
16
17
 
17
- def self.preprocess_tags(template, tags = nil)
18
+ SUPPORTED_TYPES = Set[%w(AWS::AutoScaling::AutoScalingGroup AWS::CloudTrail::Trail AWS::EC2::CustomerGateway AWS::EC2::DHCPOptions AWS::EC2::Instance AWS::EC2::InternetGateway AWS::EC2::NetworkAcl AWS::EC2::NetworkInterface AWS::EC2::RouteTable AWS::EC2::SecurityGroup AWS::EC2::Subnet AWS::EC2::Volume AWS::EC2::VPC AWS::EC2::VPCPeeringConnection AWS::EC2::VPNConnection AWS::EC2::VPNGateway AWS::ElasticBeanstalk::Environment AWS::ElasticLoadBalancing::LoadBalancer AWS::RDS::DBCluster AWS::RDS::DBClusterParameterGroup AWS::RDS::DBInstance AWS::RDS::DBParameterGroup AWS::RDS::DBSecurityGroup AWS::RDS::DBSubnetGroup AWS::RDS::OptionGroup AWS::S3::Bucket)]
18
19
 
19
- supportedTypes = [
20
- 'AWS::AutoScaling::AutoScalingGroup',
21
- 'AWS::CloudTrail::Trail',
22
- 'AWS::EC2::CustomerGateway',
23
- 'AWS::EC2::DHCPOptions',
24
- 'AWS::EC2::Instance',
25
- 'AWS::EC2::InternetGateway',
26
- 'AWS::EC2::NetworkAcl',
27
- 'AWS::EC2::NetworkInterface',
28
- 'AWS::EC2::RouteTable',
29
- 'AWS::EC2::SecurityGroup',
30
- 'AWS::EC2::Subnet',
31
- 'AWS::EC2::Volume',
32
- 'AWS::EC2::VPC',
33
- 'AWS::EC2::VPCPeeringConnection',
34
- 'AWS::EC2::VPNConnection',
35
- 'AWS::EC2::VPNGateway',
36
- 'AWS::ElasticBeanstalk::Environment',
37
- 'AWS::ElasticLoadBalancing::LoadBalancer',
38
- 'AWS::RDS::DBCluster',
39
- 'AWS::RDS::DBClusterParameterGroup',
40
- 'AWS::RDS::DBInstance',
41
- 'AWS::RDS::DBParameterGroup',
42
- 'AWS::RDS::DBSecurityGroup',
43
- 'AWS::RDS::DBSubnetGroup',
44
- 'AWS::RDS::OptionGroup',
45
- 'AWS::S3::Bucket'
46
- ]
20
+ def self.preprocess_tags(template, tags = nil)
47
21
 
48
22
  unless tags.nil?
49
23
 
50
24
  tags_for_asg = adjust_tags_for_asg(tags)
51
25
 
52
- template["Resources"].each {|(key, value)|
26
+ template['Resources'].each {|(key, value)|
53
27
 
54
28
  tags_to_apply = tags
55
- if value["Type"] == 'AWS::AutoScaling::AutoScalingGroup'
29
+ if value['Type'] == 'AWS::AutoScaling::AutoScalingGroup'
56
30
  tags_to_apply = tags_for_asg
57
31
  end
58
32
 
59
- if supportedTypes.include? value["Type"]
60
- if value["Properties"]["Tags"].nil?
61
- value["Properties"]["Tags"] = tags_to_apply
33
+ if SUPPORTED_TYPES.include? value['Type']
34
+ if value['Properties']['Tags'].nil?
35
+ value['Properties']['Tags'] = tags_to_apply
62
36
  else
63
- value["Properties"]["Tags"] = (tags_to_apply + value["Properties"]["Tags"]).uniq { |s| s.first }
37
+ value['Properties']['Tags'] = (tags_to_apply + value['Properties']['Tags']).uniq { |s| s.first }
64
38
  end
65
39
  end
66
40
  }
@@ -70,18 +44,18 @@ module AutoStacker24
70
44
  end
71
45
 
72
46
  def self.adjust_tags_for_asg(tags)
73
- asg_tags = tags.inject([]) { |t,element| t << element.dup }
74
-
75
- asg_tags.each {|(tag)|
76
- tag["PropagateAtLaunch"] = "true"
77
- }
78
-
79
- asg_tags
47
+ tags.map {|element| element.merge('PropagateAtLaunch' => 'true') }
80
48
  end
81
49
 
82
50
  def self.preprocess_json(json)
83
51
  if json.is_a?(Hash)
84
- json.inject({}){|m, (k, v)| m.merge(k => preprocess_json(v))}
52
+ json.inject({}) do |m, (k, v)|
53
+ if k == 'UserData' && v.is_a?(String)
54
+ m.merge(k => preprocess_user_data(v))
55
+ else
56
+ m.merge(k => preprocess_json(v))
57
+ end
58
+ end
85
59
  elsif json.is_a?(Array)
86
60
  json.map{|v| preprocess_json(v)}
87
61
  elsif json.is_a?(String)
@@ -91,6 +65,12 @@ module AutoStacker24
91
65
  end
92
66
  end
93
67
 
68
+ def self.preprocess_user_data(s)
69
+ m = /^@file:\/\/(.*)/.match(s)
70
+ s = File.read(m[1]) if m
71
+ {'Fn::Base64' => s}
72
+ end
73
+
94
74
  def self.preprocess_string(s)
95
75
  parts = tokenize(s).map do |token|
96
76
  case token
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autostacker24
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.57
4
+ version: 1.0.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Mueller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-01 00:00:00.000000000 Z
12
+ date: 2016-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-core
@@ -43,10 +43,12 @@ description: n/a
43
43
  email:
44
44
  - jmueller@autoscout24.com
45
45
  - crodemeyer@autoscout24.com
46
- executables: []
46
+ executables:
47
+ - autostacker24
47
48
  extensions: []
48
49
  extra_rdoc_files: []
49
50
  files:
51
+ - bin/autostacker24
50
52
  - lib/autostacker24.rb
51
53
  - lib/autostacker24/stacker.rb
52
54
  - lib/autostacker24/template_preprocessor.rb