cf_factory 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/examples/base_vpc.rb +40 -0
  2. data/examples/cloudinit_script_for_one_instance.rb +77 -0
  3. data/examples/cloudinit_script_with_autoscaling.rb +85 -0
  4. data/examples/elb_with_cloudfront.rb +101 -0
  5. data/examples/instance_with_eip.rb +38 -0
  6. data/examples/instance_with_yum.rb +38 -0
  7. data/examples/just_an_instance.rb +29 -0
  8. data/examples/play_with_region_and_zones.rb +26 -0
  9. data/examples/ra_web_hosting.rb +146 -0
  10. data/examples/s3_with_cloudfront.rb +36 -0
  11. data/examples/test_vpc.rb +53 -0
  12. data/lib/cf_factory/as/cf_as_group.rb +75 -0
  13. data/lib/cf_factory/as/cf_as_launch_config.rb +53 -0
  14. data/lib/cf_factory/as/cf_as_scaling_policy.rb +33 -0
  15. data/lib/cf_factory/base/cf_base.rb +97 -0
  16. data/lib/cf_factory/base/cf_ec2_tag.rb +32 -0
  17. data/lib/cf_factory/base/cf_generator.rb +18 -0
  18. data/lib/cf_factory/base/cf_helper.rb +91 -0
  19. data/lib/cf_factory/base/cf_inner.rb +55 -0
  20. data/lib/cf_factory/base/cf_main.rb +101 -0
  21. data/lib/cf_factory/base/cf_mapping.rb +26 -0
  22. data/lib/cf_factory/base/cf_named_inner.rb +0 -0
  23. data/lib/cf_factory/base/cf_output.rb +24 -0
  24. data/lib/cf_factory/base/cf_parameter.rb +25 -0
  25. data/lib/cf_factory/base/cf_script_reader.rb +32 -0
  26. data/lib/cf_factory/cloudformation/cf_cloud_formation_init.rb +25 -0
  27. data/lib/cf_factory/cloudformation/cf_cloudformation_command.rb +37 -0
  28. data/lib/cf_factory/cloudformation/cf_cloudformation_commands.rb +25 -0
  29. data/lib/cf_factory/cloudformation/cf_cloudformation_config.rb +33 -0
  30. data/lib/cf_factory/cloudformation/cf_cloudformation_file.rb +38 -0
  31. data/lib/cf_factory/cloudformation/cf_cloudformation_files.rb +25 -0
  32. data/lib/cf_factory/cloudformation/cf_cloudformation_inner.rb +28 -0
  33. data/lib/cf_factory/cloudformation/cf_cloudformation_package.rb +34 -0
  34. data/lib/cf_factory/cloudformation/cf_cloudformation_packages.rb +42 -0
  35. data/lib/cf_factory/cloudformation/cf_cloudformation_sources.rb +30 -0
  36. data/lib/cf_factory/cloudformation/cf_init_script.rb +73 -0
  37. data/lib/cf_factory/cloudfront/cf_cache_behavior.rb +37 -0
  38. data/lib/cf_factory/cloudfront/cf_cache_behaviors.rb +28 -0
  39. data/lib/cf_factory/cloudfront/cf_cloudfront_distribution.rb +64 -0
  40. data/lib/cf_factory/cloudfront/cf_custom_origin_config.rb +37 -0
  41. data/lib/cf_factory/cloudfront/cf_default_cache_behavior.rb +32 -0
  42. data/lib/cf_factory/cloudfront/cf_distribution_config.rb +31 -0
  43. data/lib/cf_factory/cloudfront/cf_forwarded_values.rb +25 -0
  44. data/lib/cf_factory/cloudfront/cf_logging.rb +24 -0
  45. data/lib/cf_factory/cloudfront/cf_origin.rb +40 -0
  46. data/lib/cf_factory/cloudfront/cf_s3_origin_config.rb +25 -0
  47. data/lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb +58 -0
  48. data/lib/cf_factory/ec2/cf_ebs_volume.rb +54 -0
  49. data/lib/cf_factory/ec2/cf_ec2_instance.rb +62 -0
  50. data/lib/cf_factory/ec2/cf_ec2_security_group.rb +40 -0
  51. data/lib/cf_factory/ec2/cf_ec2_security_group_egress.rb +28 -0
  52. data/lib/cf_factory/ec2/cf_ec2_security_group_ingress.rb +39 -0
  53. data/lib/cf_factory/ec2/cf_eip.rb +26 -0
  54. data/lib/cf_factory/ec2/cf_eip_association.rb +29 -0
  55. data/lib/cf_factory/elb/cf_app_cookie_stickiness_policy.rb +15 -0
  56. data/lib/cf_factory/elb/cf_elb.rb +49 -0
  57. data/lib/cf_factory/elb/cf_health_check.rb +23 -0
  58. data/lib/cf_factory/elb/cf_lb_cookie_stickiness_policy.rb +15 -0
  59. data/lib/cf_factory/elb/cf_listener.rb +26 -0
  60. data/lib/cf_factory/help/fixes.rb +14 -0
  61. data/lib/cf_factory/help/ip_mask.rb +165 -0
  62. data/lib/cf_factory/help/template_validation.rb +28 -0
  63. data/lib/cf_factory/iam/cf_iam_access_key.rb +32 -0
  64. data/lib/cf_factory/iam/cf_iam_group.rb +30 -0
  65. data/lib/cf_factory/iam/cf_iam_instance_profile.rb +30 -0
  66. data/lib/cf_factory/iam/cf_iam_policy.rb +18 -0
  67. data/lib/cf_factory/iam/cf_iam_role.rb +56 -0
  68. data/lib/cf_factory/iam/cf_iam_statement.rb +23 -0
  69. data/lib/cf_factory/iam/cf_iam_user.rb +34 -0
  70. data/lib/cf_factory/iam/cf_policy_document.rb +19 -0
  71. data/lib/cf_factory/modules/base_vpc.rb +61 -0
  72. data/lib/cf_factory/rds/cf_rds_instance.rb +53 -0
  73. data/lib/cf_factory/rds/cf_rds_security_group.rb +33 -0
  74. data/lib/cf_factory/rds/cf_rds_security_group_ingress.rb +29 -0
  75. data/lib/cf_factory/rds/cf_rds_subnet_group.rb +29 -0
  76. data/lib/cf_factory/route53/cf_elb_alias_target.rb +21 -0
  77. data/lib/cf_factory/route53/cf_record_set.rb +61 -0
  78. data/lib/cf_factory/route53/cf_route53_record_set.rb +61 -0
  79. data/lib/cf_factory/route53/cf_route53_record_set_group.rb +42 -0
  80. data/lib/cf_factory/s3/cf_s3_bucket.rb +32 -0
  81. data/lib/cf_factory/s3/cf_web_site_config.rb +24 -0
  82. data/lib/cf_factory/sqs/cf_sqs_queue.rb +26 -0
  83. data/lib/cf_factory/vpc/cf_attach_gateway.rb +28 -0
  84. data/lib/cf_factory/vpc/cf_internet_gateway.rb +30 -0
  85. data/lib/cf_factory/vpc/cf_network_acl.rb +39 -0
  86. data/lib/cf_factory/vpc/cf_network_acl_association.rb +24 -0
  87. data/lib/cf_factory/vpc/cf_network_acl_entry.rb +37 -0
  88. data/lib/cf_factory/vpc/cf_route.rb +43 -0
  89. data/lib/cf_factory/vpc/cf_route_table.rb +41 -0
  90. data/lib/cf_factory/vpc/cf_route_table_association.rb +24 -0
  91. data/lib/cf_factory/vpc/cf_subnet.rb +48 -0
  92. data/lib/cf_factory/vpc/cf_vpc.rb +64 -0
  93. data/lib/cf_factory.rb +103 -0
  94. metadata +140 -0
