cf_factory 0.0.4 → 0.0.5
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.
- data/bin/cf_factory +9 -9
- data/examples/base_vpc.rb +40 -40
- data/examples/cloudfront_private.rb +23 -23
- data/examples/cloudinit_script_for_one_instance.rb +77 -77
- data/examples/cloudinit_script_with_autoscaling.rb +85 -85
- data/examples/dynamodb_table.rb +24 -24
- data/examples/elastic_beanstalk_example.rb +23 -23
- data/examples/elb_with_cloudfront.rb +100 -100
- data/examples/instance_with_eip.rb +40 -40
- data/examples/instance_with_yum.rb +40 -40
- data/examples/just_an_instance.rb +31 -31
- data/examples/nat_mutual_monitoring.rb +69 -69
- data/examples/play_with_region_and_zones.rb +28 -28
- data/examples/ra_web_hosting.rb +148 -148
- data/examples/s3_with_cloudfront.rb +35 -35
- data/examples/test_vpc.rb +61 -61
- data/lib/cf_factory/as/cf_as_group.rb +80 -77
- data/lib/cf_factory/as/cf_as_launch_config.rb +55 -55
- data/lib/cf_factory/as/cf_as_scaling_policy.rb +35 -35
- data/lib/cf_factory/as/cf_as_update_policy.rb +23 -0
- data/lib/cf_factory/base/cf_base.rb +112 -102
- data/lib/cf_factory/base/cf_ec2_tag.rb +34 -34
- data/lib/cf_factory/base/cf_generator.rb +20 -20
- data/lib/cf_factory/base/cf_helper.rb +93 -93
- data/lib/cf_factory/base/cf_inner.rb +74 -74
- data/lib/cf_factory/base/cf_main.rb +103 -103
- data/lib/cf_factory/base/cf_mapping.rb +28 -28
- data/lib/cf_factory/base/cf_named_inner.rb +70 -1
- data/lib/cf_factory/base/cf_output.rb +26 -26
- data/lib/cf_factory/base/cf_parameter.rb +27 -27
- data/lib/cf_factory/base/cf_script_reader.rb +34 -34
- data/lib/cf_factory/cloudformation/cf_cloud_formation_init.rb +27 -27
- data/lib/cf_factory/cloudformation/cf_cloudformation_command.rb +39 -39
- data/lib/cf_factory/cloudformation/cf_cloudformation_commands.rb +27 -27
- data/lib/cf_factory/cloudformation/cf_cloudformation_config.rb +35 -35
- data/lib/cf_factory/cloudformation/cf_cloudformation_file.rb +40 -40
- data/lib/cf_factory/cloudformation/cf_cloudformation_files.rb +27 -27
- data/lib/cf_factory/cloudformation/cf_cloudformation_inner.rb +30 -30
- data/lib/cf_factory/cloudformation/cf_cloudformation_package.rb +36 -36
- data/lib/cf_factory/cloudformation/cf_cloudformation_packages.rb +44 -44
- data/lib/cf_factory/cloudformation/cf_cloudformation_sources.rb +32 -32
- data/lib/cf_factory/cloudformation/cf_init_script.rb +80 -80
- data/lib/cf_factory/cloudfront/cf_cache_behavior.rb +39 -39
- data/lib/cf_factory/cloudfront/cf_cache_behaviors.rb +30 -30
- data/lib/cf_factory/cloudfront/cf_cloudfront_distribution.rb +66 -66
- data/lib/cf_factory/cloudfront/cf_custom_origin_config.rb +39 -39
- data/lib/cf_factory/cloudfront/cf_default_cache_behavior.rb +34 -34
- data/lib/cf_factory/cloudfront/cf_distribution_config.rb +33 -33
- data/lib/cf_factory/cloudfront/cf_forwarded_values.rb +27 -27
- data/lib/cf_factory/cloudfront/cf_logging.rb +26 -26
- data/lib/cf_factory/cloudfront/cf_origin.rb +42 -42
- data/lib/cf_factory/cloudfront/cf_s3_origin_config.rb +27 -27
- data/lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb +60 -60
- data/lib/cf_factory/dynamo/cf_dynamo_table.rb +45 -45
- data/lib/cf_factory/eb/cd_eb_solution_stack.rb +27 -28
- data/lib/cf_factory/eb/cf_eb_application.rb +41 -41
- data/lib/cf_factory/eb/cf_eb_application_version.rb +24 -24
- data/lib/cf_factory/eb/cf_eb_configuration_template.rb +36 -36
- data/lib/cf_factory/eb/cf_eb_environment.rb +56 -56
- data/lib/cf_factory/eb/cf_eb_option_setting.rb +19 -19
- data/lib/cf_factory/ec2/cf_ebs_volume.rb +56 -56
- data/lib/cf_factory/ec2/cf_ec2_instance.rb +80 -66
- data/lib/cf_factory/ec2/cf_ec2_security_group.rb +42 -42
- data/lib/cf_factory/ec2/cf_ec2_security_group_egress.rb +30 -30
- data/lib/cf_factory/ec2/cf_ec2_security_group_ingress.rb +41 -41
- data/lib/cf_factory/ec2/cf_eip.rb +28 -28
- data/lib/cf_factory/ec2/cf_eip_association.rb +33 -31
- data/lib/cf_factory/ec2/cf_inner_network_interface.rb +26 -0
- data/lib/cf_factory/ec2/cf_network_interface.rb +40 -0
- data/lib/cf_factory/elb/cf_app_cookie_stickiness_policy.rb +17 -17
- data/lib/cf_factory/elb/cf_elb.rb +51 -51
- data/lib/cf_factory/elb/cf_health_check.rb +25 -25
- data/lib/cf_factory/elb/cf_lb_cookie_stickiness_policy.rb +17 -17
- data/lib/cf_factory/elb/cf_listener.rb +28 -28
- data/lib/cf_factory/help/fixes.rb +15 -15
- data/lib/cf_factory/help/ip_mask.rb +167 -167
- data/lib/cf_factory/help/template_validation.rb +30 -30
- data/lib/cf_factory/iam/cf_iam_access_key.rb +34 -34
- data/lib/cf_factory/iam/cf_iam_group.rb +32 -32
- data/lib/cf_factory/iam/cf_iam_instance_profile.rb +32 -32
- data/lib/cf_factory/iam/cf_iam_policy.rb +20 -20
- data/lib/cf_factory/iam/cf_iam_role.rb +58 -58
- data/lib/cf_factory/iam/cf_iam_statement.rb +25 -25
- data/lib/cf_factory/iam/cf_iam_user.rb +36 -36
- data/lib/cf_factory/iam/cf_policy_document.rb +21 -21
- data/lib/cf_factory/modules/base_vpc.rb +63 -63
- data/lib/cf_factory/rds/cf_rds_instance.rb +55 -55
- data/lib/cf_factory/rds/cf_rds_security_group.rb +35 -35
- data/lib/cf_factory/rds/cf_rds_security_group_ingress.rb +31 -31
- data/lib/cf_factory/rds/cf_rds_subnet_group.rb +31 -31
- data/lib/cf_factory/route53/cf_elb_alias_target.rb +23 -23
- data/lib/cf_factory/route53/cf_record_set.rb +63 -63
- data/lib/cf_factory/route53/cf_route53_record_set.rb +63 -63
- data/lib/cf_factory/route53/cf_route53_record_set_group.rb +44 -44
- data/lib/cf_factory/s3/cf_s3_bucket.rb +34 -34
- data/lib/cf_factory/s3/cf_web_site_config.rb +26 -26
- data/lib/cf_factory/sqs/cf_sqs_queue.rb +28 -28
- data/lib/cf_factory/vpc/cf_attach_gateway.rb +30 -30
- data/lib/cf_factory/vpc/cf_internet_gateway.rb +32 -32
- data/lib/cf_factory/vpc/cf_network_acl.rb +41 -41
- data/lib/cf_factory/vpc/cf_network_acl_association.rb +26 -26
- data/lib/cf_factory/vpc/cf_network_acl_entry.rb +39 -39
- data/lib/cf_factory/vpc/cf_route.rb +45 -45
- data/lib/cf_factory/vpc/cf_route_table.rb +43 -43
- data/lib/cf_factory/vpc/cf_route_table_association.rb +26 -26
- data/lib/cf_factory/vpc/cf_subnet.rb +50 -50
- data/lib/cf_factory/vpc/cf_vpc.rb +66 -66
- data/lib/cf_factory.rb +12 -12
- metadata +120 -91
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
require 'cf_factory/base/cf_base'
|
|
2
|
-
require 'cf_factory/base/cf_inner'
|
|
3
|
-
|
|
4
|
-
module CfFactory
|
|
5
|
-
class CfCloudFormationInner
|
|
6
|
-
include CfInner
|
|
7
|
-
|
|
8
|
-
def initialize(key_value_list, indent)
|
|
9
|
-
@key_value_list = key_value_list
|
|
10
|
-
@additional_indent = indent
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def additional_indent
|
|
14
|
-
@additional_indent
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def get_cf_attributes
|
|
18
|
-
result = {}
|
|
19
|
-
puts "key_value_list = #{@key_value_list}"
|
|
20
|
-
@key_value_list.each() {|key_value_pair|
|
|
21
|
-
key = key_value_pair.keys.first
|
|
22
|
-
value = key_value_pair[key]
|
|
23
|
-
puts "key_value_pair = #{key_value_pair} key = #{key} value = #{value}"
|
|
24
|
-
result[key] = value
|
|
25
|
-
}
|
|
26
|
-
result
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
end
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
require 'cf_factory/base/cf_inner'
|
|
3
|
+
|
|
4
|
+
module CfFactory
|
|
5
|
+
class CfCloudFormationInner
|
|
6
|
+
include CfInner
|
|
7
|
+
|
|
8
|
+
def initialize(key_value_list, indent)
|
|
9
|
+
@key_value_list = key_value_list
|
|
10
|
+
@additional_indent = indent
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def additional_indent
|
|
14
|
+
@additional_indent
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_cf_attributes
|
|
18
|
+
result = {}
|
|
19
|
+
puts "key_value_list = #{@key_value_list}"
|
|
20
|
+
@key_value_list.each() {|key_value_pair|
|
|
21
|
+
key = key_value_pair.keys.first
|
|
22
|
+
value = key_value_pair[key]
|
|
23
|
+
puts "key_value_pair = #{key_value_pair} key = #{key} value = #{value}"
|
|
24
|
+
result[key] = value
|
|
25
|
+
}
|
|
26
|
+
result
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
require 'cf_factory/base/cf_base'
|
|
2
|
-
require 'cf_factory/base/cf_inner'
|
|
3
|
-
require 'cf_factory/base/cf_helper'
|
|
4
|
-
|
|
5
|
-
module CfFactory
|
|
6
|
-
class CfCloudFormationPackage
|
|
7
|
-
include CfInner
|
|
8
|
-
|
|
9
|
-
def get_package_type
|
|
10
|
-
@package_type
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def initialize(package_type, package_name, versions, options = {})
|
|
14
|
-
@package_type = package_type
|
|
15
|
-
@package_name = package_name
|
|
16
|
-
@versions = versions
|
|
17
|
-
#
|
|
18
|
-
@additional_indent = 6
|
|
19
|
-
#TODO: authentication + encoding missing
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def additional_indent
|
|
23
|
-
@additional_indent += 12
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def get_cf_attributes
|
|
27
|
-
result = {}
|
|
28
|
-
result["#{@package_name}"] = @versions.inspect
|
|
29
|
-
result
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def generate
|
|
33
|
-
CfGenerator.indent(self.additional_indent, "\"#{@package_name}\" : #{@versions.inspect}")
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
require 'cf_factory/base/cf_inner'
|
|
3
|
+
require 'cf_factory/base/cf_helper'
|
|
4
|
+
|
|
5
|
+
module CfFactory
|
|
6
|
+
class CfCloudFormationPackage
|
|
7
|
+
include CfInner
|
|
8
|
+
|
|
9
|
+
def get_package_type
|
|
10
|
+
@package_type
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize(package_type, package_name, versions, options = {})
|
|
14
|
+
@package_type = package_type
|
|
15
|
+
@package_name = package_name
|
|
16
|
+
@versions = versions
|
|
17
|
+
#
|
|
18
|
+
@additional_indent = 6
|
|
19
|
+
#TODO: authentication + encoding missing
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def additional_indent
|
|
23
|
+
@additional_indent += 12
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_cf_attributes
|
|
27
|
+
result = {}
|
|
28
|
+
result["#{@package_name}"] = @versions.inspect
|
|
29
|
+
result
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def generate
|
|
33
|
+
CfGenerator.indent(self.additional_indent, "\"#{@package_name}\" : #{@versions.inspect}")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
require 'cf_factory/base/cf_base'
|
|
2
|
-
require 'cf_factory/base/cf_inner'
|
|
3
|
-
require 'cf_factory/base/cf_helper'
|
|
4
|
-
|
|
5
|
-
module CfFactory
|
|
6
|
-
class CfCloudFormationPackages
|
|
7
|
-
include CfInner
|
|
8
|
-
|
|
9
|
-
def initialize(package_definitions)
|
|
10
|
-
@package_definitions = package_definitions
|
|
11
|
-
#
|
|
12
|
-
@additional_indent = 6
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def additional_indent
|
|
16
|
-
@additional_indent
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def get_cf_attributes
|
|
20
|
-
result = {}
|
|
21
|
-
sort_packages_by_type()
|
|
22
|
-
@packages_by_type.keys.each() {|package_type|
|
|
23
|
-
result["#{package_type}"] = "{\n#{CfHelper.generate_inner_list(@packages_by_type[package_type])}\n#{" "*(@additional_indent+10)}}"
|
|
24
|
-
}
|
|
25
|
-
result
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def sort_packages_by_type
|
|
31
|
-
@packages_by_type = {}
|
|
32
|
-
@package_definitions.each() {|package_definition|
|
|
33
|
-
packages_of_type = @packages_by_type[package_definition.get_package_type]
|
|
34
|
-
if packages_of_type.nil?
|
|
35
|
-
packages_of_type = []
|
|
36
|
-
@packages_by_type[package_definition.get_package_type] = packages_of_type
|
|
37
|
-
end
|
|
38
|
-
packages_of_type << package_definition
|
|
39
|
-
}
|
|
40
|
-
@packages_by_type
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
end
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
require 'cf_factory/base/cf_inner'
|
|
3
|
+
require 'cf_factory/base/cf_helper'
|
|
4
|
+
|
|
5
|
+
module CfFactory
|
|
6
|
+
class CfCloudFormationPackages
|
|
7
|
+
include CfInner
|
|
8
|
+
|
|
9
|
+
def initialize(package_definitions)
|
|
10
|
+
@package_definitions = package_definitions
|
|
11
|
+
#
|
|
12
|
+
@additional_indent = 6
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def additional_indent
|
|
16
|
+
@additional_indent
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_cf_attributes
|
|
20
|
+
result = {}
|
|
21
|
+
sort_packages_by_type()
|
|
22
|
+
@packages_by_type.keys.each() {|package_type|
|
|
23
|
+
result["#{package_type}"] = "{\n#{CfHelper.generate_inner_list(@packages_by_type[package_type])}\n#{" "*(@additional_indent+10)}}"
|
|
24
|
+
}
|
|
25
|
+
result
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def sort_packages_by_type
|
|
31
|
+
@packages_by_type = {}
|
|
32
|
+
@package_definitions.each() {|package_definition|
|
|
33
|
+
packages_of_type = @packages_by_type[package_definition.get_package_type]
|
|
34
|
+
if packages_of_type.nil?
|
|
35
|
+
packages_of_type = []
|
|
36
|
+
@packages_by_type[package_definition.get_package_type] = packages_of_type
|
|
37
|
+
end
|
|
38
|
+
packages_of_type << package_definition
|
|
39
|
+
}
|
|
40
|
+
@packages_by_type
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
require 'cf_factory/base/cf_base'
|
|
2
|
-
require 'cf_factory/base/cf_inner'
|
|
3
|
-
|
|
4
|
-
module CfFactory
|
|
5
|
-
class CfCloudFormationSources
|
|
6
|
-
include CfInner
|
|
7
|
-
|
|
8
|
-
def initialize(source_list, additional_indent = 6)
|
|
9
|
-
@source_list = source_list
|
|
10
|
-
@additional_indent = additional_indent
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def additional_indent
|
|
14
|
-
6
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def add_additional_indent
|
|
18
|
-
@additional_indent += 2
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def get_cf_attributes
|
|
22
|
-
result = {}
|
|
23
|
-
@source_list.each() {|key_value|
|
|
24
|
-
key = key_value.keys.first
|
|
25
|
-
value = key_value[key]
|
|
26
|
-
result[key] = value
|
|
27
|
-
}
|
|
28
|
-
result
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
end
|
|
32
|
-
end
|
|
1
|
+
require 'cf_factory/base/cf_base'
|
|
2
|
+
require 'cf_factory/base/cf_inner'
|
|
3
|
+
|
|
4
|
+
module CfFactory
|
|
5
|
+
class CfCloudFormationSources
|
|
6
|
+
include CfInner
|
|
7
|
+
|
|
8
|
+
def initialize(source_list, additional_indent = 6)
|
|
9
|
+
@source_list = source_list
|
|
10
|
+
@additional_indent = additional_indent
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def additional_indent
|
|
14
|
+
6
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_additional_indent
|
|
18
|
+
@additional_indent += 2
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get_cf_attributes
|
|
22
|
+
result = {}
|
|
23
|
+
@source_list.each() {|key_value|
|
|
24
|
+
key = key_value.keys.first
|
|
25
|
+
value = key_value[key]
|
|
26
|
+
result[key] = value
|
|
27
|
+
}
|
|
28
|
+
result
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
module CfFactory
|
|
2
|
-
class CfInitScript
|
|
3
|
-
# Every parameter-string will be transformed into something like { "Ref" : "<parameter>" }
|
|
4
|
-
def initialize(script, parameter_array)
|
|
5
|
-
@script = script
|
|
6
|
-
@parameter_array = parameter_array
|
|
7
|
-
prepare
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def user_data
|
|
11
|
-
@user_data
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.create_basic(resource_id, access_key, secret_key)
|
|
15
|
-
stack = CfHelper.generate_ref("AWS::StackName")
|
|
16
|
-
CfInitScript.new(basic_script(), [stack, resource_id, access_key, secret_key])
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.create_from_text(file_path, params)
|
|
20
|
-
contents = File.open(file_path).read
|
|
21
|
-
CfInitScript.new(contents,params)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def validate
|
|
27
|
-
if @script.occurences_of("<!par!") != @parameter_array.size
|
|
28
|
-
raise Exception.new("the number of parameters does not correspond to the number of placeholders in the script")
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Looks for all occurences of <!#par#!> in the script and builds a string that is base64-encoded and joined
|
|
33
|
-
# and where all those occurences are replaced with the parameter name specified in the constructor.
|
|
34
|
-
def prepare
|
|
35
|
-
#divide along parameters
|
|
36
|
-
#@script.strip!()
|
|
37
|
-
divided_script = @script.split("<!par!>")
|
|
38
|
-
script_with_params = []
|
|
39
|
-
count = 0
|
|
40
|
-
divided_script.each() {|part|
|
|
41
|
-
#puts "part [#{count}] = #{part}"
|
|
42
|
-
part.split("\n").each() {|line|
|
|
43
|
-
next if line.strip.size == 0
|
|
44
|
-
script_with_params << "#{line.lstrip} " #TODO: make this work with the line-breaks
|
|
45
|
-
script_with_params << "\n"
|
|
46
|
-
}
|
|
47
|
-
script_with_params.delete_at(script_with_params.size()-1)
|
|
48
|
-
script_with_params << @parameter_array[count]
|
|
49
|
-
count += 1
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
join = CfHelper.join(script_with_params)
|
|
53
|
-
|
|
54
|
-
@user_data = join
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def self.basic_script
|
|
58
|
-
init_script = "
|
|
59
|
-
#!/bin/bash -v
|
|
60
|
-
/opt/aws/bin/cfn-init -s <!par!> -r <!par!>
|
|
61
|
-
--access-key <!par!>
|
|
62
|
-
--secret-key <!par!>
|
|
63
|
-
|| error_exit 'Failed to run cfn-init'
|
|
64
|
-
"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def self.basic_script_with_update
|
|
68
|
-
init_script = "
|
|
69
|
-
#!/bin/bash -v
|
|
70
|
-
yum update -y aws-cfn-bootstrap
|
|
71
|
-
# Run cfn-init for config
|
|
72
|
-
/opt/aws/bin/cfn-init -s <!par!> -r <!par!>
|
|
73
|
-
--access-key <!par!>
|
|
74
|
-
--secret-key <!par!>
|
|
75
|
-
|| error_exit 'Failed to run cfn-init'
|
|
76
|
-
"
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
end
|
|
80
|
-
end
|
|
1
|
+
module CfFactory
|
|
2
|
+
class CfInitScript
|
|
3
|
+
# Every parameter-string will be transformed into something like { "Ref" : "<parameter>" }
|
|
4
|
+
def initialize(script, parameter_array)
|
|
5
|
+
@script = script
|
|
6
|
+
@parameter_array = parameter_array
|
|
7
|
+
prepare
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def user_data
|
|
11
|
+
@user_data
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.create_basic(resource_id, access_key, secret_key)
|
|
15
|
+
stack = CfHelper.generate_ref("AWS::StackName")
|
|
16
|
+
CfInitScript.new(basic_script(), [stack, resource_id, access_key, secret_key])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.create_from_text(file_path, params)
|
|
20
|
+
contents = File.open(file_path).read
|
|
21
|
+
CfInitScript.new(contents,params)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def validate
|
|
27
|
+
if @script.occurences_of("<!par!") != @parameter_array.size
|
|
28
|
+
raise Exception.new("the number of parameters does not correspond to the number of placeholders in the script")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Looks for all occurences of <!#par#!> in the script and builds a string that is base64-encoded and joined
|
|
33
|
+
# and where all those occurences are replaced with the parameter name specified in the constructor.
|
|
34
|
+
def prepare
|
|
35
|
+
#divide along parameters
|
|
36
|
+
#@script.strip!()
|
|
37
|
+
divided_script = @script.split("<!par!>")
|
|
38
|
+
script_with_params = []
|
|
39
|
+
count = 0
|
|
40
|
+
divided_script.each() {|part|
|
|
41
|
+
#puts "part [#{count}] = #{part}"
|
|
42
|
+
part.split("\n").each() {|line|
|
|
43
|
+
next if line.strip.size == 0
|
|
44
|
+
script_with_params << "#{line.lstrip} " #TODO: make this work with the line-breaks
|
|
45
|
+
script_with_params << "\n"
|
|
46
|
+
}
|
|
47
|
+
script_with_params.delete_at(script_with_params.size()-1)
|
|
48
|
+
script_with_params << @parameter_array[count]
|
|
49
|
+
count += 1
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
join = CfHelper.join(script_with_params)
|
|
53
|
+
|
|
54
|
+
@user_data = join
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.basic_script
|
|
58
|
+
init_script = "
|
|
59
|
+
#!/bin/bash -v
|
|
60
|
+
/opt/aws/bin/cfn-init -s <!par!> -r <!par!>
|
|
61
|
+
--access-key <!par!>
|
|
62
|
+
--secret-key <!par!>
|
|
63
|
+
|| error_exit 'Failed to run cfn-init'
|
|
64
|
+
"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.basic_script_with_update
|
|
68
|
+
init_script = "
|
|
69
|
+
#!/bin/bash -v
|
|
70
|
+
yum update -y aws-cfn-bootstrap
|
|
71
|
+
# Run cfn-init for config
|
|
72
|
+
/opt/aws/bin/cfn-init -s <!par!> -r <!par!>
|
|
73
|
+
--access-key <!par!>
|
|
74
|
+
--secret-key <!par!>
|
|
75
|
+
|| error_exit 'Failed to run cfn-init'
|
|
76
|
+
"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
require 'cf_factory/base/cf_inner'
|
|
2
|
-
|
|
3
|
-
module CfFactory
|
|
4
|
-
class CfCacheBehavior
|
|
5
|
-
include CfInner
|
|
6
|
-
|
|
7
|
-
attr_reader(:id)
|
|
8
|
-
|
|
9
|
-
def additional_indent
|
|
10
|
-
6
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.create_basic(target_origin_id, path_pattern, options = {})
|
|
14
|
-
CfCacheBehavior.new(target_origin_id, CfForwardedValues.new(true), "allow-all", path_pattern, options)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def initialize(target_origin_id, forwarded_values, viewer_protocol_policy, path_pattern, options)
|
|
18
|
-
@target_origin_id = target_origin_id
|
|
19
|
-
@forwarded_values = forwarded_values
|
|
20
|
-
@forwarded_values.add(2)
|
|
21
|
-
@view_protocol_policy = viewer_protocol_policy
|
|
22
|
-
@path_pattern = path_pattern
|
|
23
|
-
@min_ttl = options[:min_ttl]
|
|
24
|
-
@trusted_signers = options[:trusted_signers]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def get_cf_attributes
|
|
28
|
-
result = {}
|
|
29
|
-
result["TargetOriginId"] = @target_origin_id
|
|
30
|
-
result["ForwardedValues"] = @forwarded_values.generate
|
|
31
|
-
result["ViewerProtocolPolicy"] = @view_protocol_policy
|
|
32
|
-
result["PathPattern"] = @path_pattern
|
|
33
|
-
result["MinTTL"] = @min_ttl unless @min_ttl.nil?
|
|
34
|
-
result["TrustedSigners"] = @trusted_signers unless @trusted_signers.nil?
|
|
35
|
-
result
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
end
|
|
1
|
+
require 'cf_factory/base/cf_inner'
|
|
2
|
+
|
|
3
|
+
module CfFactory
|
|
4
|
+
class CfCacheBehavior
|
|
5
|
+
include CfInner
|
|
6
|
+
|
|
7
|
+
attr_reader(:id)
|
|
8
|
+
|
|
9
|
+
def additional_indent
|
|
10
|
+
6
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.create_basic(target_origin_id, path_pattern, options = {})
|
|
14
|
+
CfCacheBehavior.new(target_origin_id, CfForwardedValues.new(true), "allow-all", path_pattern, options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize(target_origin_id, forwarded_values, viewer_protocol_policy, path_pattern, options)
|
|
18
|
+
@target_origin_id = target_origin_id
|
|
19
|
+
@forwarded_values = forwarded_values
|
|
20
|
+
@forwarded_values.add(2)
|
|
21
|
+
@view_protocol_policy = viewer_protocol_policy
|
|
22
|
+
@path_pattern = path_pattern
|
|
23
|
+
@min_ttl = options[:min_ttl]
|
|
24
|
+
@trusted_signers = options[:trusted_signers]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def get_cf_attributes
|
|
28
|
+
result = {}
|
|
29
|
+
result["TargetOriginId"] = @target_origin_id
|
|
30
|
+
result["ForwardedValues"] = @forwarded_values.generate
|
|
31
|
+
result["ViewerProtocolPolicy"] = @view_protocol_policy
|
|
32
|
+
result["PathPattern"] = @path_pattern
|
|
33
|
+
result["MinTTL"] = @min_ttl unless @min_ttl.nil?
|
|
34
|
+
result["TrustedSigners"] = @trusted_signers unless @trusted_signers.nil?
|
|
35
|
+
result
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
require 'cf_factory/base/cf_inner'
|
|
2
|
-
|
|
3
|
-
module CfFactory
|
|
4
|
-
class CfDefaultCacheBehaviors
|
|
5
|
-
include CfInner
|
|
6
|
-
|
|
7
|
-
def additional_indent
|
|
8
|
-
4
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def initialize(target_origin_id, forwarded_values, viewer_protocol_policy, options = {})
|
|
12
|
-
@target_origin_id = target_origin_id
|
|
13
|
-
@forwarded_values = forwarded_values
|
|
14
|
-
@viewer_protocol_policy = viewer_protocol_policy
|
|
15
|
-
|
|
16
|
-
@min_ttl = options[:min_ttl]
|
|
17
|
-
@trusted_signers = options[:trusted_signers]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def get_cf_attributes
|
|
21
|
-
result = {}
|
|
22
|
-
result["TargetOriginId"] = @target_origin_id
|
|
23
|
-
result["ForwardedValues"] = @forwarded_values.generate
|
|
24
|
-
result["ViewerProtocolPolicy"] = @viewer_protocol_policy
|
|
25
|
-
result["MinTTL"] = @min_ttl unless @min_ttl.nil?
|
|
26
|
-
result
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
end
|
|
1
|
+
require 'cf_factory/base/cf_inner'
|
|
2
|
+
|
|
3
|
+
module CfFactory
|
|
4
|
+
class CfDefaultCacheBehaviors
|
|
5
|
+
include CfInner
|
|
6
|
+
|
|
7
|
+
def additional_indent
|
|
8
|
+
4
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initialize(target_origin_id, forwarded_values, viewer_protocol_policy, options = {})
|
|
12
|
+
@target_origin_id = target_origin_id
|
|
13
|
+
@forwarded_values = forwarded_values
|
|
14
|
+
@viewer_protocol_policy = viewer_protocol_policy
|
|
15
|
+
|
|
16
|
+
@min_ttl = options[:min_ttl]
|
|
17
|
+
@trusted_signers = options[:trusted_signers]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get_cf_attributes
|
|
21
|
+
result = {}
|
|
22
|
+
result["TargetOriginId"] = @target_origin_id
|
|
23
|
+
result["ForwardedValues"] = @forwarded_values.generate
|
|
24
|
+
result["ViewerProtocolPolicy"] = @viewer_protocol_policy
|
|
25
|
+
result["MinTTL"] = @min_ttl unless @min_ttl.nil?
|
|
26
|
+
result
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|