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.
Files changed (173) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +29 -0
  6. data/LICENSE +202 -0
  7. data/README.md +41 -0
  8. data/autocomplete +137 -0
  9. data/bin/cumulus +658 -0
  10. data/cumulus +2 -0
  11. data/cumulus-aws.gemspec +20 -0
  12. data/lib/autoscaling/AutoScaling.rb +40 -0
  13. data/lib/autoscaling/loader/Loader.rb +56 -0
  14. data/lib/autoscaling/manager/Manager.rb +360 -0
  15. data/lib/autoscaling/models/AlarmConfig.rb +165 -0
  16. data/lib/autoscaling/models/AlarmDiff.rb +172 -0
  17. data/lib/autoscaling/models/AutoScalingDiff.rb +178 -0
  18. data/lib/autoscaling/models/GroupConfig.rb +330 -0
  19. data/lib/autoscaling/models/PolicyConfig.rb +135 -0
  20. data/lib/autoscaling/models/PolicyDiff.rb +73 -0
  21. data/lib/autoscaling/models/ScheduledActionDiff.rb +53 -0
  22. data/lib/autoscaling/models/ScheduledConfig.rb +96 -0
  23. data/lib/aws_extensions/ec2/DhcpOptions.rb +41 -0
  24. data/lib/aws_extensions/ec2/Instance.rb +29 -0
  25. data/lib/aws_extensions/ec2/NetworkAcl.rb +25 -0
  26. data/lib/aws_extensions/ec2/NetworkInterface.rb +14 -0
  27. data/lib/aws_extensions/ec2/RouteTable.rb +26 -0
  28. data/lib/aws_extensions/ec2/SecurityGroup.rb +16 -0
  29. data/lib/aws_extensions/ec2/Subnet.rb +28 -0
  30. data/lib/aws_extensions/ec2/Volume.rb +24 -0
  31. data/lib/aws_extensions/ec2/Vpc.rb +14 -0
  32. data/lib/aws_extensions/ec2/VpcEndpoint.rb +11 -0
  33. data/lib/aws_extensions/elb/BackendServerDescription.rb +12 -0
  34. data/lib/aws_extensions/elb/PolicyDescription.rb +14 -0
  35. data/lib/aws_extensions/kinesis/StreamDescription.rb +12 -0
  36. data/lib/aws_extensions/route53/AliasTarget.rb +21 -0
  37. data/lib/aws_extensions/s3/Bucket.rb +33 -0
  38. data/lib/aws_extensions/s3/BucketAcl.rb +28 -0
  39. data/lib/aws_extensions/s3/BucketCors.rb +17 -0
  40. data/lib/aws_extensions/s3/BucketLifecycle.rb +21 -0
  41. data/lib/aws_extensions/s3/BucketLogging.rb +18 -0
  42. data/lib/aws_extensions/s3/BucketNotification.rb +23 -0
  43. data/lib/aws_extensions/s3/BucketPolicy.rb +18 -0
  44. data/lib/aws_extensions/s3/BucketTagging.rb +15 -0
  45. data/lib/aws_extensions/s3/BucketVersioning.rb +14 -0
  46. data/lib/aws_extensions/s3/BucketWebsite.rb +49 -0
  47. data/lib/aws_extensions/s3/CORSRule.rb +27 -0
  48. data/lib/aws_extensions/s3/ReplicationConfiguration.rb +22 -0
  49. data/lib/cloudfront/CloudFront.rb +83 -0
  50. data/lib/cloudfront/loader/Loader.rb +31 -0
  51. data/lib/cloudfront/manager/Manager.rb +183 -0
  52. data/lib/cloudfront/models/CacheBehaviorConfig.rb +237 -0
  53. data/lib/cloudfront/models/CacheBehaviorDiff.rb +211 -0
  54. data/lib/cloudfront/models/CustomOriginConfig.rb +51 -0
  55. data/lib/cloudfront/models/CustomOriginDiff.rb +74 -0
  56. data/lib/cloudfront/models/DistributionConfig.rb +183 -0
  57. data/lib/cloudfront/models/DistributionDiff.rb +131 -0
  58. data/lib/cloudfront/models/InvalidationConfig.rb +37 -0
  59. data/lib/cloudfront/models/OriginConfig.rb +144 -0
  60. data/lib/cloudfront/models/OriginDiff.rb +86 -0
  61. data/lib/cloudfront/models/OriginSslProtocols.rb +28 -0
  62. data/lib/cloudfront/models/OriginSslProtocolsDiff.rb +39 -0
  63. data/lib/common/BaseLoader.rb +80 -0
  64. data/lib/common/manager/Manager.rb +148 -0
  65. data/lib/common/models/Diff.rb +114 -0
  66. data/lib/common/models/ListChange.rb +21 -0
  67. data/lib/common/models/TagsDiff.rb +55 -0
  68. data/lib/common/models/UTCTimeSource.rb +17 -0
  69. data/lib/conf/Configuration.rb +365 -0
  70. data/lib/ec2/EC2.rb +503 -0
  71. data/lib/ec2/IPProtocolMapping.rb +165 -0
  72. data/lib/ec2/loaders/EbsLoader.rb +19 -0
  73. data/lib/ec2/loaders/InstanceLoader.rb +32 -0
  74. data/lib/ec2/managers/EbsManager.rb +176 -0
  75. data/lib/ec2/managers/InstanceManager.rb +509 -0
  76. data/lib/ec2/models/EbsGroupConfig.rb +133 -0
  77. data/lib/ec2/models/EbsGroupDiff.rb +48 -0
  78. data/lib/ec2/models/InstanceConfig.rb +202 -0
  79. data/lib/ec2/models/InstanceDiff.rb +95 -0
  80. data/lib/elb/ELB.rb +148 -0
  81. data/lib/elb/loader/Loader.rb +65 -0
  82. data/lib/elb/manager/Manager.rb +581 -0
  83. data/lib/elb/models/AccessLogConfig.rb +82 -0
  84. data/lib/elb/models/AccessLogDiff.rb +47 -0
  85. data/lib/elb/models/HealthCheckConfig.rb +91 -0
  86. data/lib/elb/models/HealthCheckDiff.rb +50 -0
  87. data/lib/elb/models/ListenerConfig.rb +99 -0
  88. data/lib/elb/models/ListenerDiff.rb +91 -0
  89. data/lib/elb/models/LoadBalancerConfig.rb +239 -0
  90. data/lib/elb/models/LoadBalancerDiff.rb +265 -0
  91. data/lib/iam/IAM.rb +36 -0
  92. data/lib/iam/loader/Loader.rb +117 -0
  93. data/lib/iam/manager/IamGroups.rb +98 -0
  94. data/lib/iam/manager/IamResource.rb +288 -0
  95. data/lib/iam/manager/IamRoles.rb +112 -0
  96. data/lib/iam/manager/IamUsers.rb +54 -0
  97. data/lib/iam/manager/Manager.rb +29 -0
  98. data/lib/iam/migration/AssumeRoleUnifier.rb +34 -0
  99. data/lib/iam/migration/PolicyUnifier.rb +90 -0
  100. data/lib/iam/models/GroupConfig.rb +40 -0
  101. data/lib/iam/models/IamDiff.rb +132 -0
  102. data/lib/iam/models/PolicyConfig.rb +67 -0
  103. data/lib/iam/models/ResourceWithPolicy.rb +208 -0
  104. data/lib/iam/models/RoleConfig.rb +53 -0
  105. data/lib/iam/models/StatementConfig.rb +35 -0
  106. data/lib/iam/models/UserConfig.rb +21 -0
  107. data/lib/kinesis/Kinesis.rb +94 -0
  108. data/lib/kinesis/loader/Loader.rb +19 -0
  109. data/lib/kinesis/manager/Manager.rb +206 -0
  110. data/lib/kinesis/models/StreamConfig.rb +75 -0
  111. data/lib/kinesis/models/StreamDiff.rb +58 -0
  112. data/lib/lambda/Lambda.rb +41 -0
  113. data/lib/route53/loader/Loader.rb +32 -0
  114. data/lib/route53/manager/Manager.rb +241 -0
  115. data/lib/route53/models/AliasTarget.rb +86 -0
  116. data/lib/route53/models/RecordConfig.rb +178 -0
  117. data/lib/route53/models/RecordDiff.rb +140 -0
  118. data/lib/route53/models/Vpc.rb +24 -0
  119. data/lib/route53/models/ZoneConfig.rb +156 -0
  120. data/lib/route53/models/ZoneDiff.rb +118 -0
  121. data/lib/s3/S3.rb +89 -0
  122. data/lib/s3/loader/Loader.rb +66 -0
  123. data/lib/s3/manager/Manager.rb +296 -0
  124. data/lib/s3/models/BucketConfig.rb +321 -0
  125. data/lib/s3/models/BucketDiff.rb +167 -0
  126. data/lib/s3/models/GrantConfig.rb +189 -0
  127. data/lib/s3/models/GrantDiff.rb +50 -0
  128. data/lib/s3/models/LifecycleConfig.rb +142 -0
  129. data/lib/s3/models/LifecycleDiff.rb +46 -0
  130. data/lib/s3/models/LoggingConfig.rb +81 -0
  131. data/lib/s3/models/NotificationConfig.rb +157 -0
  132. data/lib/s3/models/NotificationDiff.rb +62 -0
  133. data/lib/s3/models/ReplicationConfig.rb +133 -0
  134. data/lib/s3/models/ReplicationDiff.rb +60 -0
  135. data/lib/s3/models/WebsiteConfig.rb +107 -0
  136. data/lib/security/SecurityGroups.rb +39 -0
  137. data/lib/security/loader/Loader.rb +94 -0
  138. data/lib/security/manager/Manager.rb +246 -0
  139. data/lib/security/models/RuleConfig.rb +161 -0
  140. data/lib/security/models/RuleDiff.rb +72 -0
  141. data/lib/security/models/RuleMigration.rb +127 -0
  142. data/lib/security/models/SecurityGroupConfig.rb +172 -0
  143. data/lib/security/models/SecurityGroupDiff.rb +112 -0
  144. data/lib/sns/SNS.rb +40 -0
  145. data/lib/sqs/SQS.rb +62 -0
  146. data/lib/sqs/loader/Loader.rb +34 -0
  147. data/lib/sqs/manager/Manager.rb +128 -0
  148. data/lib/sqs/models/DeadLetterConfig.rb +70 -0
  149. data/lib/sqs/models/DeadLetterDiff.rb +35 -0
  150. data/lib/sqs/models/QueueConfig.rb +115 -0
  151. data/lib/sqs/models/QueueDiff.rb +89 -0
  152. data/lib/util/Colors.rb +111 -0
  153. data/lib/util/StatusCodes.rb +51 -0
  154. data/lib/vpc/loader/Loader.rb +73 -0
  155. data/lib/vpc/manager/Manager.rb +954 -0
  156. data/lib/vpc/models/AclEntryConfig.rb +150 -0
  157. data/lib/vpc/models/AclEntryDiff.rb +54 -0
  158. data/lib/vpc/models/DhcpConfig.rb +100 -0
  159. data/lib/vpc/models/DhcpDiff.rb +90 -0
  160. data/lib/vpc/models/EndpointConfig.rb +76 -0
  161. data/lib/vpc/models/EndpointDiff.rb +69 -0
  162. data/lib/vpc/models/NetworkAclConfig.rb +87 -0
  163. data/lib/vpc/models/NetworkAclDiff.rb +116 -0
  164. data/lib/vpc/models/RouteConfig.rb +82 -0
  165. data/lib/vpc/models/RouteDiff.rb +50 -0
  166. data/lib/vpc/models/RouteTableConfig.rb +92 -0
  167. data/lib/vpc/models/RouteTableDiff.rb +101 -0
  168. data/lib/vpc/models/SubnetConfig.rb +113 -0
  169. data/lib/vpc/models/SubnetDiff.rb +78 -0
  170. data/lib/vpc/models/VpcConfig.rb +173 -0
  171. data/lib/vpc/models/VpcDiff.rb +315 -0
  172. data/rakefile.rb +8 -0
  173. metadata +245 -0
