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,211 @@
|
|
1
|
+
require "common/models/Diff"
|
2
|
+
require "common/models/ListChange"
|
3
|
+
require "util/Colors"
|
4
|
+
|
5
|
+
module Cumulus
|
6
|
+
module CloudFront
|
7
|
+
|
8
|
+
# Public: The types of changes that can be made to cache behaviors
|
9
|
+
module CacheBehaviorChange
|
10
|
+
include Common::DiffChange
|
11
|
+
|
12
|
+
PATH = Common::DiffChange::next_change_id
|
13
|
+
TARGET = Common::DiffChange::next_change_id
|
14
|
+
QUERY = Common::DiffChange::next_change_id
|
15
|
+
COOKIES = Common::DiffChange::next_change_id
|
16
|
+
COOKIES_WHITELIST = Common::DiffChange::next_change_id
|
17
|
+
HEADERS = Common::DiffChange::next_change_id
|
18
|
+
SIGNERS = Common::DiffChange::next_change_id
|
19
|
+
VIEWER_PROTOCOL = Common::DiffChange::next_change_id
|
20
|
+
MINTTL = Common::DiffChange::next_change_id
|
21
|
+
MAXTTL = Common::DiffChange::next_change_id
|
22
|
+
DEFTTL = Common::DiffChange::next_change_id
|
23
|
+
STREAMING = Common::DiffChange::next_change_id
|
24
|
+
METHODS_ALLOWED = Common::DiffChange::next_change_id
|
25
|
+
METHODS_CACHED = Common::DiffChange::next_change_id
|
26
|
+
COMPRESS = Common::DiffChange::next_change_id
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Represents a single difference between local configuration and AWS
|
30
|
+
# configuration of zones.
|
31
|
+
class CacheBehaviorDiff < Common::Diff
|
32
|
+
include CacheBehaviorChange
|
33
|
+
|
34
|
+
attr_accessor :cookies
|
35
|
+
attr_accessor :headers
|
36
|
+
attr_accessor :signers
|
37
|
+
attr_accessor :allowed_methods
|
38
|
+
attr_accessor :cached_methods
|
39
|
+
|
40
|
+
# Public: Static method that produces a diff representing changes in CacheBehavior cookies whitelist
|
41
|
+
#
|
42
|
+
# added_cookies - the cookies that were added
|
43
|
+
# removed_cookies - the cookies that were removed
|
44
|
+
# local - the local configuration for the zone
|
45
|
+
#
|
46
|
+
# Returns the diff
|
47
|
+
def self.cookies_whitelist(added_cookies, removed_cookies, local)
|
48
|
+
diff = CacheBehaviorDiff.new(COOKIES_WHITELIST, nil, local)
|
49
|
+
diff.cookies = Common::ListChange.new(added_cookies, removed_cookies)
|
50
|
+
diff
|
51
|
+
end
|
52
|
+
|
53
|
+
# Public: Static method that produces a diff representing changes in CacheBehavior headers
|
54
|
+
#
|
55
|
+
# added_headers - the headers that were added
|
56
|
+
# removed_headers - the headers that were removed
|
57
|
+
# local - the local configuration for the zone
|
58
|
+
#
|
59
|
+
# Returns the diff
|
60
|
+
def self.headers(added_headers, removed_headers, local)
|
61
|
+
diff = CacheBehaviorDiff.new(HEADERS, nil, local)
|
62
|
+
diff.headers = Common::ListChange.new(added_headers, removed_headers)
|
63
|
+
diff
|
64
|
+
end
|
65
|
+
|
66
|
+
# Public: Static method that produces a diff representing changes in CacheBehavior trusted signers
|
67
|
+
#
|
68
|
+
# added_signers - the trusted signers that were added
|
69
|
+
# removed_signers - the trusted signers that were removed
|
70
|
+
# local - the local configuration for the zone
|
71
|
+
#
|
72
|
+
# Returns the diff
|
73
|
+
def self.signers(added_signers, removed_signers, local)
|
74
|
+
diff = CacheBehaviorDiff.new(SIGNERS, nil, local)
|
75
|
+
diff.signers = Common::ListChange.new(added_signers, removed_signers)
|
76
|
+
diff
|
77
|
+
end
|
78
|
+
|
79
|
+
# Public: Static method that produces a diff representing changes in CacheBehavior allowed methods
|
80
|
+
#
|
81
|
+
# added_allowed_methods - the allowed methods that were added
|
82
|
+
# removed_allowed_methods - the allowed methods that were removed
|
83
|
+
# local - the local configuration for the zone
|
84
|
+
#
|
85
|
+
# Returns the diff
|
86
|
+
def self.allowed_methods(added_allowed_methods, removed_allowed_methods, local)
|
87
|
+
diff = CacheBehaviorDiff.new(METHODS_ALLOWED, nil, local)
|
88
|
+
diff.allowed_methods = Common::ListChange.new(added_allowed_methods, removed_allowed_methods)
|
89
|
+
diff
|
90
|
+
end
|
91
|
+
|
92
|
+
# Public: Static method that produces a diff representing changes in CacheBehavior cached methods
|
93
|
+
#
|
94
|
+
# added_cached_methods - the cached methods that were added
|
95
|
+
# removed_cached_methods - the cached methods that were removed
|
96
|
+
# local - the local configuration for the zone
|
97
|
+
#
|
98
|
+
# Returns the diff
|
99
|
+
def self.cached_methods(added_cached_methods, removed_cached_methods, local)
|
100
|
+
diff = CacheBehaviorDiff.new(METHODS_CACHED, nil, local)
|
101
|
+
diff.cached_methods = Common::ListChange.new(added_cached_methods, removed_cached_methods)
|
102
|
+
diff
|
103
|
+
end
|
104
|
+
|
105
|
+
def diff_string
|
106
|
+
case @type
|
107
|
+
when PATH
|
108
|
+
[
|
109
|
+
"path:",
|
110
|
+
Colors.aws_changes("\tAWS - #{@aws.path_pattern}"),
|
111
|
+
Colors.local_changes("\tLocal - #{@local.path_pattern}"),
|
112
|
+
].join("\n")
|
113
|
+
when TARGET
|
114
|
+
[
|
115
|
+
"target origin id:",
|
116
|
+
Colors.aws_changes("\tAWS - #{@aws.target_origin_id}"),
|
117
|
+
Colors.local_changes("\tLocal - #{@local.target_origin_id}"),
|
118
|
+
].join("\n")
|
119
|
+
when QUERY
|
120
|
+
[
|
121
|
+
"forward query strings:",
|
122
|
+
Colors.aws_changes("\tAWS - #{@aws.forwarded_values.query_string}"),
|
123
|
+
Colors.local_changes("\tLocal - #{@local.forward_query_strings}"),
|
124
|
+
].join("\n")
|
125
|
+
when COOKIES
|
126
|
+
[
|
127
|
+
"forwarded cookies:",
|
128
|
+
Colors.aws_changes("\tAWS - #{@aws.forwarded_values.cookies.forward}"),
|
129
|
+
Colors.local_changes("\tLocal - #{@local.forwarded_cookies}"),
|
130
|
+
].join("\n")
|
131
|
+
when COOKIES_WHITELIST
|
132
|
+
[
|
133
|
+
"whitelisted forwarded cookies:",
|
134
|
+
cookies.removed.map{ |removed| Colors.removed("\t#{removed}")},
|
135
|
+
cookies.added.map{ |added| Colors.added("\t#{added}")},
|
136
|
+
].flatten.join("\n")
|
137
|
+
when HEADERS
|
138
|
+
[
|
139
|
+
"forwarded headers:",
|
140
|
+
headers.removed.map{ |removed| Colors.removed("\t#{removed}")},
|
141
|
+
headers.added.map{ |added| Colors.added("\t#{added}")},
|
142
|
+
].flatten.join("\n")
|
143
|
+
when SIGNERS
|
144
|
+
[
|
145
|
+
"trusted signers:",
|
146
|
+
signers.removed.map{ |removed| Colors.removed("\t#{removed}")},
|
147
|
+
signers.added.map{ |added| Colors.added("\t#{added}")},
|
148
|
+
].flatten.join("\n")
|
149
|
+
when VIEWER_PROTOCOL
|
150
|
+
[
|
151
|
+
"viewer protocol policy:",
|
152
|
+
Colors.aws_changes("\tAWS - #{@aws.viewer_protocol_policy}"),
|
153
|
+
Colors.local_changes("\tLocal - #{@local.viewer_protocol_policy}"),
|
154
|
+
].join("\n")
|
155
|
+
when MINTTL
|
156
|
+
[
|
157
|
+
"min ttl:",
|
158
|
+
Colors.aws_changes("\tAWS - #{@aws.min_ttl}"),
|
159
|
+
Colors.local_changes("\tLocal - #{@local.min_ttl}"),
|
160
|
+
].join("\n")
|
161
|
+
when MAXTTL
|
162
|
+
[
|
163
|
+
"max ttl:",
|
164
|
+
Colors.aws_changes("\tAWS - #{@aws.max_ttl}"),
|
165
|
+
Colors.local_changes("\tLocal - #{@local.max_ttl}"),
|
166
|
+
].join("\n")
|
167
|
+
when DEFTTL
|
168
|
+
[
|
169
|
+
"default ttl:",
|
170
|
+
Colors.aws_changes("\tAWS - #{@aws.default_ttl}"),
|
171
|
+
Colors.local_changes("\tLocal - #{@local.default_ttl}"),
|
172
|
+
].join("\n")
|
173
|
+
when STREAMING
|
174
|
+
[
|
175
|
+
"smooth streaming:",
|
176
|
+
Colors.aws_changes("\tAWS - #{@aws.smooth_streaming}"),
|
177
|
+
Colors.local_changes("\tLocal - #{@local.smooth_streaming}"),
|
178
|
+
].join("\n")
|
179
|
+
when METHODS_ALLOWED
|
180
|
+
[
|
181
|
+
"allowed methods:",
|
182
|
+
allowed_methods.removed.map{ |removed| Colors.removed("\t#{removed}")},
|
183
|
+
allowed_methods.added.map{ |added| Colors.added("\t#{added}")},
|
184
|
+
].flatten.join("\n")
|
185
|
+
when METHODS_CACHED
|
186
|
+
[
|
187
|
+
"cached methods:",
|
188
|
+
cached_methods.removed.map{ |removed| Colors.removed("\t#{removed}")},
|
189
|
+
cached_methods.added.map{ |added| Colors.added("\t#{added}")},
|
190
|
+
].flatten.join("\n")
|
191
|
+
when COMPRESS
|
192
|
+
[
|
193
|
+
"compress:",
|
194
|
+
Colors.aws_changes("\tAWS - #{@aws.compress}"),
|
195
|
+
Colors.local_changes("\tLocal - #{@local.compress}"),
|
196
|
+
].join("\n")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def asset_type
|
201
|
+
"Cache Behavior"
|
202
|
+
end
|
203
|
+
|
204
|
+
def aws_name
|
205
|
+
"#{@aws.target_origin_id}/#{@aws.path_pattern}"
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "cloudfront/models/CustomOriginDiff"
|
2
|
+
|
3
|
+
module Cumulus
|
4
|
+
module CloudFront
|
5
|
+
CustomOriginConfig = Struct.new(:http_port, :https_port, :protocol_policy, :origin_ssl_protocols) do
|
6
|
+
|
7
|
+
def diff(aws)
|
8
|
+
diffs = []
|
9
|
+
|
10
|
+
aws_http_port = aws && aws.http_port
|
11
|
+
if self.http_port != aws_http_port
|
12
|
+
diffs << CustomOriginDiff.new(CustomOriginChange::HTTP, aws_http_port, self.http_port)
|
13
|
+
end
|
14
|
+
|
15
|
+
aws_https_port = aws && aws.https_port
|
16
|
+
if self.https_port != aws_https_port
|
17
|
+
diffs << CustomOriginDiff.new(CustomOriginChange::HTTPS, aws_https_port, self.https_port)
|
18
|
+
end
|
19
|
+
|
20
|
+
aws_protocol = aws && aws.origin_protocol_policy
|
21
|
+
if self.protocol_policy != aws_protocol
|
22
|
+
diffs << CustomOriginDiff.new(CustomOriginChange::POLICY, aws_protocol, self.protocol_policy)
|
23
|
+
end
|
24
|
+
|
25
|
+
if self.origin_ssl_protocols
|
26
|
+
ssl_protocol_diffs = self.origin_ssl_protocols.diff(aws.origin_ssl_protocols)
|
27
|
+
else
|
28
|
+
if aws.origin_ssl_protocols && aws.origin_protocol_policy != "http-only"
|
29
|
+
ssl_protocol_diffs = OriginSslProtocols.new([]).diff(aws.origin_ssl_protocols)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
if ssl_protocol_diffs && ssl_protocol_diffs.length > 0
|
33
|
+
diffs << CustomOriginDiff.ssl_protocols(ssl_protocol_diffs, aws, self)
|
34
|
+
end
|
35
|
+
|
36
|
+
diffs
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_local
|
40
|
+
{
|
41
|
+
"http-port" => self.http_port,
|
42
|
+
"https-port" => self.https_port,
|
43
|
+
"protocol-policy" => self.protocol_policy,
|
44
|
+
"origin-ssl-protocols" => if self.origin_ssl_protocols
|
45
|
+
self.origin_ssl_protocols.to_local
|
46
|
+
end
|
47
|
+
}.reject { |k, v| v.nil? }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "common/models/Diff"
|
2
|
+
require "util/Colors"
|
3
|
+
|
4
|
+
module Cumulus
|
5
|
+
module CloudFront
|
6
|
+
|
7
|
+
# Public: The types of changes that can be made to zones
|
8
|
+
module CustomOriginChange
|
9
|
+
include Common::DiffChange
|
10
|
+
|
11
|
+
HTTP = Common::DiffChange::next_change_id
|
12
|
+
HTTPS = Common::DiffChange::next_change_id
|
13
|
+
POLICY = Common::DiffChange::next_change_id
|
14
|
+
SSL_PROTOCOLS = Common::DiffChange::next_change_id
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Represents a single difference between local configuration and AWS
|
18
|
+
# configuration of zones.
|
19
|
+
class CustomOriginDiff < Common::Diff
|
20
|
+
include CustomOriginChange
|
21
|
+
|
22
|
+
attr_accessor :ssl_protocol_changes
|
23
|
+
|
24
|
+
# Public: Static method that produces a diff representing changes in ssl protocols
|
25
|
+
#
|
26
|
+
# changes - the OriginSslProtocolsDiffs
|
27
|
+
# aws - the aws configuration for the custom origin
|
28
|
+
# local - the local configuration for the custom origin
|
29
|
+
#
|
30
|
+
# Returns the diff containing those changes
|
31
|
+
def self.ssl_protocols(changes, aws, local)
|
32
|
+
diff = CustomOriginDiff.new(SSL_PROTOCOLS, aws, local)
|
33
|
+
diff.ssl_protocol_changes = changes
|
34
|
+
diff
|
35
|
+
end
|
36
|
+
|
37
|
+
def diff_string
|
38
|
+
case @type
|
39
|
+
when HTTP
|
40
|
+
[
|
41
|
+
"http port:",
|
42
|
+
Colors.aws_changes("\tAWS - #{@aws}"),
|
43
|
+
Colors.local_changes("\tLocal - #{@local}"),
|
44
|
+
].join("\n")
|
45
|
+
when HTTPS
|
46
|
+
[
|
47
|
+
"https port:",
|
48
|
+
Colors.aws_changes("\tAWS - #{@aws}"),
|
49
|
+
Colors.local_changes("\tLocal - #{@local}"),
|
50
|
+
].join("\n")
|
51
|
+
when POLICY
|
52
|
+
[
|
53
|
+
"protocol policy:",
|
54
|
+
Colors.aws_changes("\tAWS - #{@aws}"),
|
55
|
+
Colors.local_changes("\tLocal - #{@local}"),
|
56
|
+
].join("\n")
|
57
|
+
when SSL_PROTOCOLS
|
58
|
+
[
|
59
|
+
"origin ssl protocols:",
|
60
|
+
(@ssl_protocol_changes.flat_map do |c|
|
61
|
+
c.to_s.lines.map { |l| "\t#{l.chomp}" }
|
62
|
+
end).join("\n"),
|
63
|
+
].join("\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def aws_name
|
68
|
+
@aws.id
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require "conf/Configuration"
|
2
|
+
require "cloudfront/models/DistributionDiff"
|
3
|
+
require "cloudfront/models/OriginConfig"
|
4
|
+
require "cloudfront/models/CacheBehaviorConfig"
|
5
|
+
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
module Cumulus
|
9
|
+
module CloudFront
|
10
|
+
# Public: An object representing configuration for a distribution
|
11
|
+
class DistributionConfig
|
12
|
+
attr_accessor :id
|
13
|
+
attr_reader :name
|
14
|
+
attr_reader :aliases
|
15
|
+
attr_reader :origins
|
16
|
+
attr_reader :default_cache_behavior
|
17
|
+
attr_reader :cache_behaviors
|
18
|
+
attr_reader :comment
|
19
|
+
attr_reader :enabled
|
20
|
+
|
21
|
+
# Public: Constructor
|
22
|
+
#
|
23
|
+
# json - a hash containing the JSON configuration for the distribution
|
24
|
+
def initialize(name, json = nil)
|
25
|
+
@name = name
|
26
|
+
if !json.nil?
|
27
|
+
@id = json["id"]
|
28
|
+
@aliases = json["aliases"] || []
|
29
|
+
@origins = json["origins"].map { |o| OriginConfig.new(o) }
|
30
|
+
@default_cache_behavior = CacheBehaviorConfig.new(json["default-cache-behavior"], true)
|
31
|
+
@cache_behaviors = (json["cache-behaviors"] || []).map { |cb| CacheBehaviorConfig.new(cb) }
|
32
|
+
@comment = json["comment"]
|
33
|
+
@enabled = json["enabled"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def populate!(id, aws)
|
38
|
+
@id = id
|
39
|
+
@name = id
|
40
|
+
@aliases = aws.aliases.items
|
41
|
+
@origins = aws.origins.items.map do |origin|
|
42
|
+
config = OriginConfig.new()
|
43
|
+
config.populate!(origin)
|
44
|
+
config
|
45
|
+
end
|
46
|
+
@default_cache_behavior = CacheBehaviorConfig.new()
|
47
|
+
@default_cache_behavior.populate!(aws.default_cache_behavior, true)
|
48
|
+
@cache_behaviors = aws.cache_behaviors.items.map do |cache_behavior|
|
49
|
+
config = CacheBehaviorConfig.new()
|
50
|
+
config.populate!(cache_behavior)
|
51
|
+
config
|
52
|
+
end
|
53
|
+
@comment = aws.comment
|
54
|
+
@enabled = aws.enabled
|
55
|
+
end
|
56
|
+
|
57
|
+
# Public: Get the config as a prettified JSON string.
|
58
|
+
#
|
59
|
+
# Returns the JSON string
|
60
|
+
def pretty_json
|
61
|
+
JSON.pretty_generate({
|
62
|
+
"id" => @id,
|
63
|
+
"aliases" => @aliases,
|
64
|
+
"origins" => @origins.map(&:to_local),
|
65
|
+
"default-cache-behavior" => @default_cache_behavior.to_local,
|
66
|
+
"cache-behaviors" => @cache_behaviors.map(&:to_local),
|
67
|
+
"comment" => @comment,
|
68
|
+
"enabled" => @enabled,
|
69
|
+
})
|
70
|
+
end
|
71
|
+
|
72
|
+
# Public: Produce an array of differences between this local configuration and the
|
73
|
+
# configuration in AWS
|
74
|
+
#
|
75
|
+
# aws - the AWS resource
|
76
|
+
#
|
77
|
+
# Returns an array of the DistributionDiffs that were found
|
78
|
+
def diff(aws)
|
79
|
+
diffs = []
|
80
|
+
|
81
|
+
added_aliases = (@aliases - aws.aliases.items)
|
82
|
+
removed_aliases = aws.aliases.items - @aliases
|
83
|
+
if !added_aliases.empty? or !removed_aliases.empty?
|
84
|
+
diffs << DistributionDiff.aliases(added_aliases, removed_aliases, self)
|
85
|
+
end
|
86
|
+
|
87
|
+
origin_diffs = diff_origins(aws.origins.items)
|
88
|
+
if !origin_diffs.empty?
|
89
|
+
diffs << DistributionDiff.origins(origin_diffs, self)
|
90
|
+
end
|
91
|
+
|
92
|
+
default_cache_diffs = @default_cache_behavior.diff(aws.default_cache_behavior)
|
93
|
+
if !default_cache_diffs.empty?
|
94
|
+
diffs << DistributionDiff.default_cache(default_cache_diffs, self)
|
95
|
+
end
|
96
|
+
|
97
|
+
diffs << diff_caches(aws)
|
98
|
+
|
99
|
+
if @comment != aws.comment
|
100
|
+
diffs << DistributionDiff.new(DistributionChange::COMMENT, aws, self)
|
101
|
+
end
|
102
|
+
|
103
|
+
if @enabled != aws.enabled
|
104
|
+
diffs << DistributionDiff.new(DistributionChange::ENABLED, aws, self)
|
105
|
+
end
|
106
|
+
|
107
|
+
diffs.flatten
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
# Internal: Produce an array of differences between the local origins and the aws origins
|
113
|
+
#
|
114
|
+
# aws_origins - the AWS origins from a cloudfront config
|
115
|
+
#
|
116
|
+
# Returns an array of OriginDiffs that were found
|
117
|
+
def diff_origins(aws_origins)
|
118
|
+
diffs = []
|
119
|
+
|
120
|
+
# map the origins to their keys
|
121
|
+
aws = Hash[aws_origins.map { |o| [o.id, o] }]
|
122
|
+
local = Hash[@origins.map { |o| [o.id, o] }]
|
123
|
+
|
124
|
+
# find origins that are not configured locally
|
125
|
+
aws.each do |origin_id, origin|
|
126
|
+
if !local.include?(origin_id)
|
127
|
+
diffs << OriginDiff.unmanaged(origin)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
local.each do |origin_id, origin|
|
132
|
+
if !aws.include?(origin_id)
|
133
|
+
diffs << OriginDiff.added(origin)
|
134
|
+
else
|
135
|
+
diffs << origin.diff(aws[origin_id])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
diffs.flatten
|
140
|
+
end
|
141
|
+
|
142
|
+
# Internal: Produce an array of differences between local cache behaviors and aws cache behaviors
|
143
|
+
#
|
144
|
+
# aws - the AWS config
|
145
|
+
#
|
146
|
+
# Returns an array of CacheBehaviorDiff
|
147
|
+
def diff_caches(aws)
|
148
|
+
removed = []
|
149
|
+
added = []
|
150
|
+
changed = Hash.new
|
151
|
+
|
152
|
+
aws_cache_behaviors = if aws.cache_behaviors.nil? then [] else aws.cache_behaviors.items end
|
153
|
+
|
154
|
+
aws = Hash[aws_cache_behaviors.map { |c| ["#{c.target_origin_id}/#{c.path_pattern}", c]}]
|
155
|
+
local = Hash[@cache_behaviors.map { |c| ["#{c.target_origin_id}/#{c.path_pattern}", c]}]
|
156
|
+
|
157
|
+
# find cache behaviors that are not configured locally
|
158
|
+
aws.each do |cache_id, cache|
|
159
|
+
if !local.include?(cache_id)
|
160
|
+
removed << CacheBehaviorDiff.unmanaged(cache)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
local.each do |cache_id, cache|
|
165
|
+
if !aws.include?(cache_id)
|
166
|
+
added << CacheBehaviorDiff.added(cache)
|
167
|
+
else
|
168
|
+
diffs = cache.diff(aws[cache_id])
|
169
|
+
changed[cache_id] = diffs if !diffs.empty?
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
if !removed.empty? or !added.empty? or !changed.empty?
|
174
|
+
DistributionDiff.caches(removed, added, changed, self)
|
175
|
+
else
|
176
|
+
[]
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|