@@ -0,0 +1,32 @@
1
+ # Reads a file, integrates the specified arguments, and generates indented output taken specified parameters into account
2
+ class CfScriptReader
3
+ def initialize(file_to_read, indentation = 0)
4
+ @file = file_to_read
5
+ @indent = indentation
6
+ end
7
+
8
+ def apply_arguments(*arguments)
9
+ @arguments = arguments
10
+ puts @arguments.inspect
11
+ end
12
+
13
+ def generate()
14
+ contents = File.open(@file, "r") {|f| f.read}
15
+ count = 1
16
+ @arguments.each() {|arg|
17
+ pattern = /<\$#{count}>/
18
+ puts "pattern = #{pattern.inspect}"
19
+ contents.gsub!(pattern, arg)
20
+ count += 1
21
+ }
22
+ result = ""
23
+ contents.each_line do |line|
24
+ result += "#{' '*@indent}#{line}"
25
+ end
26
+ result
27
+ end
28
+
29
+ private
30
+
31
+
32
+ end
@@ -0,0 +1,25 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+
4
+ class CfCloudFormationInit
5
+ include CfInner
6
+
7
+ #config: key value pair of config-sets
8
+ def initialize(configs)
9
+ @configs = configs
10
+ @name = "AWS::CloudFormation::Init"
11
+ end
12
+
13
+ def get_cf_attributes
14
+ result = {}
15
+ @configs.each() {|c|
16
+ result[c.get_name] = c.generate
17
+ }
18
+ result
19
+ end
20
+
21
+ def generate
22
+ generate_name
23
+ end
24
+
25
+ end
@@ -0,0 +1,37 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+ require 'cf_factory/base/cf_helper'
4
+
5
+ class CfCloudFormationCommand
6
+ include CfInner
7
+
8
+ def get_name
9
+ @name
10
+ end
11
+
12
+ def initialize(name, command, options = {})
13
+ @name = name
14
+ @command = command
15
+ #
16
+ @env = options[:env]
17
+ @cwd = options[:cwd]
18
+ @test = options[:test]
19
+ @ignore_errors = options[:ignore_errors]
20
+ @additional_indent = 6
21
+ end
22
+
23
+ def additional_indent
24
+ @additional_indent += 2
25
+ end
26
+
27
+ def get_cf_attributes
28
+ result = {}
29
+ result['command'] = @command
30
+ result['env'] = @env unless @env.nil?
31
+ result['cwd'] = @cwd unless @cwd.nil?
32
+ result['test'] = @test unless @test.nil?
33
+ result['ignoreErrors'] = @ignore_errors unless @ignore_errors.nil?
34
+ result
35
+ end
36
+
37
+ end
@@ -0,0 +1,25 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+ require 'cf_factory/base/cf_helper'
4
+
5
+ class CfCloudFormationCommands
6
+ include CfInner
7
+
8
+ def initialize(commands)
9
+ @commands = commands
10
+ @additional_indent = 4
11
+ end
12
+
13
+ def additional_indent
14
+ @additional_indent += 2
15
+ end
16
+
17
+ def get_cf_attributes
18
+ result = {}
19
+ @commands.each() {|command|
20
+ result[command.get_name] = command.generate
21
+ }
22
+ result
23
+ end
24
+
25
+ end
@@ -0,0 +1,33 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+ require 'cf_factory/base/cf_helper'
4
+
5
+ class CfCloudFormationConfig
6
+ include CfInner
7
+
8
+ def get_name
9
+ @name
10
+ end
11
+
12
+ def initialize(name, sources, commands, files, packages)
13
+ @name = name
14
+ @sources = sources
15
+ @commands = commands
16
+ @files = files
17
+ @packages = packages
18
+ end
19
+
20
+ def additional_indent
21
+ 4
22
+ end
23
+
24
+ def get_cf_attributes
25
+ result = {}
26
+ result["sources"] = CfHelper.clean(@sources.generate) unless @sources.nil?
27
+ result["commands"] = @commands.generate unless @commands.nil?
28
+ result["files"] = @files.generate unless @files.nil?
29
+ result["packages"] = @packages.generate unless @packages.nil?
30
+ result
31
+ end
32
+
33
+ end
@@ -0,0 +1,38 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+ require 'cf_factory/base/cf_helper'
4
+
5
+ class CfCloudFormationFile
6
+ include CfInner
7
+
8
+ def get_name
9
+ @name
10
+ end
11
+
12
+ def initialize(name, content, group, owner, mode, options = {})
13
+ @name = name
14
+ @content = content
15
+ @group = group
16
+ @owner = owner
17
+ @mode = mode
18
+ @source = options[:source]
19
+ #
20
+ @additional_indent = 6
21
+ #TODO: authentication + encoding missing
22
+ end
23
+
24
+ def additional_indent
25
+ @additional_indent += 2
26
+ end
27
+
28
+ def get_cf_attributes
29
+ result = {}
30
+ result["content"] = @content
31
+ result["group"] = @group
32
+ result["owner"] = @owner
33
+ result["mode"] = @mode
34
+ result["source"] = @source unless @source.nil?
35
+ result
36
+ end
37
+
38
+ end
@@ -0,0 +1,25 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+ require 'cf_factory/base/cf_helper'
4
+
5
+ class CfCloudFormationFiles
6
+ include CfInner
7
+
8
+ def initialize(files)
9
+ @files = files
10
+ @additional_indent = 4
11
+ end
12
+
13
+ def additional_indent
14
+ @additional_indent += 2
15
+ end
16
+
17
+ def get_cf_attributes
18
+ result = {}
19
+ @files.each() {|file|
20
+ result[file.get_name] = file.generate
21
+ }
22
+ result
23
+ end
24
+
25
+ end
@@ -0,0 +1,28 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+
4
+ class CfCloudFormationInner
5
+ include CfInner
6
+
7
+ def initialize(key_value_list, indent)
8
+ @key_value_list = key_value_list
9
+ @additional_indent = indent
10
+ end
11
+
12
+ def additional_indent
13
+ @additional_indent
14
+ end
15
+
16
+ def get_cf_attributes
17
+ result = {}
18
+ puts "key_value_list = #{@key_value_list}"
19
+ @key_value_list.each() {|key_value_pair|
20
+ key = key_value_pair.keys.first
21
+ value = key_value_pair[key]
22
+ puts "key_value_pair = #{key_value_pair} key = #{key} value = #{value}"
23
+ result[key] = value
24
+ }
25
+ result
26
+ end
27
+
28
+ end
@@ -0,0 +1,34 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+ require 'cf_factory/base/cf_helper'
4
+
5
+ class CfCloudFormationPackage
6
+ include CfInner
7
+
8
+ def get_package_type
9
+ @package_type
10
+ end
11
+
12
+ def initialize(package_type, package_name, versions, options = {})
13
+ @package_type = package_type
14
+ @package_name = package_name
15
+ @versions = versions
16
+ #
17
+ @additional_indent = 6
18
+ #TODO: authentication + encoding missing
19
+ end
20
+
21
+ def additional_indent
22
+ @additional_indent += 12
23
+ end
24
+
25
+ def get_cf_attributes
26
+ result = {}
27
+ result["#{@package_name}"] = @versions.inspect
28
+ result
29
+ end
30
+
31
+ def generate
32
+ CfGenerator.indent(self.additional_indent, "\"#{@package_name}\" : #{@versions.inspect}")
33
+ end
34
+ end
@@ -0,0 +1,42 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+ require 'cf_factory/base/cf_helper'
4
+
5
+ class CfCloudFormationPackages
6
+ include CfInner
7
+
8
+ def initialize(package_definitions)
9
+ @package_definitions = package_definitions
10
+ #
11
+ @additional_indent = 6
12
+ end
13
+
14
+ def additional_indent
15
+ @additional_indent
16
+ end
17
+
18
+ def get_cf_attributes
19
+ result = {}
20
+ sort_packages_by_type()
21
+ @packages_by_type.keys.each() {|package_type|
22
+ result["#{package_type}"] = "{\n#{CfHelper.generate_inner_list(@packages_by_type[package_type])}\n#{" "*(@additional_indent+10)}}"
23
+ }
24
+ result
25
+ end
26
+
27
+ private
28
+
29
+ def sort_packages_by_type
30
+ @packages_by_type = {}
31
+ @package_definitions.each() {|package_definition|
32
+ packages_of_type = @packages_by_type[package_definition.get_package_type]
33
+ if packages_of_type.nil?
34
+ packages_of_type = []
35
+ @packages_by_type[package_definition.get_package_type] = packages_of_type
36
+ end
37
+ packages_of_type << package_definition
38
+ }
39
+ @packages_by_type
40
+ end
41
+
42
+ end
@@ -0,0 +1,30 @@
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_inner'
3
+
4
+ class CfCloudFormationSources
5
+ include CfInner
6
+
7
+ def initialize(source_list, additional_indent = 6)
8
+ @source_list = source_list
9
+ @additional_indent = additional_indent
10
+ end
11
+
12
+ def additional_indent
13
+ 6
14
+ end
15
+
16
+ def add_additional_indent
17
+ @additional_indent += 2
18
+ end
19
+
20
+ def get_cf_attributes
21
+ result = {}
22
+ @source_list.each() {|key_value|
23
+ key = key_value.keys.first
24
+ value = key_value[key]
25
+ result[key] = value
26
+ }
27
+ result
28
+ end
29
+
30
+ end
@@ -0,0 +1,73 @@
1
+ class CfInitScript
2
+ # Every parameter-string will be transformed into something like { "Ref" : "<parameter>" }
3
+ def initialize(script, parameter_array)
4
+ @script = script
5
+ @parameter_array = parameter_array
6
+ prepare
7
+ end
8
+
9
+ def user_data
10
+ @user_data
11
+ end
12
+
13
+ def self.create_basic(resource_id, access_key, secret_key)
14
+ stack = CfHelper.generate_ref("AWS::StackName")
15
+ CfInitScript.new(basic_script(), [stack, resource_id, access_key, secret_key])
16
+ end
17
+
18
+ private
19
+
20
+ def validate
21
+ if @script.occurences_of("<!par!") != @parameter_array.size
22
+ raise Exception.new("the number of parameters does not correspond to the number of placeholders in the script")
23
+ end
24
+ end
25
+
26
+ # Looks for all occurences of <!#par#!> in the script and builds a string that is base64-encoded and joined
27
+ # and where all those occurences are replaced with the parameter name specified in the constructor.
28
+ def prepare
29
+ #divide along parameters
30
+ #@script.strip!()
31
+ divided_script = @script.split("<!par!>")
32
+ script_with_params = []
33
+ count = 0
34
+ divided_script.each() {|part|
35
+ #puts "part [#{count}] = #{part}"
36
+ part.split("\n").each() {|line|
37
+ next if line.strip.size == 0
38
+ script_with_params << "#{line.lstrip} " #TODO: make this work with the line-breaks
39
+ script_with_params << "\n"
40
+ }
41
+ script_with_params.delete_at(script_with_params.size()-1)
42
+ script_with_params << @parameter_array[count]
43
+ count += 1
44
+ }
45
+
46
+ join = CfHelper.join(script_with_params)
47
+
48
+ @user_data = join
49
+ end
50
+
51
+ def self.basic_script
52
+ init_script = "
53
+ #!/bin/bash -v
54
+ /opt/aws/bin/cfn-init -s <!par!> -r <!par!>
55
+ --access-key <!par!>
56
+ --secret-key <!par!>
57
+ || error_exit 'Failed to run cfn-init'
58
+ "
59
+ end
60
+
61
+ def self.basic_script_with_update
62
+ init_script = "
63
+ #!/bin/bash -v
64
+ yum update -y aws-cfn-bootstrap
65
+ # Run cfn-init for config
66
+ /opt/aws/bin/cfn-init -s <!par!> -r <!par!>
67
+ --access-key <!par!>
68
+ --secret-key <!par!>
69
+ || error_exit 'Failed to run cfn-init'
70
+ "
71
+ end
72
+
73
+ end
@@ -0,0 +1,37 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ class CfCacheBehavior
4
+ include CfInner
5
+
6
+ attr_reader(:id)
7
+
8
+ def additional_indent
9
+ 6
10
+ end
11
+
12
+ def self.create_basic(target_origin_id, path_pattern, options = {})
13
+ CfCacheBehavior.new(target_origin_id, CfForwardedValues.new(true), "allow-all", path_pattern, options)
14
+ end
15
+
16
+ def initialize(target_origin_id, forwarded_values, viewer_protocol_policy, path_pattern, options)
17
+ @target_origin_id = target_origin_id
18
+ @forwarded_values = forwarded_values
19
+ @forwarded_values.add(2)
20
+ @view_protocol_policy = viewer_protocol_policy
21
+ @path_pattern = path_pattern
22
+ @min_ttl = options[:min_ttl]
23
+ @trusted_signers = options[:trusted_signers]
24
+ end
25
+
26
+ def get_cf_attributes
27
+ result = {}
28
+ result["TargetOriginId"] = @target_origin_id
29
+ result["ForwardedValues"] = @forwarded_values.generate
30
+ result["ViewerProtocolPolicy"] = @view_protocol_policy
31
+ result["PathPattern"] = @path_pattern
32
+ result["MinTTL"] = @min_ttl unless @min_ttl.nil?
33
+ result["TrustedSigners"] = @trusted_signers unless @trusted_signers.nil?
34
+ result
35
+ end
36
+
37
+ end
@@ -0,0 +1,28 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ class CfDefaultCacheBehaviors
4
+ include CfInner
5
+
6
+ def additional_indent
7
+ 4
8
+ end
9
+
10
+ def initialize(target_origin_id, forwarded_values, viewer_protocol_policy, options = {})
11
+ @target_origin_id = target_origin_id
12
+ @forwarded_values = forwarded_values
13
+ @viewer_protocol_policy = viewer_protocol_policy
14
+
15
+ @min_ttl = options[:min_ttl]
16
+ @trusted_signers = options[:trusted_signers]
17
+ end
18
+
19
+ def get_cf_attributes
20
+ result = {}
21
+ result["TargetOriginId"] = @target_origin_id
22
+ result["ForwardedValues"] = @forwarded_values.generate
23
+ result["ViewerProtocolPolicy"] = @viewer_protocol_policy
24
+ result["MinTTL"] = @min_ttl unless @min_ttl.nil?
25
+ result
26
+ end
27
+
28
+ end
@@ -0,0 +1,64 @@
1
+ require 'cf_factory/base/cf_base'
2
+
3
+ class CfCloudfrontDistribution
4
+ include CfBase
5
+
6
+ def initialize(name, distribution_details)
7
+ @name = name
8
+ @distribution = distribution_details
9
+ end
10
+
11
+ def set_tags(tag_list)
12
+ @tag_list = tag_list
13
+ end
14
+
15
+ def self.create_s3_distribution(name, s3_bucket, origin_options = {}, cache_behaviour_options = {}, distribution_options = {})
16
+ s3_origin = CfS3OriginConfig.new
17
+ origin_config = CfOrigin.new(s3_bucket.short_domain_name(),s3_bucket.generate_ref,s3_origin, origin_options)
18
+ default_cache_behavior = CfDefaultCacheBehavior.new(origin_config.id,CfForwardedValues.new(true),"allow-all", cache_behaviour_options)
19
+ distribution_details = CfDistributionConfig.new([origin_config],default_cache_behavior, true, distribution_options)
20
+ CfCloudfrontDistribution.new(name, distribution_details)
21
+ end
22
+
23
+ def self.create_elb_distribution(name, elb, origin_options = {}, cache_behaviour_options = {}, distribution_options = {})
24
+ custom_origin = CfCustomOriginConfig.new("http-only")
25
+ origin_config = CfOrigin.new(elb.retrieve_attribute("DNSName"),elb.generate_ref,custom_origin,origin_options)
26
+ default_cache_behavior = CfDefaultCacheBehavior.new(origin_config.id,CfForwardedValues.new(true),"allow-all", cache_behaviour_options)
27
+ distribution_details = CfDistributionConfig.new([origin_config],default_cache_behavior, true, distribution_options)
28
+ CfCloudfrontDistribution.new(name, distribution_details)
29
+ end
30
+
31
+ def self.create_domain_distribution(name, origin_domain, origin_id, origin_options = {}, cache_behaviour_options = {}, distribution_options = {})
32
+ custom_origin = CfCustomOriginConfig.new("http-only")
33
+ origin_config = CfOrigin.new(origin_domain,origin_id,custom_origin,origin_options)
34
+ default_cache_behavior = CfDefaultCacheBehavior.new(origin_config.id,CfForwardedValues.new(true),"allow-all", cache_behaviour_options)
35
+ distribution_details = CfDistributionConfig.new([origin_config],default_cache_behavior, true, distribution_options)
36
+ CfCloudfrontDistribution.new(name, distribution_details)
37
+ end
38
+
39
+ def self.create_multi_origin_distribution(name, origins, default_cache_behavior, cache_behaviors, distribution_options = {})
40
+ distribution_details = CfDistributionConfig.new(origins,default_cache_behavior, true, distribution_options.merge({:cache_behaviors => cache_behaviors}))
41
+ CfCloudfrontDistribution.new(name, distribution_details)
42
+ end
43
+
44
+ def self.create_multi_origin_distribution_old(name, origins, cache_behaviour_options = {}, distribution_options = {})
45
+ default_cache_behavior = CfDefaultCacheBehavior.new("XXX was origin_config.id",CfForwardedValues.new(true),"allow-all", cache_behaviour_options)
46
+ distribution_details = CfDistributionConfig.new(origins,default_cache_behavior, true, distribution_options)
47
+ CfCloudfrontDistribution.new(name, distribution_details)
48
+ end
49
+
50
+ def get_cf_type
51
+ "AWS::CloudFront::Distribution"
52
+ end
53
+
54
+ def get_cf_attributes
55
+ result = super
56
+ end
57
+
58
+ def get_cf_properties
59
+ result = {}
60
+ result["DistributionConfig"] = @distribution.generate
61
+ result
62
+ end
63
+
64
+ end
@@ -0,0 +1,37 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ class CfCustomOriginConfig
4
+ PROTOCOL_VALUES = ["http-only","match-viewer"]
5
+ include CfInner
6
+
7
+ def additional_indent
8
+ 6
9
+ end
10
+
11
+
12
+ def initialize(protocol, options = {})
13
+ @protocol = protocol
14
+ @http_port = options[:http_port]
15
+ @https_port = options[:https_port]
16
+ validate()
17
+ end
18
+
19
+ def get_cf_attributes
20
+ result = {}
21
+ result["OriginProtocolPolicy"] = @protocol
22
+ result["HTTPPort"] = @http_port unless @http_port.nil?
23
+ result["HTTPSPort"] = @https_port unless @https_port.nil?
24
+ result
25
+ end
26
+
27
+ def is_custom?
28
+ true
29
+ end
30
+
31
+ private
32
+
33
+ def validate
34
+ raise Exception.new("protocol must be within #{PROTOCOL_VALUES}") unless PROTOCOL_VALUES.include?(@protocol)
35
+ end
36
+
37
+ end
@@ -0,0 +1,32 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ class CfDefaultCacheBehavior
4
+ include CfInner
5
+
6
+ def additional_indent
7
+ 4
8
+ end
9
+
10
+ def self.create_basic(target_origin_id)
11
+ CfDefaultCacheBehavior.new(target_origin_id,CfForwardedValues.new(true),"allow-all")
12
+ end
13
+
14
+ def initialize(target_origin_id, forwarded_values, viewer_protocol_policy, options = {})
15
+ @target_origin_id = target_origin_id
16
+ @forwarded_values = forwarded_values
17
+ @viewer_protocol_policy = viewer_protocol_policy
18
+
19
+ @min_ttl = options[:min_ttl]
20
+ @trusted_signers = options[:trusted_signers]
21
+ end
22
+
23
+ def get_cf_attributes
24
+ result = {}
25
+ result["TargetOriginId"] = @target_origin_id
26
+ result["ForwardedValues"] = @forwarded_values.generate
27
+ result["ViewerProtocolPolicy"] = @viewer_protocol_policy
28
+ result["MinTTL"] = @min_ttl unless @min_ttl.nil?
29
+ result
30
+ end
31
+
32
+ end
@@ -0,0 +1,31 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ class CfDistributionConfig
4
+ include CfInner
5
+
6
+ def additional_indent
7
+ 2
8
+ end
9
+
10
+ def initialize(origins, default_cache_behaviour, enabled = true, options = {})
11
+ @origins = origins
12
+ @default_cache_behaviour = default_cache_behaviour
13
+ @enabled = enabled
14
+
15
+ @cache_behaviors = options[:cache_behaviors]
16
+ @aliases = options[:aliases]
17
+ @logging = options[:logging]
18
+ end
19
+
20
+ def get_cf_attributes
21
+ result = {}
22
+ result["Origins"] = CfHelper.generate_inner_array(@origins)
23
+ result["DefaultCacheBehavior"] = @default_cache_behaviour.generate
24
+ result["Enabled"] = @enabled
25
+ result["Logging"] = @logging.generate unless @logging.nil?
26
+ result["Aliases"] = @aliases.inspect unless @aliases.nil?
27
+ result["CacheBehaviors"] = CfHelper.generate_inner_array(@cache_behaviors)
28
+ result
29
+ end
30
+
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ class CfForwardedValues
4
+ include CfInner
5
+
6
+ def additional_indent
7
+ @additional_indent
8
+ end
9
+
10
+ def add(add_indent)
11
+ @additional_indent += add_indent
12
+ end
13
+
14
+ def initialize(query_string)
15
+ @query_string = query_string
16
+ @additional_indent = 6
17
+ end
18
+
19
+ def get_cf_attributes
20
+ result = {}
21
+ result["QueryString"] = @query_string
22
+ result
23
+ end
24
+
25
+ end