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,157 @@
|
|
1
|
+
require "lambda/Lambda"
|
2
|
+
require "s3/models/NotificationDiff"
|
3
|
+
require "sns/SNS"
|
4
|
+
require "sqs/SQS"
|
5
|
+
|
6
|
+
module Cumulus
|
7
|
+
module S3
|
8
|
+
class NotificationConfig
|
9
|
+
attr_reader :name
|
10
|
+
attr_reader :prefix
|
11
|
+
attr_reader :suffix
|
12
|
+
attr_reader :target
|
13
|
+
attr_reader :triggers
|
14
|
+
attr_reader :type
|
15
|
+
|
16
|
+
# Public: Constructor
|
17
|
+
#
|
18
|
+
# json - a hash representing the JSON configuration. Expects to be passed
|
19
|
+
# an object from the "notifications" array of S3 bucket configuration.
|
20
|
+
def initialize(json = nil)
|
21
|
+
if json
|
22
|
+
@name = json["name"]
|
23
|
+
@prefix = json["prefix"]
|
24
|
+
@suffix = json["suffix"]
|
25
|
+
@target = json["target"]
|
26
|
+
@triggers = (json["triggers"] || []).map { |t| "s3:#{t}" }
|
27
|
+
@type = json["type"]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Public: Populate this NotificationConfig with the values in an AWS configuration
|
32
|
+
# of events.
|
33
|
+
#
|
34
|
+
# aws - the aws object to populate from
|
35
|
+
def populate!(aws)
|
36
|
+
@name = aws.id
|
37
|
+
@prefix = aws.filter.key.filter_rules.find { |r| r.name.downcase == "prefix" }.value rescue nil
|
38
|
+
@suffix = aws.filter.key.filter_rules.find { |r| r.name.downcase == "suffix" }.value rescue nil
|
39
|
+
@triggers = aws.events
|
40
|
+
if aws.respond_to? "queue_arn"
|
41
|
+
@type = "sqs"
|
42
|
+
@target = aws.queue_arn[(aws.queue_arn.rindex(":") + 1)..-1]
|
43
|
+
elsif aws.respond_to? "lambda_function_arn"
|
44
|
+
@type = "lambda"
|
45
|
+
@target = aws.lambda_function_arn[(aws.lambda_function_arn.rindex(":") + 1)..-1]
|
46
|
+
else
|
47
|
+
@type = "sns"
|
48
|
+
@target = aws.topic_arn[(aws.topic_arn.rindex(":") + 1)..-1]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Public: Produce an AWS compatible hash for this NotificationConfig.
|
53
|
+
#
|
54
|
+
# Returns the hash.
|
55
|
+
def to_aws
|
56
|
+
if @type == "sns"
|
57
|
+
topic_arn = SNS.get_aws(@target)
|
58
|
+
elsif @type == "sqs"
|
59
|
+
queue_arn = SQS.get_arn(@target)
|
60
|
+
elsif @type == "lambda"
|
61
|
+
lambda_function_arn = Lambda.get_aws(@target).function_arn
|
62
|
+
end
|
63
|
+
{
|
64
|
+
id: @name,
|
65
|
+
events: @triggers,
|
66
|
+
topic_arn: topic_arn,
|
67
|
+
queue_arn: queue_arn,
|
68
|
+
lambda_function_arn: lambda_function_arn,
|
69
|
+
filter: {
|
70
|
+
key: {
|
71
|
+
filter_rules: [
|
72
|
+
if @prefix then {
|
73
|
+
name: "prefix",
|
74
|
+
value: @prefix
|
75
|
+
} end,
|
76
|
+
if @suffix then {
|
77
|
+
name: "suffix",
|
78
|
+
value: @suffix
|
79
|
+
} end
|
80
|
+
].reject { |e| e.nil? }
|
81
|
+
}.reject { |k, v| v.nil? or v.empty? }
|
82
|
+
}.reject { |k, v| v.nil? or v.empty? }
|
83
|
+
}.reject { |k, v| v.nil? or v.empty? }
|
84
|
+
end
|
85
|
+
|
86
|
+
# Public: Produce an AWS compatible hash for this NotificationConfig.
|
87
|
+
#
|
88
|
+
# Returns the hash
|
89
|
+
def to_h
|
90
|
+
{
|
91
|
+
name: @name,
|
92
|
+
triggers: @triggers.map { |t| t[3..-1] }, # substring off the "s3:"
|
93
|
+
prefix: @prefix,
|
94
|
+
suffix: @suffix,
|
95
|
+
type: @type,
|
96
|
+
target: @target,
|
97
|
+
}.reject { |k, v| v.nil? }
|
98
|
+
end
|
99
|
+
|
100
|
+
# Public: Produce an array of differences between this local configuration
|
101
|
+
# and the configuration in AWS
|
102
|
+
#
|
103
|
+
# aws - the AWS resource
|
104
|
+
#
|
105
|
+
# Returns an array of the NotificationDiffs that were found
|
106
|
+
def diff(aws)
|
107
|
+
diffs = []
|
108
|
+
|
109
|
+
if @prefix != aws.prefix
|
110
|
+
diffs << NotificationDiff.new(NotificationChange::PREFIX, aws, self)
|
111
|
+
end
|
112
|
+
if @suffix != aws.suffix
|
113
|
+
diffs << NotificationDiff.new(NotificationChange::SUFFIX, aws, self)
|
114
|
+
end
|
115
|
+
if @triggers.sort != aws.triggers.sort
|
116
|
+
diffs << NotificationDiff.new(NotificationChange::TRIGGERS, aws, self)
|
117
|
+
end
|
118
|
+
if @type != aws.type
|
119
|
+
diffs << NotificationDiff.new(NotificationChange::TYPE, aws, self)
|
120
|
+
end
|
121
|
+
if @target != aws.target
|
122
|
+
diffs << NotificationDiff.new(NotificationChange::TARGET, aws, self)
|
123
|
+
end
|
124
|
+
|
125
|
+
diffs
|
126
|
+
end
|
127
|
+
|
128
|
+
# Public: Check NotificationConfig equality with other objects.
|
129
|
+
#
|
130
|
+
# other - the other object to check
|
131
|
+
#
|
132
|
+
# Returns whether this NotificationConfig is equal to `other`
|
133
|
+
def ==(other)
|
134
|
+
if !other.is_a? NotificationConfig or
|
135
|
+
@name != other.name or
|
136
|
+
@prefix != other.prefix or
|
137
|
+
@suffix != other.suffix or
|
138
|
+
@target != other.target or
|
139
|
+
@triggers.sort != other.triggers.sort or
|
140
|
+
@type != other.type
|
141
|
+
false
|
142
|
+
else
|
143
|
+
true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Public: Check if this NotificationConfig is not equal to the other object
|
148
|
+
#
|
149
|
+
# other - the other object to check
|
150
|
+
#
|
151
|
+
# Returns whether this NotificationConfig is not equal to `other`
|
152
|
+
def !=(other)
|
153
|
+
!(self == other)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "common/models/Diff"
|
2
|
+
require "common/models/ListChange"
|
3
|
+
require "util/Colors"
|
4
|
+
|
5
|
+
module Cumulus
|
6
|
+
module S3
|
7
|
+
# Public: The types of changes that can be made to an S3 Notification
|
8
|
+
module NotificationChange
|
9
|
+
include Common::DiffChange
|
10
|
+
|
11
|
+
PREFIX = Common::DiffChange.next_change_id
|
12
|
+
SUFFIX = Common::DiffChange.next_change_id
|
13
|
+
TRIGGERS = Common::DiffChange.next_change_id
|
14
|
+
TYPE = Common::DiffChange.next_change_id
|
15
|
+
TARGET = Common::DiffChange.next_change_id
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Represents a single difference between local configuration and AWS
|
19
|
+
# S3 Notification configuration
|
20
|
+
class NotificationDiff < Common::Diff
|
21
|
+
include NotificationChange
|
22
|
+
|
23
|
+
def initialize(type, aws = nil, local = nil)
|
24
|
+
super(type, aws, local)
|
25
|
+
|
26
|
+
if aws and local
|
27
|
+
@triggers = Common::ListChange.new(
|
28
|
+
local.triggers - aws.triggers,
|
29
|
+
aws.triggers - local.triggers
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def asset_type
|
35
|
+
"Notification"
|
36
|
+
end
|
37
|
+
|
38
|
+
def aws_name
|
39
|
+
@aws.name
|
40
|
+
end
|
41
|
+
|
42
|
+
def diff_string
|
43
|
+
case @type
|
44
|
+
when PREFIX
|
45
|
+
"Prefix: AWS - #{Colors.aws_changes(@aws.prefix)}, Local - #{Colors.local_changes(@local.prefix)}"
|
46
|
+
when SUFFIX
|
47
|
+
"Suffix: AWS - #{Colors.aws_changes(@aws.suffix)}, Local - #{Colors.local_changes(@local.suffix)}"
|
48
|
+
when TRIGGERS
|
49
|
+
[
|
50
|
+
"Triggers:",
|
51
|
+
@triggers.removed.map { |t| Colors.removed("\t#{t}") },
|
52
|
+
@triggers.added.map { |t| Colors.added("\t#{t}") },
|
53
|
+
].flatten.join("\n")
|
54
|
+
when TYPE
|
55
|
+
"Type: AWS - #{Colors.aws_changes(@aws.type)}, Local - #{Colors.local_changes(@local.type)}"
|
56
|
+
when TARGET
|
57
|
+
"Target: AWS - #{Colors.aws_changes(@aws.target)}, Local - #{Colors.local_changes(@local.target)}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require "s3/models/ReplicationDiff"
|
2
|
+
require "iam/IAM"
|
3
|
+
require "util/Colors"
|
4
|
+
|
5
|
+
module Cumulus
|
6
|
+
module S3
|
7
|
+
class ReplicationConfig
|
8
|
+
attr_reader :destination
|
9
|
+
attr_reader :iam_role
|
10
|
+
attr_reader :prefixes
|
11
|
+
|
12
|
+
# Public: Constructor
|
13
|
+
#
|
14
|
+
# json - a hash representing the JSON configuration. Expects to be passed
|
15
|
+
# the "replication" node of S3 bucket configuration.
|
16
|
+
def initialize(json = nil)
|
17
|
+
if json
|
18
|
+
@destination = json["destination"]
|
19
|
+
@iam_role = json["iam-role"]
|
20
|
+
@prefixes = json["prefixes"] || []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Public: Produce an AWS hash representing this ReplicationConfig
|
25
|
+
#
|
26
|
+
# Returns the hash
|
27
|
+
def to_aws
|
28
|
+
role_arn = IAM.get_role_arn(@iam_role)
|
29
|
+
if role_arn.nil?
|
30
|
+
puts Colors.red("No IAM role named #{name}")
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
{
|
35
|
+
role: role_arn,
|
36
|
+
rules: if @prefixes.empty?
|
37
|
+
[{
|
38
|
+
prefix: "",
|
39
|
+
status: "Enabled",
|
40
|
+
destination: {
|
41
|
+
bucket: "arn:aws:s3:::#{@destination}"
|
42
|
+
}
|
43
|
+
}]
|
44
|
+
else
|
45
|
+
@prefixes.map do |prefix|
|
46
|
+
{
|
47
|
+
prefix: prefix,
|
48
|
+
status: "Enabled",
|
49
|
+
destination: {
|
50
|
+
bucket: "arn:aws:s3:::#{@destination}"
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
# Public: Converts this ReplicationConfig to a hash that matches Cumulus
|
59
|
+
# configuration.
|
60
|
+
#
|
61
|
+
# Returns the hash
|
62
|
+
def to_h
|
63
|
+
{
|
64
|
+
"iam-role" => @iam_role,
|
65
|
+
"prefixes" => if !@prefixes.empty? then @prefixes end,
|
66
|
+
"destination" => @destination,
|
67
|
+
}.reject { |k, v| v.nil? }
|
68
|
+
end
|
69
|
+
|
70
|
+
# Public: Produce an array of differences between this local configuration
|
71
|
+
# and the configuration in AWS
|
72
|
+
#
|
73
|
+
# aws - the AWS resource
|
74
|
+
#
|
75
|
+
# Returns an array of the ReplicationDiff that were found
|
76
|
+
def diff(aws)
|
77
|
+
diffs = []
|
78
|
+
|
79
|
+
if @destination != aws.destination
|
80
|
+
diffs << ReplicationDiff.new(ReplicationChange::DESTINATION, aws, self)
|
81
|
+
end
|
82
|
+
if @iam_role != aws.iam_role
|
83
|
+
diffs << ReplicationDiff.new(ReplicationChange::ROLE, aws, self)
|
84
|
+
end
|
85
|
+
if @prefixes.sort != aws.prefixes
|
86
|
+
diffs << ReplicationDiff.new(ReplicationChange::PREFIX, aws, self)
|
87
|
+
end
|
88
|
+
|
89
|
+
diffs
|
90
|
+
end
|
91
|
+
|
92
|
+
# Public: Populate this ReplicationConfig with the values in an AWS
|
93
|
+
# replication configuration.
|
94
|
+
#
|
95
|
+
# aws - the aws object to populate from
|
96
|
+
def populate!(aws)
|
97
|
+
@destination = aws.rules[0].destination.bucket
|
98
|
+
@destination = @destination[(@destination.rindex(":") + 1)..-1]
|
99
|
+
@iam_role = aws.role[(aws.role.rindex("/") + 1)..-1]
|
100
|
+
@prefixes = aws.rules.map(&:prefix)
|
101
|
+
|
102
|
+
if @prefixes.size == 1 and @prefixes[0] == ""
|
103
|
+
@prefixes = []
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Public: Check ReplicationConfig equality with other objects.
|
108
|
+
#
|
109
|
+
# other - the other object to check
|
110
|
+
#
|
111
|
+
# Returns whether this ReplicationConfig is equal to `other`
|
112
|
+
def ==(other)
|
113
|
+
if !other.is_a? ReplicationConfig or
|
114
|
+
@destination != other.destination or
|
115
|
+
@iam_role != other.iam_role or
|
116
|
+
@prefixes.sort != other.prefix.sort
|
117
|
+
false
|
118
|
+
else
|
119
|
+
true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Public: Check if this ReplicationConfig is not equal to the other object
|
124
|
+
#
|
125
|
+
# other - the other object to check
|
126
|
+
#
|
127
|
+
# Returns whether this ReplicationConfig is not equal to `other`
|
128
|
+
def !=(other)
|
129
|
+
!(self == other)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "common/models/Diff"
|
2
|
+
require "common/models/ListChange"
|
3
|
+
require "util/Colors"
|
4
|
+
|
5
|
+
module Cumulus
|
6
|
+
module S3
|
7
|
+
# Public: The types of changes that can be made to S3 Replication
|
8
|
+
module ReplicationChange
|
9
|
+
include Common::DiffChange
|
10
|
+
|
11
|
+
DESTINATION = Common::DiffChange.next_change_id
|
12
|
+
PREFIX = Common::DiffChange.next_change_id
|
13
|
+
ROLE = Common::DiffChange.next_change_id
|
14
|
+
end
|
15
|
+
|
16
|
+
# Public: Represents a single difference between local configuration and AWS
|
17
|
+
# S3 Replication configuration.
|
18
|
+
class ReplicationDiff < Common::Diff
|
19
|
+
include ReplicationChange
|
20
|
+
|
21
|
+
def initialize(type, aws = nil, local = nil)
|
22
|
+
super(type, aws, local)
|
23
|
+
|
24
|
+
if aws and local
|
25
|
+
@prefixes = Common::ListChange.new(
|
26
|
+
local.prefixes - aws.prefixes,
|
27
|
+
aws.prefixes - local.prefixes
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def asset_type
|
33
|
+
"S3 Replication"
|
34
|
+
end
|
35
|
+
|
36
|
+
def aws_name
|
37
|
+
"Configuration"
|
38
|
+
end
|
39
|
+
|
40
|
+
def local_name
|
41
|
+
"Configuration"
|
42
|
+
end
|
43
|
+
|
44
|
+
def diff_string
|
45
|
+
case @type
|
46
|
+
when DESTINATION
|
47
|
+
"Destination: AWS - #{Colors.aws_changes(@aws.destination)}, Local - #{Colors.local_changes(@local.destination)}"
|
48
|
+
when ROLE
|
49
|
+
"IAM Role: AWS - #{Colors.aws_changes(@aws.iam_role)}, Local - #{Colors.local_changes(@local.iam_role)}"
|
50
|
+
when PREFIX
|
51
|
+
[
|
52
|
+
"Prefixes:",
|
53
|
+
@prefixes.removed.map { |p| Colors.removed("\t#{p}") },
|
54
|
+
@prefixes.added.map { |p| Colors.added("\t#{p}") },
|
55
|
+
].flatten.join("\n")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module Cumulus
|
2
|
+
module S3
|
3
|
+
class WebsiteConfig
|
4
|
+
attr_reader :error
|
5
|
+
attr_reader :index
|
6
|
+
attr_reader :redirect
|
7
|
+
|
8
|
+
# Public: Constructor
|
9
|
+
#
|
10
|
+
# json - a hash representing the JSON configuration, expects to be handed
|
11
|
+
# the 'website' node of S3 configuration.
|
12
|
+
def initialize(json = nil)
|
13
|
+
if json
|
14
|
+
@redirect = json["redirect"]
|
15
|
+
@index = json["index"]
|
16
|
+
@error = json["error"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: Populate this WebsiteConfig with the values in an AWS WebsiteConfiguration
|
21
|
+
# object.
|
22
|
+
#
|
23
|
+
# aws - the aws object to populate from
|
24
|
+
def populate!(aws)
|
25
|
+
@index = aws.safe_index
|
26
|
+
@error = aws.safe_error
|
27
|
+
@redirect = aws.safe_redirection
|
28
|
+
end
|
29
|
+
|
30
|
+
# Public: Produce a hash that is compatible with AWS website configuration.
|
31
|
+
#
|
32
|
+
# Returns the website configuration in AWS format
|
33
|
+
def to_aws
|
34
|
+
if @index
|
35
|
+
{
|
36
|
+
error_document: {
|
37
|
+
key: @error
|
38
|
+
},
|
39
|
+
index_document: {
|
40
|
+
suffix: @index
|
41
|
+
},
|
42
|
+
}
|
43
|
+
else
|
44
|
+
{
|
45
|
+
redirect_all_requests_to: {
|
46
|
+
host_name: if @redirect and @redirect.include?("://")
|
47
|
+
@redirect.split("://")[1]
|
48
|
+
else
|
49
|
+
@redirect
|
50
|
+
end,
|
51
|
+
protocol: if @redirect and @redirect.include?("://") then @redirect.split("://")[0] end
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Public: Converts this WebsiteConfig to a hash that matches Cumulus
|
58
|
+
# configuration.
|
59
|
+
#
|
60
|
+
# Returns the hash
|
61
|
+
def to_h
|
62
|
+
{
|
63
|
+
error: @error,
|
64
|
+
index: @index,
|
65
|
+
redirect: @redirect,
|
66
|
+
}.reject { |k, v| v.nil? }
|
67
|
+
end
|
68
|
+
|
69
|
+
# Public: Check WebsiteConfig equality with other objects
|
70
|
+
#
|
71
|
+
# other - the other object to check
|
72
|
+
#
|
73
|
+
# Returns whether this WebsiteConfig is equal to `other`
|
74
|
+
def ==(other)
|
75
|
+
if !other.is_a? WebsiteConfig or
|
76
|
+
@redirect != other.redirect or
|
77
|
+
@index != other.index or
|
78
|
+
@error != other.error
|
79
|
+
false
|
80
|
+
else
|
81
|
+
true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Public: Check if this WebsiteConfig is not equal to the other object
|
86
|
+
#
|
87
|
+
# other - the other object to check
|
88
|
+
#
|
89
|
+
# Returns whether this WebsiteConfig is not equal to `other`
|
90
|
+
def !=(other)
|
91
|
+
!(self == other)
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_s
|
95
|
+
if @redirect
|
96
|
+
"Redirect all traffic to #{@redirect}"
|
97
|
+
elsif @index
|
98
|
+
if @error
|
99
|
+
"Index document: #{@index}, Error document: #{@error}"
|
100
|
+
else
|
101
|
+
"Index document: #{@index}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|