@@ -0,0 +1,189 @@
1
+ require "s3/models/GrantDiff"
2
+
3
+ module Cumulus
4
+ module S3
5
+ class GrantConfig
6
+ @@all_permissions = ["list", "update", "view-permissions", "edit-permissions"].sort
7
+
8
+ attr_reader :email
9
+ attr_reader :name
10
+ attr_reader :permissions
11
+
12
+
13
+ # Public: A static method that will produce the Cumulus version of the permission
14
+ # so that the names we use in Cumulus are a little closer to the names
15
+ # in the AWS console.
16
+ #
17
+ # aws_permission - the string permission to convert
18
+ #
19
+ # Returns an array of the Cumulus version of the permission
20
+ def self.to_cumulus_permission(aws_permission)
21
+ case aws_permission
22
+ when "FULL_CONTROL"
23
+ @@all_permissions
24
+ when "WRITE"
25
+ ["update"]
26
+ when "READ"
27
+ ["list"]
28
+ when "WRITE_ACP"
29
+ ["edit-permissions"]
30
+ when "READ_ACP"
31
+ ["view-permissions"]
32
+ end
33
+ end
34
+
35
+ # Public: A static method that will produce the AWS version of the
36
+ # permission.
37
+ #
38
+ # cumulus_permission - the string permission to convert
39
+ #
40
+ # Returns the converted permission string
41
+ def self.to_aws_permission(cumulus_permission)
42
+ case cumulus_permission
43
+ when "update"
44
+ "WRITE"
45
+ when "list"
46
+ "READ"
47
+ when "edit-permissions"
48
+ "WRITE_ACP"
49
+ when "view-permissions"
50
+ "READ_ACP"
51
+ end
52
+ end
53
+
54
+ # Public: Constructor
55
+ #
56
+ # json - a hash representing the JSON configuration. Expects to be passed
57
+ # an object from the "grants" array of S3 bucket configuration.
58
+ def initialize(json = nil)
59
+ if json
60
+ @name = json["name"]
61
+ @email = json["email"]
62
+ @id = json["id"]
63
+ @permissions = json["permissions"].sort
64
+ if @permissions.include?("all")
65
+ @permissions = @@all_permissions
66
+ end
67
+ end
68
+ end
69
+
70
+ # Public: Populate this GrantConfig from the avlues in an
71
+ # Aws::S3::Types::Grant
72
+ #
73
+ # aws - the aws object to populate from
74
+ def populate!(aws)
75
+ @name = if aws.grantee.type == "CanonicalUser"
76
+ aws.grantee.display_name
77
+ else
78
+ case aws.grantee.uri
79
+ when "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
80
+ "AuthenticatedUsers"
81
+ when "http://acs.amazonaws.com/groups/global/AllUsers"
82
+ "Everyone"
83
+ when "http://acs.amazonaws.com/groups/s3/LogDelivery"
84
+ "LogDelivery"
85
+ end
86
+ end
87
+ @email = aws.grantee.email_address
88
+ @permissions = GrantConfig.to_cumulus_permission(aws.permission)
89
+ @id = aws.grantee.id
90
+ end
91
+
92
+ # Public: Produce an AWS compatible array of hashes representing this
93
+ # GrantConfig.
94
+ #
95
+ # Returns the array of hashes.
96
+ def to_aws
97
+ @permissions.map do |permission|
98
+ if @name == "AuthenticatedUsers"
99
+ type = "Group"
100
+ uri = "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
101
+ elsif @name == "Everyone"
102
+ type = "Group"
103
+ uri = "http://acs.amazonaws.com/groups/global/AllUsers"
104
+ elsif @name == "LogDelivery"
105
+ type = "Group"
106
+ uri = "http://acs.amazonaws.com/groups/s3/LogDelivery"
107
+ elsif @email
108
+ type = "AmazonCustomerByEmail"
109
+ else
110
+ type = "CanonicalUser"
111
+ display_name = @name
112
+ end
113
+
114
+ {
115
+ grantee: {
116
+ display_name: if !@email then @name end,
117
+ email_address: if @email then @email end,
118
+ id: if !@email then @id end,
119
+ type: type,
120
+ uri: uri,
121
+ }.reject { |k, v| v.nil? },
122
+ permission: GrantConfig.to_aws_permission(permission)
123
+ }
124
+ end
125
+ end
126
+
127
+ # Public: Converts this GrantConfig to a hash that matches Cumulus
128
+ # configuration.
129
+ #
130
+ # Returns the hash
131
+ def to_h
132
+ {
133
+ name: @name,
134
+ id: @id,
135
+ email: @email,
136
+ permissions: if @permissions.sort == @@all_permissions then ["all"] else @permissions.sort end,
137
+ }.reject { |k, v| v.nil? }
138
+ end
139
+
140
+ # Public: Produce an array of differences between this local configuration
141
+ # and the configuration in AWS
142
+ #
143
+ # aws - the AWS resource
144
+ #
145
+ # Returns an array of the GrantDiffs that were found
146
+ def diff(aws)
147
+ diffs = []
148
+
149
+ if @permissions != aws.permissions
150
+ diffs << GrantDiff.new(GrantChange::PERMISSIONS, aws, self)
151
+ end
152
+
153
+ diffs
154
+ end
155
+
156
+ # Public: Add permissions to the permissions of this Grant.
157
+ #
158
+ # permissions - an Array of the permissions to add
159
+ def add_permissions!(permissions)
160
+ @permissions = (@permissions + permissions).uniq.sort
161
+ end
162
+
163
+ # Public: Check GrantConfig equality with other objects.
164
+ #
165
+ # other - the other object to check
166
+ #
167
+ # Returns whether this GrantConfig is equal to `other`
168
+ def ==(other)
169
+ if !other.is_a? GrantConfig or
170
+ @name != other.name or
171
+ @email != other.email or
172
+ @permissions.sort != other.permissions.sort
173
+ false
174
+ else
175
+ true
176
+ end
177
+ end
178
+
179
+ # Public: Check if this GrantConfig is not equal to the other object
180
+ #
181
+ # other - the other object to check
182
+ #
183
+ # Returns whether this GrantConfig is not equal to `other`
184
+ def !=(other)
185
+ !(self == other)
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,50 @@
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 a Grant
8
+ module GrantChange
9
+ include Common::DiffChange
10
+
11
+ PERMISSIONS = Common::DiffChange.next_change_id
12
+ end
13
+
14
+ # Public: Represents a single difference between local configuration and
15
+ # an AWS Grant.
16
+ class GrantDiff < Common::Diff
17
+ include GrantChange
18
+
19
+ def initialize(type, aws = nil, local = nil)
20
+ super(type, aws, local)
21
+
22
+ if aws and local
23
+ @permissions = Common::ListChange.new(
24
+ local.permissions - aws.permissions,
25
+ aws.permissions - local.permissions
26
+ )
27
+ end
28
+ end
29
+
30
+ def asset_type
31
+ "Grant"
32
+ end
33
+
34
+ def aws_name
35
+ @aws.name
36
+ end
37
+
38
+ def diff_string
39
+ case @type
40
+ when PERMISSIONS
41
+ [
42
+ "#{@local.name}:",
43
+ @permissions.removed.map { |p| Colors.removed("\t#{p}") },
44
+ @permissions.added.map { |p| Colors.added("\t#{p}") },
45
+ ].flatten.join("\n")
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,142 @@
1
+ require "s3/models/LifecycleDiff"
2
+
3
+ module Cumulus
4
+ module S3
5
+ class LifecycleConfig
6
+ attr_reader :name
7
+ attr_reader :prefix
8
+ attr_reader :days_until_glacier
9
+ attr_reader :days_until_delete
10
+ attr_reader :past_days_until_glacier
11
+ attr_reader :past_days_until_delete
12
+
13
+ # Public: Constructor
14
+ #
15
+ # json - a hash representing the JSON configuration. Expects to be passed
16
+ # an object from the "lifecycle" array of S3 bucket configuration.
17
+ def initialize(json = nil)
18
+ if json
19
+ @name = json["name"]
20
+ @prefix = json["prefix"]
21
+ @days_until_glacier = json["days-until-glacier"]
22
+ @days_until_delete = json["days-until-delete"]
23
+ if json["past-versions"]
24
+ @past_days_until_glacier = json["past-versions"]["days-until-glacier"]
25
+ @past_days_until_delete = json["past-versions"]["days-until-delete"]
26
+ end
27
+ end
28
+ end
29
+
30
+ # Public: Populate this LifecycleConfig with the values in an AWS
31
+ # Configuration object.
32
+ #
33
+ # aws - the aws object to populate from
34
+ def populate!(aws)
35
+ @name = aws.id
36
+ @prefix = aws.prefix
37
+ @days_until_glacier = (aws.transition.days unless aws.transition.storage_class.downcase != "glacier") rescue nil
38
+ @days_until_delete = aws.expiration.days rescue nil
39
+ @past_days_until_glacier = (aws.noncurrent_version_transition.noncurrent_days unless aws.noncurrent_version_transition.storage_class.downcase != "glacier") rescue nil
40
+ @past_days_until_delete = aws.noncurrent_version_expiration.noncurrent_days rescue nil
41
+ end
42
+
43
+ # Public: Produce an AWS hash representing this LifecycleConfig.
44
+ #
45
+ # Returns the hash.
46
+ def to_aws
47
+ {
48
+ id: @name,
49
+ prefix: @prefix,
50
+ status: "Enabled",
51
+ transition: if @days_until_glacier then {
52
+ days: @days_until_glacier,
53
+ storage_class: "GLACIER"
54
+ } end,
55
+ expiration: if @days_until_delete then {
56
+ days: @days_until_delete
57
+ } end,
58
+ noncurrent_version_transition: if @past_days_until_glacier then {
59
+ noncurrent_days: @past_days_until_glacier,
60
+ storage_class: "GLACIER"
61
+ } end,
62
+ noncurrent_version_expiration: if @past_days_until_delete then {
63
+ noncurrent_days: @past_days_until_delete
64
+ } end
65
+ }.reject { |k, v| v.nil? }
66
+ end
67
+
68
+ # Public: Converts this LifecycleConfig to a hash that matches Cumulus
69
+ # configuration.
70
+ #
71
+ # Returns the hash.
72
+ def to_h
73
+ {
74
+ "name" => @name,
75
+ "prefix" => @prefix,
76
+ "days-until-glacier" => @days_until_glacier,
77
+ "days-until-delete" => @days_until_delete,
78
+ "past-versions" => if @past_days_until_glacier or @past_days_until_delete then {
79
+ "days-until-glacier" => @past_days_until_glacier,
80
+ "days-until-delete" => @past_days_until_delete,
81
+ }.reject { |k, v| v.nil? } end,
82
+ }.reject { |k, v| v.nil? }
83
+ end
84
+
85
+ # Public: Produce an array of differences between this local configuration
86
+ # and the configuration in AWS
87
+ #
88
+ # aws - the AWS resource
89
+ #
90
+ # Returns an array of LifecycleDiffs that were found
91
+ def diff(aws)
92
+ diffs = []
93
+
94
+ if @prefix != aws.prefix
95
+ diffs << LifecycleDiff.new(LifecycleChange::PREFIX, aws, self)
96
+ end
97
+ if @days_until_glacier != aws.days_until_glacier
98
+ diffs << LifecycleDiff.new(LifecycleChange::DAYS_UNTIL_GLACIER, aws, self)
99
+ end
100
+ if @days_until_delete != aws.days_until_delete
101
+ diffs << LifecycleDiff.new(LifecycleChange::DAYS_UNTIL_DELETE, aws, self)
102
+ end
103
+ if @past_days_until_glacier != aws.past_days_until_glacier
104
+ diffs << LifecycleDiff.new(LifecycleChange::PAST_UNTIL_GLACIER, aws, self)
105
+ end
106
+ if @past_days_until_delete != aws.past_days_until_delete
107
+ diffs << LifecycleDiff.new(LifecycleChange::PAST_UNTIL_DELETE, aws, self)
108
+ end
109
+
110
+ diffs
111
+ end
112
+
113
+ # Public: Check LifecycleConfig equality with other objects.
114
+ #
115
+ # other - the other object to check
116
+ #
117
+ # Returns whether this LifecycleConfig is equal to `other`
118
+ def ==(other)
119
+ if !other.is_a? LifecycleConfig or
120
+ @name != other.name or
121
+ @prefix != other.prefix or
122
+ @days_until_glacier != other.days_until_glacier or
123
+ @days_until_delete != other.days_until_delete or
124
+ @past_days_until_glacier != other.past_days_until_glacier or
125
+ @past_days_until_delete != other.past_days_until_delete
126
+ false
127
+ else
128
+ true
129
+ end
130
+ end
131
+
132
+ # Public: Check if this LifecycleConfig is not equal to the other object
133
+ #
134
+ # other - the other object to check
135
+ #
136
+ # Returns whether this LifecycleConfig is not equal to `other`
137
+ def !=(other)
138
+ !(self == other)
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,46 @@
1
+ require "common/models/Diff"
2
+ require "util/Colors"
3
+
4
+ module Cumulus
5
+ module S3
6
+ # Public: The types of changes that cna be made to an S3 Lifecycle Rule
7
+ module LifecycleChange
8
+ include Common::DiffChange
9
+
10
+ DAYS_UNTIL_DELETE = Common::DiffChange.next_change_id
11
+ DAYS_UNTIL_GLACIER = Common::DiffChange.next_change_id
12
+ PAST_UNTIL_DELETE = Common::DiffChange.next_change_id
13
+ PAST_UNTIL_GLACIER = Common::DiffChange.next_change_id
14
+ PREFIX = Common::DiffChange.next_change_id
15
+ end
16
+
17
+ # Public: Represents a single difference between local configuration and AWS
18
+ # lifecycle rule configuration
19
+ class LifecycleDiff < Common::Diff
20
+ include LifecycleChange
21
+
22
+ def asset_type
23
+ "Lifecycle rule"
24
+ end
25
+
26
+ def aws_name
27
+ @aws.name
28
+ end
29
+
30
+ def diff_string
31
+ case @type
32
+ when DAYS_UNTIL_DELETE
33
+ "Days before objects are deleted: AWS - #{Colors.aws_changes(@aws.days_until_delete)}, Local - #{Colors.local_changes(@local.days_until_delete)}"
34
+ when DAYS_UNTIL_GLACIER
35
+ "Days before transition to Glacier: AWS - #{Colors.aws_changes(@aws.days_until_glacier)}, Local - #{Colors.local_changes(@local.days_until_glacier)}"
36
+ when PAST_UNTIL_DELETE
37
+ "Days before past version objects are deleted: AWS - #{Colors.aws_changes(@aws.past_days_until_delete)}, Local - #{Colors.local_changes(@local.past_days_until_delete)}"
38
+ when PAST_UNTIL_GLACIER
39
+ "Days before past version transition to Glacier: AWS - #{Colors.aws_changes(@aws.past_days_until_glacier)}, Local - #{Colors.local_changes(@local.past_days_until_glacier)}"
40
+ when PREFIX
41
+ "Prefix - AWS #{Colors.aws_changes(@aws.prefix)}, Local - #{Colors.local_changes(@local.prefix)}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,81 @@
1
+ module Cumulus
2
+ module S3
3
+ class LoggingConfig
4
+ attr_reader :target_bucket
5
+ attr_reader :prefix
6
+
7
+ # Public: Constructor
8
+ #
9
+ # json - a hash representing the JSON configuration. Expects to be handed
10
+ # the 'logging' node of S3 configuration.
11
+ def initialize(json = nil)
12
+ if json
13
+ @target_bucket = json["target-bucket"]
14
+ @prefix = json["prefix"] || ""
15
+ end
16
+ end
17
+
18
+ # Public: Populate this LoggingConfig with the values in an AWS BucketLogging
19
+ # object.
20
+ #
21
+ # aws - the aws object to populate from
22
+ def populate!(aws)
23
+ @target_bucket = aws.logging_enabled.target_bucket
24
+ @prefix = aws.logging_enabled.target_prefix
25
+ end
26
+
27
+ # Public: Produce a hash that is compatible with AWS logging configuration.
28
+ #
29
+ # Returns the logging configuration in AWS format
30
+ def to_aws
31
+ {
32
+ target_bucket: @target_bucket,
33
+ target_prefix: @prefix
34
+ }
35
+ end
36
+
37
+ # Public: Convert this LoggingConfig to a hash that matches Cumulus
38
+ # configuration.
39
+ #
40
+ # Returns the hash
41
+ def to_h
42
+ {
43
+ "target-bucket" => @target_bucket,
44
+ "prefix" => @prefix,
45
+ }.reject { |k, v| v.nil? }
46
+ end
47
+
48
+ # Public: Check LoggingConfig equality with other objects
49
+ #
50
+ # other - the other object to check
51
+ #
52
+ # Returns whether this LoggingConfig is equal to `other`
53
+ def ==(other)
54
+ if !other.is_a? LoggingConfig or
55
+ @target_bucket != other.target_bucket or
56
+ @prefix != other.prefix
57
+ false
58
+ else
59
+ true
60
+ end
61
+ end
62
+
63
+ # Public: Check if this LoggingConfig is not equal to the other object
64
+ #
65
+ # other - the other object to check
66
+ #
67
+ # Returns whether this LoggingConfig is not equal to `other`
68
+ def !=(other)
69
+ !(self == other)
70
+ end
71
+
72
+ def to_s
73
+ if @target_bucket and @prefix
74
+ "Target bucket: #{@target_bucket} with prefix #{@prefix}"
75
+ elsif @target_bucket
76
+ "Target bucket: #{@target_bucket}"
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end