cumulus-aws 0.11.1
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.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/.travis.yml +12 -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/cumulus-aws.gemspec +20 -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/rakefile.rb +8 -0
- metadata +245 -0
data/lib/sns/SNS.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require "conf/Configuration"
|
|
2
|
+
|
|
3
|
+
require "aws-sdk"
|
|
4
|
+
|
|
5
|
+
module Cumulus
|
|
6
|
+
module SNS
|
|
7
|
+
class << self
|
|
8
|
+
@@client = Aws::SNS::Client.new(Configuration.instance.client)
|
|
9
|
+
|
|
10
|
+
# Public: Static method that will get an SNS topic from AWS by its name
|
|
11
|
+
#
|
|
12
|
+
# name - the name of the topic to get
|
|
13
|
+
#
|
|
14
|
+
# Returns the Aws::SNS::Types::Topic
|
|
15
|
+
def get_aws(name)
|
|
16
|
+
topics.fetch(name)
|
|
17
|
+
rescue KeyError
|
|
18
|
+
puts "No SNS topic named #{name}"
|
|
19
|
+
exit
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Public: Provide a mapping of topics to their names.
|
|
23
|
+
# Lazily loads resources.
|
|
24
|
+
#
|
|
25
|
+
# Returns the topics mapped to their names
|
|
26
|
+
def topics
|
|
27
|
+
@topics ||= init_topics
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# Internal: Load the topics and map them to their names
|
|
33
|
+
#
|
|
34
|
+
# Returns the topics mapped to their names
|
|
35
|
+
def init_topics
|
|
36
|
+
Hash[@@client.list_topics.topics.map { |t| [t.topic_arn[(t.topic_arn.rindex(":") + 1)..-1], t.topic_arn] }]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/sqs/SQS.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "conf/Configuration"
|
|
2
|
+
require "util/Colors"
|
|
3
|
+
|
|
4
|
+
require "aws-sdk"
|
|
5
|
+
|
|
6
|
+
module Cumulus
|
|
7
|
+
module SQS
|
|
8
|
+
class << self
|
|
9
|
+
@@client = Aws::SQS::Client.new(Configuration.instance.client)
|
|
10
|
+
|
|
11
|
+
# Public: Static method that will get the ARN of a Queue
|
|
12
|
+
#
|
|
13
|
+
# name - the name of the queue to get
|
|
14
|
+
#
|
|
15
|
+
# Returns the String ARN
|
|
16
|
+
def get_arn(queue_name)
|
|
17
|
+
queue_arns.fetch(queue_name)
|
|
18
|
+
rescue KeyError
|
|
19
|
+
puts Colors.red("No SQS queue named #{queue_name}")
|
|
20
|
+
exit 1
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Public: Returns a mapping of queue name to ARN
|
|
24
|
+
def queue_arns
|
|
25
|
+
@queue_arns ||= Hash[queue_attributes.map { |name, attrs| [name, attrs["QueueArn"]] }]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Public: Return the policy of a queue as a Hash
|
|
29
|
+
def queue_policy(queue_name)
|
|
30
|
+
JSON.parse(URI.decode(queue_attributes[queue_name]["Policy"])) rescue nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Public: Return a mapping of queue name to url
|
|
34
|
+
def queue_urls
|
|
35
|
+
@queue_urls ||= init_urls
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Public: Return a mapping of queue name to attributes
|
|
39
|
+
def queue_attributes
|
|
40
|
+
@queue_attributes ||= Hash[queue_urls.map { |name, url| [name, init_attributes(url)] }]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
# Internal: Returns a Hash of attribute names to values
|
|
46
|
+
def init_attributes(queue_url)
|
|
47
|
+
@@client.get_queue_attributes({
|
|
48
|
+
queue_url: queue_url,
|
|
49
|
+
attribute_names: ["All"]
|
|
50
|
+
}).attributes
|
|
51
|
+
rescue Aws::SQS::Errors::NonExistentQueue
|
|
52
|
+
puts "Queue #{queue_url} has been deleted. Please wait a few seconds until AWS updates the list of queues"
|
|
53
|
+
exit 1
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Internal: Map queue names to their urls.
|
|
57
|
+
def init_urls
|
|
58
|
+
Hash[@@client.list_queues.queue_urls.map { |u| [u[(u.rindex("/") + 1)..-1], u] }]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "common/BaseLoader"
|
|
2
|
+
require "conf/Configuration"
|
|
3
|
+
require "sqs/models/QueueConfig"
|
|
4
|
+
|
|
5
|
+
require "aws-sdk"
|
|
6
|
+
|
|
7
|
+
# Public: Load SQS assets
|
|
8
|
+
module Cumulus
|
|
9
|
+
module SQS
|
|
10
|
+
module Loader
|
|
11
|
+
include Common::BaseLoader
|
|
12
|
+
|
|
13
|
+
@@queues_dir = Configuration.instance.sqs.queues_directory
|
|
14
|
+
@@policies_dir = Configuration.instance.sqs.policies_directory
|
|
15
|
+
|
|
16
|
+
# Public: Load all the queue configurations as QueueConfig objects
|
|
17
|
+
#
|
|
18
|
+
# Returns an array of QueueConfig
|
|
19
|
+
def self.queues
|
|
20
|
+
Common::BaseLoader::resources(@@queues_dir, &QueueConfig.method(:new))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Public: Load the specified policy as a JSON object
|
|
24
|
+
#
|
|
25
|
+
# Returns the JSON object for the policy
|
|
26
|
+
def self.policy(policy_name)
|
|
27
|
+
Common::BaseLoader::resource(policy_name, @@policies_dir) do |policy_name, policy|
|
|
28
|
+
policy
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require "common/manager/Manager"
|
|
2
|
+
require "conf/Configuration"
|
|
3
|
+
require "util/Colors"
|
|
4
|
+
require "sqs/models/QueueConfig"
|
|
5
|
+
require "sqs/models/QueueDiff"
|
|
6
|
+
require "sqs/SQS"
|
|
7
|
+
|
|
8
|
+
require "aws-sdk"
|
|
9
|
+
require "json"
|
|
10
|
+
|
|
11
|
+
module Cumulus
|
|
12
|
+
module SQS
|
|
13
|
+
class Manager < Common::Manager
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
super()
|
|
17
|
+
@create_asset = true
|
|
18
|
+
@client = Aws::SQS::Client.new(Configuration.instance.client)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def resource_name
|
|
22
|
+
"Queue"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def local_resources
|
|
26
|
+
@local_resources ||= Hash[Loader.queues.map { |local| [local.name, local] }]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def aws_resources
|
|
30
|
+
@aws_resources ||= Hash[SQS::queue_attributes.map { |name, attrs| [name, QueueConfig.new(name).populate!(attrs) ] }]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def unmanaged_diff(aws)
|
|
34
|
+
QueueDiff.unmanaged(aws)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def added_diff(local)
|
|
38
|
+
QueueDiff.added(local)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def diff_resource(local, aws)
|
|
42
|
+
local.diff(aws)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def urls
|
|
46
|
+
local_resources.keys.sort.each do |name|
|
|
47
|
+
url = SQS::queue_urls[name] || "does not exist"
|
|
48
|
+
puts "#{name} => #{url}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def update(local, diffs)
|
|
53
|
+
@client.set_queue_attributes({
|
|
54
|
+
queue_url: SQS::queue_urls[local.name],
|
|
55
|
+
attributes: {
|
|
56
|
+
"DelaySeconds" => if diffs.any? { |d| d.type == QueueChange::DELAY } then local.delay end,
|
|
57
|
+
"MaximumMessageSize" => if diffs.any? { |d| d.type == QueueChange::MESSAGE_SIZE } then local.max_message_size end,
|
|
58
|
+
"MessageRetentionPeriod" => if diffs.any? { |d| d.type == QueueChange::MESSAGE_RETENTION } then local.message_retention end,
|
|
59
|
+
"Policy" => if diffs.any? { |d| d.type == QueueChange::POLICY }
|
|
60
|
+
if local.policy then JSON.generate(Loader.policy(local.policy)) else "" end
|
|
61
|
+
end,
|
|
62
|
+
"ReceiveMessageWaitTimeSeconds" => if diffs.any? { |d| d.type == QueueChange::RECEIVE_WAIT } then local.receive_wait_time end,
|
|
63
|
+
"VisibilityTimeout" => if diffs.any? { |d| d.type == QueueChange::VISIBILITY } then local.visibility_timeout end,
|
|
64
|
+
"RedrivePolicy" => if diffs.any? { |d| d.type == QueueChange::DEAD }
|
|
65
|
+
if local.dead_letter then JSON.generate(local.dead_letter.to_aws) else "" end
|
|
66
|
+
end
|
|
67
|
+
}.reject { |k, v| v.nil? }
|
|
68
|
+
})
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def create(local)
|
|
72
|
+
url = @client.create_queue({
|
|
73
|
+
queue_name: local.name,
|
|
74
|
+
attributes: {
|
|
75
|
+
"DelaySeconds" => "#{local.delay}",
|
|
76
|
+
"MaximumMessageSize" => "#{local.max_message_size}",
|
|
77
|
+
"MessageRetentionPeriod" => "#{local.message_retention}",
|
|
78
|
+
"Policy" => if local.policy then JSON.generate(Loader.policy(local.policy)) end,
|
|
79
|
+
"ReceiveMessageWaitTimeSeconds" => "#{local.receive_wait_time}",
|
|
80
|
+
"VisibilityTimeout" => "#{local.visibility_timeout}",
|
|
81
|
+
"RedrivePolicy" => if local.dead_letter then JSON.generate(local.dead_letter.to_aws) end
|
|
82
|
+
}.reject { |k, v| v.nil? }
|
|
83
|
+
}).queue_url
|
|
84
|
+
puts Colors.blue("Queue #{local.name} was created with url #{url}")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Public: Migrates the existing AWS config to Cumulus
|
|
88
|
+
def migrate
|
|
89
|
+
# Create the directories
|
|
90
|
+
sqs_dir = "#{@migration_root}/sqs"
|
|
91
|
+
policies_dir = "#{sqs_dir}/policies"
|
|
92
|
+
queues_dir = "#{sqs_dir}/queues"
|
|
93
|
+
|
|
94
|
+
if !Dir.exists?(@migration_root)
|
|
95
|
+
Dir.mkdir(@migration_root)
|
|
96
|
+
end
|
|
97
|
+
if !Dir.exists?(sqs_dir)
|
|
98
|
+
Dir.mkdir(sqs_dir)
|
|
99
|
+
end
|
|
100
|
+
if !Dir.exists?(policies_dir)
|
|
101
|
+
Dir.mkdir(policies_dir)
|
|
102
|
+
end
|
|
103
|
+
if !Dir.exists?(queues_dir)
|
|
104
|
+
Dir.mkdir(queues_dir)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
puts Colors.blue("Migrating queues to #{queues_dir}")
|
|
108
|
+
aws_resources.each do |name, config|
|
|
109
|
+
puts Colors.blue("Migrating queue #{name}")
|
|
110
|
+
|
|
111
|
+
# If there is a policy, then save it to the policies dir with the name of the queue
|
|
112
|
+
queue_policy = SQS::queue_policy(name)
|
|
113
|
+
if queue_policy
|
|
114
|
+
policy_json = JSON.pretty_generate(queue_policy)
|
|
115
|
+
policy_file = "#{policies_dir}/#{name}.json"
|
|
116
|
+
puts "Migrating policy to #{policy_file}"
|
|
117
|
+
File.open("#{policy_file}", "w") { |f| f.write(policy_json) }
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
json = JSON.pretty_generate(config.to_hash)
|
|
121
|
+
File.open("#{queues_dir}/#{name}.json", "w") { |f| f.write(json) }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require "sqs/models/DeadLetterDiff"
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Cumulus
|
|
6
|
+
module SQS
|
|
7
|
+
|
|
8
|
+
# Public: An object representing configuration for a queue's dead letter options
|
|
9
|
+
class DeadLetterConfig
|
|
10
|
+
attr_reader :target
|
|
11
|
+
attr_reader :max_receives
|
|
12
|
+
|
|
13
|
+
# Public: Constructor
|
|
14
|
+
#
|
|
15
|
+
# json - a hash containing the JSON configuration for dead letter options
|
|
16
|
+
def initialize(json = nil)
|
|
17
|
+
if !json.nil?
|
|
18
|
+
@target = json["target"]
|
|
19
|
+
@max_receives = json["max-receives"]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_hash
|
|
24
|
+
{
|
|
25
|
+
"target" => @target,
|
|
26
|
+
"max-receives" => @max_receives,
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_aws
|
|
31
|
+
{
|
|
32
|
+
"deadLetterTargetArn" => SQS::queue_arns[@target],
|
|
33
|
+
"maxReceiveCount" => @max_receives
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Public: Populate a config object with AWS configuration
|
|
38
|
+
#
|
|
39
|
+
# aws - the JSON string containing dead letter attributes in AWS
|
|
40
|
+
def populate!(aws)
|
|
41
|
+
attributes = JSON.parse(URI.decode(aws))
|
|
42
|
+
|
|
43
|
+
@target = SQS::queue_arns.key(attributes["deadLetterTargetArn"])
|
|
44
|
+
@max_receives = if attributes["maxReceiveCount"] then attributes["maxReceiveCount"].to_i end
|
|
45
|
+
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Public: Produce an array of differences between two DeadLetterConfig objects
|
|
50
|
+
#
|
|
51
|
+
# aws - the DeadLetterConfig object built from aws config
|
|
52
|
+
#
|
|
53
|
+
# Returns an array of the DeadLetterDiffs that were found
|
|
54
|
+
def diff(aws)
|
|
55
|
+
diffs = []
|
|
56
|
+
|
|
57
|
+
if @target != aws.target
|
|
58
|
+
diffs << DeadLetterDiff.new(DeadLetterChange::TARGET, aws.target, @target)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
if @max_receives != aws.max_receives
|
|
62
|
+
diffs << DeadLetterDiff.new(DeadLetterChange::RECEIVE, aws.max_receives, @max_receives)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
diffs
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "common/models/Diff"
|
|
2
|
+
require "util/Colors"
|
|
3
|
+
|
|
4
|
+
module Cumulus
|
|
5
|
+
module SQS
|
|
6
|
+
# Public: The types of changes that can be made to a dead letter config
|
|
7
|
+
module DeadLetterChange
|
|
8
|
+
include Common::DiffChange
|
|
9
|
+
|
|
10
|
+
TARGET = Common::DiffChange.next_change_id
|
|
11
|
+
RECEIVE = Common::DiffChange.next_change_id
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Public: Represents a single difference between local configuration and AWS configuration
|
|
15
|
+
class DeadLetterDiff < Common::Diff
|
|
16
|
+
include DeadLetterChange
|
|
17
|
+
|
|
18
|
+
def diff_string
|
|
19
|
+
asset = case @type
|
|
20
|
+
when TARGET
|
|
21
|
+
"Target"
|
|
22
|
+
when RECEIVE
|
|
23
|
+
"Max Receive Count"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
[
|
|
27
|
+
"#{asset}:",
|
|
28
|
+
Colors.aws_changes("\tAWS - #{aws}"),
|
|
29
|
+
Colors.local_changes("\tLocal - #{local}")
|
|
30
|
+
].join("\n")
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require "sqs/loader/Loader"
|
|
2
|
+
require "sqs/models/DeadLetterConfig"
|
|
3
|
+
require "sqs/models/QueueDiff"
|
|
4
|
+
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
module Cumulus
|
|
8
|
+
module SQS
|
|
9
|
+
|
|
10
|
+
# Public: An object representing configuration for a queue
|
|
11
|
+
class QueueConfig
|
|
12
|
+
attr_reader :name
|
|
13
|
+
attr_reader :delay
|
|
14
|
+
attr_reader :max_message_size
|
|
15
|
+
attr_reader :message_retention
|
|
16
|
+
attr_reader :policy
|
|
17
|
+
attr_reader :receive_wait_time
|
|
18
|
+
attr_reader :visibility_timeout
|
|
19
|
+
attr_reader :dead_letter
|
|
20
|
+
|
|
21
|
+
# Public: Constructor
|
|
22
|
+
#
|
|
23
|
+
# json - a hash containing the JSON configuration for the queue
|
|
24
|
+
def initialize(name, json = nil)
|
|
25
|
+
@name = name
|
|
26
|
+
if !json.nil?
|
|
27
|
+
@delay = json["delay"]
|
|
28
|
+
@max_message_size = json["max-message-size"]
|
|
29
|
+
@message_retention = json["message-retention"]
|
|
30
|
+
@policy = json["policy"]
|
|
31
|
+
@receive_wait_time = json["receive-wait-time"]
|
|
32
|
+
@visibility_timeout = json["visibility-timeout"]
|
|
33
|
+
@dead_letter = if json["dead-letter"] then DeadLetterConfig.new(json["dead-letter"]) end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def to_hash
|
|
38
|
+
{
|
|
39
|
+
"delay" => @delay,
|
|
40
|
+
"max-message-size" => @max_message_size,
|
|
41
|
+
"message-retention" => @message_retention,
|
|
42
|
+
"policy" => @policy,
|
|
43
|
+
"receive-wait-time" => @receive_wait_time,
|
|
44
|
+
"visibility-timeout" => @visibility_timeout,
|
|
45
|
+
"dead-letter" => if @dead_letter then @dead_letter.to_hash end,
|
|
46
|
+
}.reject { |k, v| v.nil? }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Public: Populate a config object with AWS configuration
|
|
50
|
+
#
|
|
51
|
+
# attributes - the queue attributes in AWS
|
|
52
|
+
def populate!(attributes)
|
|
53
|
+
@delay = if attributes["DelaySeconds"] then attributes["DelaySeconds"].to_i end
|
|
54
|
+
@max_message_size = if attributes["MaximumMessageSize"] then attributes["MaximumMessageSize"].to_i end
|
|
55
|
+
@message_retention = if attributes["MessageRetentionPeriod"] then attributes["MessageRetentionPeriod"].to_i end
|
|
56
|
+
@receive_wait_time = if attributes["ReceiveMessageWaitTimeSeconds"] then attributes["ReceiveMessageWaitTimeSeconds"].to_i end
|
|
57
|
+
@visibility_timeout = if attributes["VisibilityTimeout"] then attributes["VisibilityTimeout"].to_i end
|
|
58
|
+
@dead_letter = if attributes["RedrivePolicy"] then DeadLetterConfig.new().populate!(attributes["RedrivePolicy"]) end
|
|
59
|
+
|
|
60
|
+
# Policy is handled specially because we store them in a separate file locally.
|
|
61
|
+
# For migrating we assume the policy is the same as the queue name, otherwise this
|
|
62
|
+
# attribute is not used from AWS config
|
|
63
|
+
@policy = if attributes["Policy"] then @name end
|
|
64
|
+
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Public: Produce an array of differences between this local configuration and the
|
|
69
|
+
# configuration in AWS
|
|
70
|
+
#
|
|
71
|
+
# aws - the AWS resource
|
|
72
|
+
#
|
|
73
|
+
# Returns an array of the QueueDiffs that were found
|
|
74
|
+
def diff(aws)
|
|
75
|
+
diffs = []
|
|
76
|
+
|
|
77
|
+
if @delay != aws.delay
|
|
78
|
+
diffs << QueueDiff.new(QueueChange::DELAY, aws.delay, @delay)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
if @max_message_size != aws.max_message_size
|
|
82
|
+
diffs << QueueDiff.new(QueueChange::MESSAGE_SIZE, aws.max_message_size, @max_message_size)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
if @message_retention != aws.message_retention
|
|
86
|
+
diffs << QueueDiff.new(QueueChange::MESSAGE_RETENTION, aws.message_retention, @message_retention)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
if @receive_wait_time != aws.receive_wait_time
|
|
90
|
+
diffs << QueueDiff.new(QueueChange::RECEIVE_WAIT, aws.receive_wait_time, @receive_wait_time)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
if @visibility_timeout != aws.visibility_timeout
|
|
94
|
+
diffs << QueueDiff.new(QueueChange::VISIBILITY, aws.visibility_timeout, @visibility_timeout)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
aws_dead_letter = aws.dead_letter || DeadLetterConfig.new()
|
|
98
|
+
local_dead_letter = @dead_letter || DeadLetterConfig.new()
|
|
99
|
+
dead_diffs = local_dead_letter.diff(aws_dead_letter)
|
|
100
|
+
if !dead_diffs.empty?
|
|
101
|
+
diffs << QueueDiff.new(QueueChange::DEAD, aws_dead_letter, local_dead_letter, dead_diffs)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
aws_policy = SQS::queue_policy(@name)
|
|
105
|
+
local_policy = if @policy then Loader.policy(@policy) end
|
|
106
|
+
if local_policy != aws_policy
|
|
107
|
+
diffs << QueueDiff.new(QueueChange::POLICY, aws_policy, local_policy)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
diffs
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|