lucid-cumulus 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +202 -0
- data/README.md +41 -0
- data/autocomplete +137 -0
- data/bin/cumulus +658 -0
- data/cumulus +2 -0
- data/lib/autoscaling/AutoScaling.rb +40 -0
- data/lib/autoscaling/loader/Loader.rb +56 -0
- data/lib/autoscaling/manager/Manager.rb +360 -0
- data/lib/autoscaling/models/AlarmConfig.rb +165 -0
- data/lib/autoscaling/models/AlarmDiff.rb +172 -0
- data/lib/autoscaling/models/AutoScalingDiff.rb +178 -0
- data/lib/autoscaling/models/GroupConfig.rb +330 -0
- data/lib/autoscaling/models/PolicyConfig.rb +135 -0
- data/lib/autoscaling/models/PolicyDiff.rb +73 -0
- data/lib/autoscaling/models/ScheduledActionDiff.rb +53 -0
- data/lib/autoscaling/models/ScheduledConfig.rb +96 -0
- data/lib/aws_extensions/ec2/DhcpOptions.rb +41 -0
- data/lib/aws_extensions/ec2/Instance.rb +29 -0
- data/lib/aws_extensions/ec2/NetworkAcl.rb +25 -0
- data/lib/aws_extensions/ec2/NetworkInterface.rb +14 -0
- data/lib/aws_extensions/ec2/RouteTable.rb +26 -0
- data/lib/aws_extensions/ec2/SecurityGroup.rb +16 -0
- data/lib/aws_extensions/ec2/Subnet.rb +28 -0
- data/lib/aws_extensions/ec2/Volume.rb +24 -0
- data/lib/aws_extensions/ec2/Vpc.rb +14 -0
- data/lib/aws_extensions/ec2/VpcEndpoint.rb +11 -0
- data/lib/aws_extensions/elb/BackendServerDescription.rb +12 -0
- data/lib/aws_extensions/elb/PolicyDescription.rb +14 -0
- data/lib/aws_extensions/kinesis/StreamDescription.rb +12 -0
- data/lib/aws_extensions/route53/AliasTarget.rb +21 -0
- data/lib/aws_extensions/s3/Bucket.rb +33 -0
- data/lib/aws_extensions/s3/BucketAcl.rb +28 -0
- data/lib/aws_extensions/s3/BucketCors.rb +17 -0
- data/lib/aws_extensions/s3/BucketLifecycle.rb +21 -0
- data/lib/aws_extensions/s3/BucketLogging.rb +18 -0
- data/lib/aws_extensions/s3/BucketNotification.rb +23 -0
- data/lib/aws_extensions/s3/BucketPolicy.rb +18 -0
- data/lib/aws_extensions/s3/BucketTagging.rb +15 -0
- data/lib/aws_extensions/s3/BucketVersioning.rb +14 -0
- data/lib/aws_extensions/s3/BucketWebsite.rb +49 -0
- data/lib/aws_extensions/s3/CORSRule.rb +27 -0
- data/lib/aws_extensions/s3/ReplicationConfiguration.rb +22 -0
- data/lib/cloudfront/CloudFront.rb +83 -0
- data/lib/cloudfront/loader/Loader.rb +31 -0
- data/lib/cloudfront/manager/Manager.rb +183 -0
- data/lib/cloudfront/models/CacheBehaviorConfig.rb +237 -0
- data/lib/cloudfront/models/CacheBehaviorDiff.rb +211 -0
- data/lib/cloudfront/models/CustomOriginConfig.rb +51 -0
- data/lib/cloudfront/models/CustomOriginDiff.rb +74 -0
- data/lib/cloudfront/models/DistributionConfig.rb +183 -0
- data/lib/cloudfront/models/DistributionDiff.rb +131 -0
- data/lib/cloudfront/models/InvalidationConfig.rb +37 -0
- data/lib/cloudfront/models/OriginConfig.rb +144 -0
- data/lib/cloudfront/models/OriginDiff.rb +86 -0
- data/lib/cloudfront/models/OriginSslProtocols.rb +28 -0
- data/lib/cloudfront/models/OriginSslProtocolsDiff.rb +39 -0
- data/lib/common/BaseLoader.rb +80 -0
- data/lib/common/manager/Manager.rb +148 -0
- data/lib/common/models/Diff.rb +114 -0
- data/lib/common/models/ListChange.rb +21 -0
- data/lib/common/models/TagsDiff.rb +55 -0
- data/lib/common/models/UTCTimeSource.rb +17 -0
- data/lib/conf/Configuration.rb +365 -0
- data/lib/ec2/EC2.rb +503 -0
- data/lib/ec2/IPProtocolMapping.rb +165 -0
- data/lib/ec2/loaders/EbsLoader.rb +19 -0
- data/lib/ec2/loaders/InstanceLoader.rb +32 -0
- data/lib/ec2/managers/EbsManager.rb +176 -0
- data/lib/ec2/managers/InstanceManager.rb +509 -0
- data/lib/ec2/models/EbsGroupConfig.rb +133 -0
- data/lib/ec2/models/EbsGroupDiff.rb +48 -0
- data/lib/ec2/models/InstanceConfig.rb +202 -0
- data/lib/ec2/models/InstanceDiff.rb +95 -0
- data/lib/elb/ELB.rb +148 -0
- data/lib/elb/loader/Loader.rb +65 -0
- data/lib/elb/manager/Manager.rb +581 -0
- data/lib/elb/models/AccessLogConfig.rb +82 -0
- data/lib/elb/models/AccessLogDiff.rb +47 -0
- data/lib/elb/models/HealthCheckConfig.rb +91 -0
- data/lib/elb/models/HealthCheckDiff.rb +50 -0
- data/lib/elb/models/ListenerConfig.rb +99 -0
- data/lib/elb/models/ListenerDiff.rb +91 -0
- data/lib/elb/models/LoadBalancerConfig.rb +239 -0
- data/lib/elb/models/LoadBalancerDiff.rb +265 -0
- data/lib/iam/IAM.rb +36 -0
- data/lib/iam/loader/Loader.rb +117 -0
- data/lib/iam/manager/IamGroups.rb +98 -0
- data/lib/iam/manager/IamResource.rb +288 -0
- data/lib/iam/manager/IamRoles.rb +112 -0
- data/lib/iam/manager/IamUsers.rb +54 -0
- data/lib/iam/manager/Manager.rb +29 -0
- data/lib/iam/migration/AssumeRoleUnifier.rb +34 -0
- data/lib/iam/migration/PolicyUnifier.rb +90 -0
- data/lib/iam/models/GroupConfig.rb +40 -0
- data/lib/iam/models/IamDiff.rb +132 -0
- data/lib/iam/models/PolicyConfig.rb +67 -0
- data/lib/iam/models/ResourceWithPolicy.rb +208 -0
- data/lib/iam/models/RoleConfig.rb +53 -0
- data/lib/iam/models/StatementConfig.rb +35 -0
- data/lib/iam/models/UserConfig.rb +21 -0
- data/lib/kinesis/Kinesis.rb +94 -0
- data/lib/kinesis/loader/Loader.rb +19 -0
- data/lib/kinesis/manager/Manager.rb +206 -0
- data/lib/kinesis/models/StreamConfig.rb +75 -0
- data/lib/kinesis/models/StreamDiff.rb +58 -0
- data/lib/lambda/Lambda.rb +41 -0
- data/lib/route53/loader/Loader.rb +32 -0
- data/lib/route53/manager/Manager.rb +241 -0
- data/lib/route53/models/AliasTarget.rb +86 -0
- data/lib/route53/models/RecordConfig.rb +178 -0
- data/lib/route53/models/RecordDiff.rb +140 -0
- data/lib/route53/models/Vpc.rb +24 -0
- data/lib/route53/models/ZoneConfig.rb +156 -0
- data/lib/route53/models/ZoneDiff.rb +118 -0
- data/lib/s3/S3.rb +89 -0
- data/lib/s3/loader/Loader.rb +66 -0
- data/lib/s3/manager/Manager.rb +296 -0
- data/lib/s3/models/BucketConfig.rb +321 -0
- data/lib/s3/models/BucketDiff.rb +167 -0
- data/lib/s3/models/GrantConfig.rb +189 -0
- data/lib/s3/models/GrantDiff.rb +50 -0
- data/lib/s3/models/LifecycleConfig.rb +142 -0
- data/lib/s3/models/LifecycleDiff.rb +46 -0
- data/lib/s3/models/LoggingConfig.rb +81 -0
- data/lib/s3/models/NotificationConfig.rb +157 -0
- data/lib/s3/models/NotificationDiff.rb +62 -0
- data/lib/s3/models/ReplicationConfig.rb +133 -0
- data/lib/s3/models/ReplicationDiff.rb +60 -0
- data/lib/s3/models/WebsiteConfig.rb +107 -0
- data/lib/security/SecurityGroups.rb +39 -0
- data/lib/security/loader/Loader.rb +94 -0
- data/lib/security/manager/Manager.rb +246 -0
- data/lib/security/models/RuleConfig.rb +161 -0
- data/lib/security/models/RuleDiff.rb +72 -0
- data/lib/security/models/RuleMigration.rb +127 -0
- data/lib/security/models/SecurityGroupConfig.rb +172 -0
- data/lib/security/models/SecurityGroupDiff.rb +112 -0
- data/lib/sns/SNS.rb +40 -0
- data/lib/sqs/SQS.rb +62 -0
- data/lib/sqs/loader/Loader.rb +34 -0
- data/lib/sqs/manager/Manager.rb +128 -0
- data/lib/sqs/models/DeadLetterConfig.rb +70 -0
- data/lib/sqs/models/DeadLetterDiff.rb +35 -0
- data/lib/sqs/models/QueueConfig.rb +115 -0
- data/lib/sqs/models/QueueDiff.rb +89 -0
- data/lib/util/Colors.rb +111 -0
- data/lib/util/StatusCodes.rb +51 -0
- data/lib/vpc/loader/Loader.rb +73 -0
- data/lib/vpc/manager/Manager.rb +954 -0
- data/lib/vpc/models/AclEntryConfig.rb +150 -0
- data/lib/vpc/models/AclEntryDiff.rb +54 -0
- data/lib/vpc/models/DhcpConfig.rb +100 -0
- data/lib/vpc/models/DhcpDiff.rb +90 -0
- data/lib/vpc/models/EndpointConfig.rb +76 -0
- data/lib/vpc/models/EndpointDiff.rb +69 -0
- data/lib/vpc/models/NetworkAclConfig.rb +87 -0
- data/lib/vpc/models/NetworkAclDiff.rb +116 -0
- data/lib/vpc/models/RouteConfig.rb +82 -0
- data/lib/vpc/models/RouteDiff.rb +50 -0
- data/lib/vpc/models/RouteTableConfig.rb +92 -0
- data/lib/vpc/models/RouteTableDiff.rb +101 -0
- data/lib/vpc/models/SubnetConfig.rb +113 -0
- data/lib/vpc/models/SubnetDiff.rb +78 -0
- data/lib/vpc/models/VpcConfig.rb +173 -0
- data/lib/vpc/models/VpcDiff.rb +315 -0
- data/lucid-cumulus.gemspec +20 -0
- data/rakefile.rb +8 -0
- metadata +245 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
require "common/BaseLoader"
|
2
|
+
require "conf/Configuration"
|
3
|
+
require "cloudfront/models/DistributionConfig"
|
4
|
+
require "cloudfront/models/InvalidationConfig"
|
5
|
+
|
6
|
+
# Public: Load CloudFront assets
|
7
|
+
module Cumulus
|
8
|
+
module CloudFront
|
9
|
+
module Loader
|
10
|
+
include Common::BaseLoader
|
11
|
+
|
12
|
+
@@distributions_dir = Configuration.instance.cloudfront.distributions_directory
|
13
|
+
@@invalidations_dir = Configuration.instance.cloudfront.invalidations_directory
|
14
|
+
|
15
|
+
# Public: Load all the distribution configurations as DistributionConfig objects
|
16
|
+
#
|
17
|
+
# Returns an array of DistributionConfig
|
18
|
+
def self.distributions
|
19
|
+
Common::BaseLoader::resources(@@distributions_dir, &DistributionConfig.method(:new))
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public loads all of the invalidation configurations as InvalidationConfig objects
|
23
|
+
#
|
24
|
+
# Returns an array of InvalidationConfig
|
25
|
+
def self.invalidations
|
26
|
+
Common::BaseLoader::resources(@@invalidations_dir, &InvalidationConfig.method(:new))
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require "common/manager/Manager"
|
2
|
+
require "conf/Configuration"
|
3
|
+
require "cloudfront/CloudFront"
|
4
|
+
require "cloudfront/loader/Loader"
|
5
|
+
require "cloudfront/models/DistributionDiff"
|
6
|
+
require "util/Colors"
|
7
|
+
require "util/StatusCodes"
|
8
|
+
|
9
|
+
require "aws-sdk"
|
10
|
+
|
11
|
+
module Cumulus
|
12
|
+
module CloudFront
|
13
|
+
class Manager < Common::Manager
|
14
|
+
def initialize
|
15
|
+
super()
|
16
|
+
@cloudfront = Aws::CloudFront::Client.new(Configuration.instance.client)
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource_name
|
20
|
+
"CloudFront Distribution"
|
21
|
+
end
|
22
|
+
|
23
|
+
def local_resources
|
24
|
+
@local_resources ||= Hash[Loader.distributions.map { |local| [local.id, local] }]
|
25
|
+
end
|
26
|
+
|
27
|
+
def aws_resources
|
28
|
+
@aws_resources ||= CloudFront::id_distributions
|
29
|
+
end
|
30
|
+
|
31
|
+
def full_distribution(distribution_id)
|
32
|
+
@full_aws_configs ||= Hash.new
|
33
|
+
|
34
|
+
@full_aws_configs[distribution_id] ||= CloudFront::load_distribution_config(distribution_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def unmanaged_diff(aws)
|
38
|
+
DistributionDiff.unmanaged(aws)
|
39
|
+
end
|
40
|
+
|
41
|
+
def added_diff(local)
|
42
|
+
DistributionDiff.added(local)
|
43
|
+
end
|
44
|
+
|
45
|
+
def diff_resource(local, aws)
|
46
|
+
local.diff(full_distribution(aws.id).distribution_config)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Migrate AWS CloudFront distributions to local config
|
50
|
+
def migrate
|
51
|
+
distributions_dir = "#{@migration_root}/distributions"
|
52
|
+
|
53
|
+
if !Dir.exists?(@migration_root)
|
54
|
+
Dir.mkdir(@migration_root)
|
55
|
+
end
|
56
|
+
if !Dir.exists?(distributions_dir)
|
57
|
+
Dir.mkdir(distributions_dir)
|
58
|
+
end
|
59
|
+
|
60
|
+
aws_resources.each_key do |dist_id|
|
61
|
+
puts "Processing #{dist_id}..."
|
62
|
+
full_config = full_distribution(dist_id).distribution_config
|
63
|
+
|
64
|
+
config = DistributionConfig.new(dist_id)
|
65
|
+
config.populate!(dist_id, full_config)
|
66
|
+
|
67
|
+
puts "Writing #{dist_id} configuration to file"
|
68
|
+
File.open("#{distributions_dir}/#{dist_id}.json", "w") { |f| f.write(config.pretty_json) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def update(local, diffs)
|
73
|
+
if !diffs.empty?
|
74
|
+
full_aws_response = full_distribution(local.id)
|
75
|
+
|
76
|
+
aws_config = full_aws_response.distribution_config
|
77
|
+
|
78
|
+
updated_config = {
|
79
|
+
aliases: {
|
80
|
+
quantity: local.aliases.size,
|
81
|
+
items: if local.aliases.empty? then nil else local.aliases end
|
82
|
+
},
|
83
|
+
origins: {
|
84
|
+
quantity: local.origins.size,
|
85
|
+
items: if local.origins.empty? then nil else local.origins.map(&:to_aws) end
|
86
|
+
},
|
87
|
+
default_cache_behavior: local.default_cache_behavior.to_aws,
|
88
|
+
cache_behaviors: {
|
89
|
+
quantity: local.cache_behaviors.size,
|
90
|
+
items: if local.cache_behaviors.empty? then nil else local.cache_behaviors.map(&:to_aws) end
|
91
|
+
},
|
92
|
+
comment: local.comment,
|
93
|
+
enabled: local.enabled
|
94
|
+
}
|
95
|
+
|
96
|
+
update_params = {
|
97
|
+
id: local.id,
|
98
|
+
if_match: full_aws_response.etag,
|
99
|
+
distribution_config: aws_config.to_h.merge(updated_config)
|
100
|
+
}
|
101
|
+
|
102
|
+
begin
|
103
|
+
@cloudfront.update_distribution(update_params)
|
104
|
+
rescue Aws::CloudFront::Errors::InvalidArgument => e
|
105
|
+
if e.message =~ /OriginSslProtocols is required/
|
106
|
+
puts Colors.red("Distribution #{local.name} must specify $.custom-origin-config.origin-ssl-protocols when \"protocol-policy\" is \"https-only\". Distribution not updated")
|
107
|
+
StatusCodes.set_status(StatusCodes::EXCEPTION)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def create(local)
|
115
|
+
create_config = {
|
116
|
+
distribution_config: {
|
117
|
+
caller_reference: local.name,
|
118
|
+
aliases: {
|
119
|
+
quantity: local.aliases.size,
|
120
|
+
items: if local.aliases.empty? then nil else local.aliases end
|
121
|
+
},
|
122
|
+
origins: {
|
123
|
+
quantity: local.origins.size,
|
124
|
+
items: if local.origins.empty? then nil else local.origins.map(&:to_aws) end
|
125
|
+
},
|
126
|
+
default_cache_behavior: local.default_cache_behavior.to_aws,
|
127
|
+
cache_behaviors: {
|
128
|
+
quantity: local.cache_behaviors.size,
|
129
|
+
items: if local.cache_behaviors.empty? then nil else local.cache_behaviors.map(&:to_aws) end
|
130
|
+
},
|
131
|
+
comment: local.comment,
|
132
|
+
enabled: local.enabled
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
local.id = @cloudfront.create_distribution(create_config).distribution.id
|
137
|
+
|
138
|
+
# Save the updated local config with id
|
139
|
+
File.open("#{Configuration.instance.cloudfront.distributions_directory}/#{local.name}.json", "w") { |f| f.write(local.pretty_json) }
|
140
|
+
puts "Distribution #{local.name} created with id #{local.id}"
|
141
|
+
|
142
|
+
rescue Aws::CloudFront::Errors::InvalidArgument => e
|
143
|
+
if e.message =~ /OriginSslProtocols is required/
|
144
|
+
puts Colors.red("Distribution #{local.name} must specify $.custom-origin-config.origin-ssl-protocols when \"protocol-policy\" is \"https-only\". Distribution not created")
|
145
|
+
StatusCodes.set_status(StatusCodes::EXCEPTION)
|
146
|
+
end
|
147
|
+
rescue => e
|
148
|
+
puts "Failed to create distribution #{local.name}\n#{e}"
|
149
|
+
end
|
150
|
+
|
151
|
+
def invalidations
|
152
|
+
@invalidations ||= Hash[Loader.invalidations.map { |local| [local.name, local] }]
|
153
|
+
end
|
154
|
+
|
155
|
+
def list_invalidations
|
156
|
+
puts invalidations.keys.join(" ")
|
157
|
+
end
|
158
|
+
|
159
|
+
def invalidate(invalidation_name)
|
160
|
+
|
161
|
+
invalidation = invalidations[invalidation_name]
|
162
|
+
|
163
|
+
# Use a combination of the current time and md5 of paths to prevent
|
164
|
+
# identical invalidations from being ran too often
|
165
|
+
time_throttle = (Time.now.to_i / 60 / 5)
|
166
|
+
md5 = Digest::MD5.hexdigest(invalidation.paths.join)[0..5]
|
167
|
+
|
168
|
+
@cloudfront.create_invalidation({
|
169
|
+
distribution_id: invalidation.distribution_id,
|
170
|
+
invalidation_batch: {
|
171
|
+
paths: {
|
172
|
+
quantity: invalidation.paths.size,
|
173
|
+
items: if !invalidation.paths.empty? then invalidation.paths end
|
174
|
+
},
|
175
|
+
caller_reference: "#{invalidation_name}-#{md5}-#{time_throttle}"
|
176
|
+
}
|
177
|
+
})
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require "conf/Configuration"
|
2
|
+
require "cloudfront/models/CacheBehaviorDiff"
|
3
|
+
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Cumulus
|
7
|
+
module CloudFront
|
8
|
+
# Public: An object representing configuration for a distribution cache behavior
|
9
|
+
class CacheBehaviorConfig
|
10
|
+
attr_reader :default
|
11
|
+
attr_reader :path_pattern
|
12
|
+
attr_reader :target_origin_id
|
13
|
+
attr_reader :forward_query_strings
|
14
|
+
attr_reader :forwarded_cookies
|
15
|
+
attr_reader :forwarded_cookies_whitelist
|
16
|
+
attr_reader :forward_headers
|
17
|
+
attr_reader :allow_blank_referer
|
18
|
+
attr_reader :referer_checks
|
19
|
+
attr_reader :referer_whitelist
|
20
|
+
attr_reader :trusted_signers
|
21
|
+
attr_reader :viewer_protocol_policy
|
22
|
+
attr_reader :min_ttl
|
23
|
+
attr_reader :max_ttl
|
24
|
+
attr_reader :default_ttl
|
25
|
+
attr_reader :smooth_streaming
|
26
|
+
attr_reader :allowed_methods
|
27
|
+
attr_reader :cached_methods
|
28
|
+
attr_reader :compress
|
29
|
+
|
30
|
+
# Public: Constructor
|
31
|
+
#
|
32
|
+
# json - a hash containing the JSON configuration for the distribution cache behavior
|
33
|
+
# default - indicates if the cache configuration is the default config (ignore path_pattern if so)
|
34
|
+
def initialize(json = nil, default = false)
|
35
|
+
if !json.nil?
|
36
|
+
@default = default
|
37
|
+
@path_pattern = json["path-pattern"] if !default
|
38
|
+
@target_origin_id = json["target-origin-id"]
|
39
|
+
@forward_query_strings = json["forward-query-strings"]
|
40
|
+
@forwarded_cookies = json["forwarded-cookies"]
|
41
|
+
@forwarded_cookies_whitelist = json["forwarded-cookies-whitelist"] || []
|
42
|
+
@forward_headers = json["forward-headers"] || []
|
43
|
+
@trusted_signers = json["trusted-signers"] || []
|
44
|
+
@viewer_protocol_policy = json["viewer-protocol-policy"]
|
45
|
+
@min_ttl = json["min-ttl"]
|
46
|
+
@max_ttl = json["max-ttl"]
|
47
|
+
@default_ttl = json["default-ttl"]
|
48
|
+
@smooth_streaming = json["smooth-streaming"]
|
49
|
+
@allowed_methods = json["allowed-methods"] || []
|
50
|
+
@cached_methods = json["cached-methods"] || []
|
51
|
+
@compress = json["compress"] || false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def populate!(aws, default = false)
|
56
|
+
@default = default
|
57
|
+
@path_pattern = aws.path_pattern if !default
|
58
|
+
@target_origin_id = aws.target_origin_id
|
59
|
+
@forward_query_strings = aws.forwarded_values.query_string
|
60
|
+
@forwarded_cookies = aws.forwarded_values.cookies.forward
|
61
|
+
@forwarded_cookies_whitelist = if aws.forwarded_values.cookies.whitelisted_names.nil? then [] else aws.forwarded_values.cookies.whitelisted_names.items end
|
62
|
+
@forward_headers = if aws.forwarded_values.headers.nil? then [] else aws.forwarded_values.headers.items end
|
63
|
+
@trusted_signers = if aws.trusted_signers.enabled then aws.trusted_signers.items else [] end
|
64
|
+
@viewer_protocol_policy = aws.viewer_protocol_policy
|
65
|
+
@min_ttl = aws.min_ttl
|
66
|
+
@max_ttl = aws.max_ttl
|
67
|
+
@default_ttl = aws.default_ttl
|
68
|
+
@smooth_streaming = aws.smooth_streaming
|
69
|
+
@allowed_methods = aws.allowed_methods.items
|
70
|
+
@cached_methods = aws.allowed_methods.cached_methods.items
|
71
|
+
@compress = aws.compress
|
72
|
+
end
|
73
|
+
|
74
|
+
# Public: Get the config as a hash
|
75
|
+
#
|
76
|
+
# Returns the hash
|
77
|
+
def to_local
|
78
|
+
{
|
79
|
+
"path-pattern" => @path_pattern,
|
80
|
+
"target-origin-id" => @target_origin_id,
|
81
|
+
"forward-query-strings" => @forward_query_strings,
|
82
|
+
"forwarded-cookies" => @forwarded_cookies,
|
83
|
+
"forwarded-cookies-whitelist" => @forwarded_cookies_whitelist,
|
84
|
+
"forward-headers" => @forward_headers,
|
85
|
+
"trusted-signers" => @trusted_signers,
|
86
|
+
"viewer-protocol-policy" => @viewer_protocol_policy,
|
87
|
+
"min-ttl" => @min_ttl,
|
88
|
+
"max-ttl" => @max_ttl,
|
89
|
+
"default-ttl" => @default_ttl,
|
90
|
+
"smooth-streaming" => @smooth_streaming,
|
91
|
+
"allowed-methods" => @allowed_methods,
|
92
|
+
"cached-methods" => @cached_methods,
|
93
|
+
"compress" => @compress
|
94
|
+
}.reject { |k, v| v.nil? }
|
95
|
+
end
|
96
|
+
|
97
|
+
# Public: Get the config in the format needed for AWS
|
98
|
+
#
|
99
|
+
# Returns the hash
|
100
|
+
def to_aws
|
101
|
+
{
|
102
|
+
path_pattern: @path_pattern,
|
103
|
+
target_origin_id: @target_origin_id,
|
104
|
+
forwarded_values: {
|
105
|
+
query_string: @forward_query_strings,
|
106
|
+
cookies: {
|
107
|
+
forward: @forwarded_cookies,
|
108
|
+
whitelisted_names: {
|
109
|
+
quantity: @forwarded_cookies_whitelist.size,
|
110
|
+
items: if @forwarded_cookies_whitelist.empty? then nil else @forwarded_cookies_whitelist end
|
111
|
+
}
|
112
|
+
},
|
113
|
+
headers: {
|
114
|
+
quantity: @forward_headers.size,
|
115
|
+
items: if @forward_headers.empty? then nil else @forward_headers end
|
116
|
+
}
|
117
|
+
},
|
118
|
+
trusted_signers: {
|
119
|
+
enabled: !@trusted_signers.empty?,
|
120
|
+
quantity: @trusted_signers.size,
|
121
|
+
items: if @trusted_signers.empty? then nil else @trusted_signers end
|
122
|
+
},
|
123
|
+
viewer_protocol_policy: @viewer_protocol_policy,
|
124
|
+
min_ttl: @min_ttl,
|
125
|
+
max_ttl: @max_ttl,
|
126
|
+
default_ttl: @default_ttl,
|
127
|
+
smooth_streaming: @smooth_streaming,
|
128
|
+
allowed_methods: {
|
129
|
+
quantity: @allowed_methods.size,
|
130
|
+
items: if @allowed_methods.empty? then nil else @allowed_methods end,
|
131
|
+
cached_methods: {
|
132
|
+
quantity: @cached_methods.size,
|
133
|
+
items: if @cached_methods.empty? then nil else @cached_methods end
|
134
|
+
}
|
135
|
+
},
|
136
|
+
compress: @compress
|
137
|
+
}
|
138
|
+
end
|
139
|
+
|
140
|
+
def name
|
141
|
+
if @default
|
142
|
+
"Default Cache"
|
143
|
+
else
|
144
|
+
"#{target_origin_id}/#{path_pattern}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Public: Produce an array of differences between this local configuration and the
|
149
|
+
# configuration in AWS
|
150
|
+
#
|
151
|
+
# aws - the AWS resource
|
152
|
+
#
|
153
|
+
# Returns an array of the CacheBehaviorDiffs that were found
|
154
|
+
def diff(aws)
|
155
|
+
diffs = []
|
156
|
+
|
157
|
+
if !default and @path_pattern != aws.path_pattern
|
158
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::PATH, aws, self)
|
159
|
+
end
|
160
|
+
|
161
|
+
if @target_origin_id != aws.target_origin_id
|
162
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::TARGET, aws, self)
|
163
|
+
end
|
164
|
+
|
165
|
+
if @forward_query_strings != aws.forwarded_values.query_string
|
166
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::QUERY, aws, self)
|
167
|
+
end
|
168
|
+
|
169
|
+
if @forwarded_cookies != aws.forwarded_values.cookies.forward
|
170
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::COOKIES, aws, self)
|
171
|
+
end
|
172
|
+
|
173
|
+
aws_whitelist_cookies = if aws.forwarded_values.cookies.whitelisted_names.nil? then [] else aws.forwarded_values.cookies.whitelisted_names.items end
|
174
|
+
added_cookies = (@forwarded_cookies_whitelist - aws_whitelist_cookies)
|
175
|
+
removed_cookies = (aws_whitelist_cookies - @forwarded_cookies_whitelist)
|
176
|
+
if !added_cookies.empty? or !removed_cookies.empty?
|
177
|
+
diffs << CacheBehaviorDiff.cookies_whitelist(added_cookies, removed_cookies, self)
|
178
|
+
end
|
179
|
+
|
180
|
+
aws_headers = if aws.forwarded_values.headers.nil? then [] else aws.forwarded_values.headers.items end
|
181
|
+
added_headers = (@forward_headers - aws_headers)
|
182
|
+
removed_headers = (aws_headers - @forward_headers)
|
183
|
+
if !added_headers.empty? or !removed_headers.empty?
|
184
|
+
diffs << CacheBehaviorDiff.headers(added_headers, removed_headers, self)
|
185
|
+
end
|
186
|
+
|
187
|
+
aws_signers = if !aws.trusted_signers.enabled then [] else aws.trusted_signers.items end
|
188
|
+
added_signers = (@trusted_signers - aws_signers)
|
189
|
+
removed_signers = (aws_signers - @trusted_signers)
|
190
|
+
if !added_signers.empty? or !removed_signers.empty?
|
191
|
+
diffs << CacheBehaviorDiff.signers(added_signers, removed_signers, self)
|
192
|
+
end
|
193
|
+
|
194
|
+
if @viewer_protocol_policy != aws.viewer_protocol_policy
|
195
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::VIEWER_PROTOCOL, aws, self)
|
196
|
+
end
|
197
|
+
|
198
|
+
if @min_ttl != aws.min_ttl
|
199
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::MINTTL, aws, self)
|
200
|
+
end
|
201
|
+
|
202
|
+
if @max_ttl != aws.max_ttl
|
203
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::MAXTTL, aws, self)
|
204
|
+
end
|
205
|
+
|
206
|
+
if @default_ttl != aws.default_ttl
|
207
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::DEFTTL, aws, self)
|
208
|
+
end
|
209
|
+
|
210
|
+
if @smooth_streaming != aws.smooth_streaming
|
211
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::STREAMING, aws, self)
|
212
|
+
end
|
213
|
+
|
214
|
+
aws_allowed_methods = if aws.allowed_methods.nil? then [] else aws.allowed_methods.items end
|
215
|
+
added_allowed_methods = (@allowed_methods - aws_allowed_methods)
|
216
|
+
removed_allowed_methods = (aws_allowed_methods - @allowed_methods)
|
217
|
+
if !added_allowed_methods.empty? or !removed_allowed_methods.empty?
|
218
|
+
diffs << CacheBehaviorDiff.allowed_methods(added_allowed_methods, removed_allowed_methods, self)
|
219
|
+
end
|
220
|
+
|
221
|
+
aws_cached_methods = if aws.allowed_methods.nil? or aws.allowed_methods.cached_methods.nil? then [] else aws.allowed_methods.cached_methods.items end
|
222
|
+
added_cached_methods = (@cached_methods - aws_cached_methods)
|
223
|
+
removed_cached_methods = (aws_cached_methods - @cached_methods)
|
224
|
+
if !added_cached_methods.empty? or !removed_cached_methods.empty?
|
225
|
+
diffs << CacheBehaviorDiff.cached_methods(added_cached_methods, removed_cached_methods, self)
|
226
|
+
end
|
227
|
+
|
228
|
+
if @compress != aws.compress
|
229
|
+
diffs << CacheBehaviorDiff.new(CacheBehaviorChange::COMPRESS, aws, self)
|
230
|
+
end
|
231
|
+
|
232
|
+
diffs
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|