ey-core 3.4.0 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +27 -5
  5. data/Gemfile +0 -1
  6. data/README.md +65 -8
  7. data/Rakefile +4 -1
  8. data/ey-core.gemspec +9 -5
  9. data/features/accounts.feature +13 -0
  10. data/features/applications.feature +29 -0
  11. data/features/current_user.feature +14 -0
  12. data/features/docker_registry_credentials.feature +21 -0
  13. data/features/environment_variables.feature +54 -0
  14. data/features/environments.feature +30 -0
  15. data/features/init.feature +6 -0
  16. data/features/login.feature +6 -0
  17. data/features/scp.feature +6 -0
  18. data/features/step_definitions/accounts_steps.rb +37 -0
  19. data/features/step_definitions/applications_steps.rb +39 -0
  20. data/features/step_definitions/current_user_steps.rb +11 -0
  21. data/features/step_definitions/deprecated_command_steps.rb +3 -0
  22. data/features/step_definitions/docker_registry_credentials_steps.rb +3 -0
  23. data/features/step_definitions/environment_variables_steps.rb +51 -0
  24. data/features/step_definitions/environments_steps.rb +52 -0
  25. data/features/step_definitions/version_steps.rb +3 -0
  26. data/features/support/account_helpers.rb +89 -0
  27. data/features/support/app_helpers.rb +19 -0
  28. data/features/support/aruba.rb +1 -0
  29. data/features/support/boilerplate.rb +1 -0
  30. data/features/support/client_helpers.rb +36 -0
  31. data/features/support/config_file_helpers.rb +42 -0
  32. data/features/support/core.rb +19 -0
  33. data/features/support/deployment_helpers.rb +19 -0
  34. data/features/support/env.rb +40 -0
  35. data/features/support/environment_helpers.rb +23 -0
  36. data/features/support/environment_variable_helpers.rb +20 -0
  37. data/features/support/fake_kernel.rb +23 -0
  38. data/features/support/io.rb +5 -0
  39. data/features/support/mock_api.rb +20 -0
  40. data/features/support/output_helpers.rb +7 -0
  41. data/features/support/resource_helpers.rb +201 -0
  42. data/features/support/server_helpers.rb +27 -0
  43. data/features/version.feature +8 -0
  44. data/features/whoami.feature +14 -0
  45. data/lib/ey-core/cli/deploy.rb +4 -4
  46. data/lib/ey-core/cli/docker_registry_login.rb +29 -0
  47. data/lib/ey-core/cli/environment_variables.rb +71 -0
  48. data/lib/ey-core/cli/helpers/core.rb +29 -0
  49. data/lib/ey-core/cli/main.rb +5 -4
  50. data/lib/ey-core/cli/servers.rb +35 -17
  51. data/lib/ey-core/cli/ssh.rb +1 -1
  52. data/lib/ey-core/client.rb +35 -0
  53. data/lib/ey-core/client/mock.rb +5 -0
  54. data/lib/ey-core/collections/auto_scaling_alarms.rb +8 -0
  55. data/lib/ey-core/collections/auto_scaling_groups.rb +8 -0
  56. data/lib/ey-core/collections/auto_scaling_policies.rb +33 -0
  57. data/lib/ey-core/collections/container_clusters.rb +9 -0
  58. data/lib/ey-core/collections/container_service_deployments.rb +17 -0
  59. data/lib/ey-core/collections/environment_variables.rb +8 -0
  60. data/lib/ey-core/collections/servers.rb +4 -0
  61. data/lib/ey-core/models/account.rb +10 -0
  62. data/lib/ey-core/models/address.rb +2 -0
  63. data/lib/ey-core/models/application.rb +1 -0
  64. data/lib/ey-core/models/auto_scaling_alarm.rb +54 -0
  65. data/lib/ey-core/models/auto_scaling_group.rb +75 -0
  66. data/lib/ey-core/models/base_auto_scaling_policy.rb +61 -0
  67. data/lib/ey-core/models/container_service_deployment.rb +17 -0
  68. data/lib/ey-core/models/environment.rb +60 -47
  69. data/lib/ey-core/models/environment_variable.rb +29 -0
  70. data/lib/ey-core/models/request.rb +6 -0
  71. data/lib/ey-core/models/server.rb +2 -0
  72. data/lib/ey-core/models/simple_auto_scaling_policy.rb +24 -0
  73. data/lib/ey-core/models/step_auto_scaling_policy.rb +24 -0
  74. data/lib/ey-core/models/target_auto_scaling_policy.rb +24 -0
  75. data/lib/ey-core/requests/boot_environment.rb +1 -1
  76. data/lib/ey-core/requests/create_account.rb +5 -0
  77. data/lib/ey-core/requests/create_address.rb +1 -0
  78. data/lib/ey-core/requests/create_application.rb +8 -7
  79. data/lib/ey-core/requests/create_auto_scaling_alarm.rb +69 -0
  80. data/lib/ey-core/requests/create_auto_scaling_group.rb +62 -0
  81. data/lib/ey-core/requests/create_auto_scaling_policy.rb +68 -0
  82. data/lib/ey-core/requests/create_environment.rb +2 -0
  83. data/lib/ey-core/requests/create_environment_variable.rb +39 -0
  84. data/lib/ey-core/requests/create_user.rb +8 -6
  85. data/lib/ey-core/requests/destroy_auto_scaling_alarm.rb +49 -0
  86. data/lib/ey-core/requests/destroy_auto_scaling_group.rb +44 -0
  87. data/lib/ey-core/requests/destroy_auto_scaling_policy.rb +49 -0
  88. data/lib/ey-core/requests/discover_container_service_deployments.rb +71 -0
  89. data/lib/ey-core/requests/discover_server.rb +60 -0
  90. data/lib/ey-core/requests/get_applications.rb +1 -1
  91. data/lib/ey-core/requests/get_auto_scaling_alarm.rb +27 -0
  92. data/lib/ey-core/requests/get_auto_scaling_alarms.rb +34 -0
  93. data/lib/ey-core/requests/get_auto_scaling_group.rb +21 -0
  94. data/lib/ey-core/requests/get_auto_scaling_groups.rb +29 -0
  95. data/lib/ey-core/requests/get_auto_scaling_policies.rb +46 -0
  96. data/lib/ey-core/requests/get_auto_scaling_policy.rb +27 -0
  97. data/lib/ey-core/requests/get_deployments.rb +1 -1
  98. data/lib/ey-core/requests/get_environment_variable.rb +19 -0
  99. data/lib/ey-core/requests/get_environment_variables.rb +29 -0
  100. data/lib/ey-core/requests/get_environments.rb +1 -1
  101. data/lib/ey-core/requests/get_ssl_certificate.rb +1 -1
  102. data/lib/ey-core/requests/retrieve_docker_registry_credentials.rb +24 -0
  103. data/lib/ey-core/requests/update_auto_scaling_alarm.rb +45 -0
  104. data/lib/ey-core/requests/update_auto_scaling_group.rb +45 -0
  105. data/lib/ey-core/requests/update_auto_scaling_policy.rb +46 -0
  106. data/lib/ey-core/requests/update_environment_variable.rb +25 -0
  107. data/lib/ey-core/test_helpers.rb +2 -0
  108. data/lib/ey-core/test_helpers/auto_scaling_helpers.rb +35 -0
  109. data/lib/ey-core/version.rb +1 -1
  110. data/spec/addresses_spec.rb +2 -1
  111. data/spec/auto_scaling_alarms_spec.rb +40 -0
  112. data/spec/auto_scaling_groups_spec.rb +28 -0
  113. data/spec/auto_scaling_policies_spec.rb +94 -0
  114. data/spec/docker_registry_credentials_spec.rb +16 -0
  115. data/spec/environments_spec.rb +18 -0
  116. data/spec/servers_spec.rb +8 -0
  117. data/spec/spec_helper.rb +7 -0
  118. data/spec/support/core.rb +0 -2
  119. metadata +192 -18
@@ -7,6 +7,7 @@ class Ey::Core::Client::Address < Ey::Core::Model
7
7
  attribute :ip_address
8
8
  attribute :provisioned_id
9
9
  attribute :location
10
+ attribute :scope
10
11
  attribute :disappeared_at, type: :time
11
12
 
12
13
  has_one :provider
@@ -37,6 +38,7 @@ class Ey::Core::Client::Address < Ey::Core::Model
37
38
  "provider" => self.provider_id,
38
39
  "address" => {
39
40
  "location" => self.location,
41
+ "scope" => self.scope,
40
42
  },
41
43
  }
42
44
 
@@ -12,6 +12,7 @@ class Ey::Core::Client::Application < Ey::Core::Model
12
12
 
13
13
  has_many :archives, key: :application_archives
14
14
  has_many :keypairs
15
+ has_many :environment_variables
15
16
 
16
17
  def save!
17
18
  params = {
@@ -0,0 +1,54 @@
1
+ class Ey::Core::Client::AutoScalingAlarm < Ey::Core::Model
2
+ extend Ey::Core::Associations
3
+
4
+ identity :id
5
+
6
+ attribute :deleted_at, type: :time
7
+ attribute :created_at, type: :time
8
+ attribute :updated_at, type: :time
9
+ attribute :auto_scaling_policy_id, aliases: "auto_scaling_policy", squash: ["id"]
10
+ attribute :name
11
+ attribute :aggregation_type
12
+ attribute :metric_type
13
+ attribute :operand
14
+ attribute :trigger_value, type: :float
15
+ attribute :number_of_periods, type: :integer
16
+ attribute :period_length, type: :integer
17
+ attribute :provisioned_id
18
+
19
+ has_one :auto_scaling_policy
20
+
21
+ def save!
22
+ requires :auto_scaling_policy_id, :trigger_value, :period_length
23
+ params = {
24
+ "auto_scaling_alarm" => {
25
+ "name" => name,
26
+ "trigger_value" => trigger_value,
27
+ "aggregation_type" => aggregation_type,
28
+ "metric_type" => metric_type,
29
+ "operand" => operand,
30
+ "period_length" => period_length,
31
+ "number_of_periods" => number_of_periods
32
+ },
33
+ "auto_scaling_policy_id" => auto_scaling_policy_id
34
+ }
35
+
36
+ if new_record?
37
+ requires :name
38
+ request_attributes = connection.create_auto_scaling_alarm(params).body["request"]
39
+ connection.requests.new(request_attributes)
40
+ else
41
+ requires :identity
42
+ params.merge!("id" => identity)
43
+ connection.requests.new(connection.update_auto_scaling_alarm(params).body["request"])
44
+ end
45
+ end
46
+
47
+ def destroy!
48
+ requires :identity
49
+
50
+ connection.requests.new(
51
+ connection.destroy_auto_scaling_alarm("id" => identity).body["request"]
52
+ )
53
+ end
54
+ end
@@ -0,0 +1,75 @@
1
+ class Ey::Core::Client::AutoScalingGroup < Ey::Core::Model
2
+ extend Ey::Core::Associations
3
+
4
+ identity :id
5
+
6
+ attribute :created_at, type: :time
7
+ attribute :deleted_at, type: :time
8
+ attribute :location_id
9
+ attribute :provisioned_id
10
+ attribute :minimum_size
11
+ attribute :maximum_size
12
+ attribute :desired_capacity
13
+ attribute :default_cooldown
14
+ attribute :grace_period
15
+
16
+ has_one :environment
17
+
18
+ def destroy
19
+ connection.requests.new(connection.destroy_auto_scaling_group("id" => self.identity).body["request"])
20
+ end
21
+
22
+ def save!
23
+ if new_record?
24
+ requires :maximum_size, :minimum_size, :environment
25
+
26
+ params = {
27
+ "url" => self.collection.url,
28
+ "environment" => self.environment_id,
29
+ "auto_scaling_group" => {
30
+ "maximum_size" => self.maximum_size,
31
+ "minimum_size" => self.minimum_size,
32
+ }
33
+ }
34
+
35
+ connection.requests.new(connection.create_auto_scaling_group(params).body["request"])
36
+ else
37
+ requires :identity
38
+
39
+ params = {
40
+ "id" => self.identity,
41
+ "auto_scaling_group" => {
42
+ "maximum_size" => self.maximum_size,
43
+ "minimum_size" => self.minimum_size,
44
+ "desired_capacity" => self.desired_capacity
45
+ }
46
+ }
47
+
48
+ connection.requests.new(connection.update_auto_scaling_group(params).body["request"])
49
+ end
50
+ end
51
+
52
+ def simple_auto_scaling_policies
53
+ auto_scaling_policies("simple")
54
+ end
55
+
56
+ def step_auto_scaling_policies
57
+ auto_scaling_policies("step")
58
+ end
59
+
60
+ def target_auto_scaling_policies
61
+ auto_scaling_policies("target")
62
+ end
63
+
64
+ private
65
+
66
+ def auto_scaling_policies(types = nil)
67
+ requires :identity
68
+ data = connection.get_auto_scaling_policies(
69
+ "auto_scaling_group" => identity,
70
+ "types" => [*types]
71
+ ).body["auto_scaling_policies"]
72
+
73
+ connection.auto_scaling_policies.load(data)
74
+ end
75
+ end
@@ -0,0 +1,61 @@
1
+ class Ey::Core::Client::BaseAutoScalingPolicy < Ey::Core::Model
2
+ extend Ey::Core::Associations
3
+
4
+ identity :id, type: :integer
5
+
6
+ attribute :provisioned_id
7
+ attribute :provisioner_id
8
+ attribute :type
9
+ attribute :name
10
+ attribute :configuration
11
+ attribute :auto_scaling_group_id
12
+
13
+ has_one :auto_scaling_group
14
+
15
+ def save!
16
+ requires :auto_scaling_group_id, :type
17
+ params = {
18
+ "url" => self.collection.url,
19
+ "auto_scaling_policy" => {
20
+ "name" => self.name
21
+ }.merge(policy_params),
22
+ "auto_scaling_group_id" => self.auto_scaling_group_id
23
+ }
24
+
25
+ if new_record?
26
+ policy_requires
27
+ requires :name
28
+ connection.requests.new(connection.create_auto_scaling_policy(params).body["request"])
29
+ else
30
+ requires :identity
31
+ params.merge("id" => identity)
32
+ connection.requests.new(connection.update_auto_scaling_policy(params).body["request"])
33
+ end
34
+ end
35
+
36
+ def destroy!
37
+ connection.requests.new(
38
+ self.connection.destroy_auto_scaling_policy("id" => self.id).body["request"]
39
+ )
40
+ end
41
+
42
+ def alarm
43
+ requires :identity
44
+
45
+ data = self.connection.get_auto_scaling_alarms(
46
+ "auto_scaling_policy_id" => identity
47
+ ).body["auto_scaling_alarms"]
48
+
49
+ self.connection.auto_scaling_alarms.load(data).first
50
+ end
51
+
52
+ private
53
+
54
+ def policy_params
55
+ raise NotImplementedError
56
+ end
57
+
58
+ def policy_requires
59
+ raise NotImplementedError
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ class Ey::Core::Client::ContainerServiceDeployment < Ey::Core::Model
2
+ extend Ey::Core::Associations
3
+
4
+ identity :id
5
+
6
+ attribute :container_service_id
7
+ attribute :public_ip_address
8
+ attribute :private_ip_address
9
+ attribute :port_mappings
10
+ attribute :health_status
11
+ attribute :container_health_status
12
+ attribute :container_instance_id
13
+ attribute :task_arn
14
+ attribute :created_at, type: :time
15
+ attribute :updated_at, type: :time
16
+ attribute :deleted_at, type: :time
17
+ end
@@ -17,10 +17,14 @@ class Ey::Core::Client::Environment < Ey::Core::Model
17
17
  attribute :release_label
18
18
  attribute :stack_name
19
19
  attribute :username
20
+ attribute :service_level
21
+ attribute :database_backup_limit
22
+ attribute :encrypted_ebs_for_everything
20
23
 
21
24
  has_one :account
22
25
  has_one :database_service
23
26
  has_one :firewall
27
+ has_one :auto_scaling_group
24
28
  has_one :assignee, assoc_name: :user, resource: :user
25
29
 
26
30
  has_many :costs
@@ -29,6 +33,7 @@ class Ey::Core::Client::Environment < Ey::Core::Model
29
33
  has_many :applications
30
34
  has_many :logical_databases
31
35
  has_many :deployments
36
+ has_many :environment_variables
32
37
 
33
38
  attr_accessor :application_id
34
39
 
@@ -125,21 +130,70 @@ class Ey::Core::Client::Environment < Ey::Core::Model
125
130
 
126
131
  def boot(options={})
127
132
  options = Cistern::Hash.stringify_keys(options)
133
+ connection.requests.new(self.connection.boot_environment(boot_params(options)).body["request"])
134
+ end
135
+
136
+ def unassign!
137
+ requires :id
138
+ merge_attributes(self.connection.unassign_environment("id" => self.id).body["environment"])
139
+ end
140
+
141
+ def save!
142
+ if new_record?
143
+ requires :application_id, :account_id, :region
144
+
145
+ params = {
146
+ "url" => self.collection.url,
147
+ "account" => self.account_id,
148
+ "environment" => {
149
+ "name" => self.name,
150
+ "application_id" => self.application_id,
151
+ "region" => self.region,
152
+ "stack_name" => self.stack_name,
153
+ "database_stack" => self.database_stack,
154
+ "release_label" => self.release_label,
155
+ "language" => self.language,
156
+ "database_backup_limit" => self.database_backup_limit,
157
+ "encrypted_ebs_for_everything" => self.encrypted_ebs_for_everything,
158
+ },
159
+ }
160
+
161
+ params["environment"].merge!("database_service" => self.database_service.id) if self.database_service
162
+
163
+ merge_attributes(self.connection.create_environment(params).body["environment"])
164
+ else
165
+ requires :identity
166
+ attributes = Cistern::Hash.slice(Cistern::Hash.stringify_keys(self.attributes), "nane", "release_label")
167
+ connection.update_environment(
168
+ "id" => self.identity,
169
+ "environment" => attributes,
170
+ )
171
+ end
172
+ end
173
+
174
+ private
175
+
176
+ def boot_params(options)
177
+ params = {
178
+ "cluster_configuration" => {}
179
+ }
180
+
128
181
  if options["blueprint_id"]
129
182
  params = {
130
183
  "cluster_configuration" => {
131
- "blueprint_id" => options["blueprint_id"]
184
+ "blueprint_id" => options["blueprint_id"],
185
+ "configuration" => {}
132
186
  }
133
187
  }
134
188
  if ip_id = options["ip_id"]
135
- params["cluster_configuration"]["ip_id"] = ip_id
189
+ params["cluster_configuration"]["configuration"]["ip_id"] = ip_id
136
190
  end
137
-
138
- self.connection.requests.new(self.connection.boot_environment(params.merge("id" => self.id)).body["request"])
139
191
  else
140
192
  raise "configuration is a required key" unless options["configuration"]
141
193
  raise "configuration['type'] is required" unless options["configuration"]["type"]
194
+ end
142
195
 
196
+ if options['configuration']
143
197
  missing_keys = []
144
198
 
145
199
  configuration = options["configuration"]
@@ -187,49 +241,8 @@ class Ey::Core::Client::Environment < Ey::Core::Model
187
241
  raise "Invalid configuration - The following keys are missing from the configuration:\n#{missing_keys.join(",\n")}"
188
242
  end
189
243
 
190
- params = {
191
- "cluster_configuration" => {
192
- "configuration" => configuration
193
- }
194
- }
195
-
196
- connection.requests.new(self.connection.boot_environment(params.merge("id" => self.id)).body["request"])
197
- end
198
- end
199
-
200
- def unassign!
201
- requires :id
202
- merge_attributes(self.connection.unassign_environment("id" => self.id).body["environment"])
203
- end
204
-
205
- def save!
206
- if new_record?
207
- requires :application_id, :account_id, :region
208
-
209
- params = {
210
- "url" => self.collection.url,
211
- "account" => self.account_id,
212
- "environment" => {
213
- "name" => self.name,
214
- "application_id" => self.application_id,
215
- "region" => self.region,
216
- "stack_name" => self.stack_name,
217
- "database_stack" => self.database_stack,
218
- "release_label" => self.release_label,
219
- "language" => self.language,
220
- },
221
- }
222
-
223
- params["environment"].merge!("database_service" => self.database_service.id) if self.database_service
224
-
225
- merge_attributes(self.connection.create_environment(params).body["environment"])
226
- else
227
- requires :identity
228
- attributes = Cistern::Hash.slice(Cistern::Hash.stringify_keys(self.attributes), "nane", "release_label")
229
- connection.update_environment(
230
- "id" => self.identity,
231
- "environment" => attributes,
232
- )
244
+ params["cluster_configuration"]["configuration"] = configuration
233
245
  end
246
+ params.merge("id" => self.id)
234
247
  end
235
248
  end
@@ -0,0 +1,29 @@
1
+ class Ey::Core::Client::EnvironmentVariable < Ey::Core::Model
2
+ extend Ey::Core::Associations
3
+
4
+ identity :id
5
+
6
+ attribute :application_id
7
+ attribute :application_name
8
+ attribute :environment_id
9
+ attribute :environment_name
10
+ attribute :name
11
+ attribute :value
12
+ attribute :sensitive
13
+
14
+ has_one :environment
15
+ has_one :application
16
+
17
+ def save!
18
+ requires :name, :value
19
+ params = Cistern::Hash.slice(Cistern::Hash.stringify_keys(attributes), "id", "name", "value")
20
+
21
+ if new_record?
22
+ requires :application_id, :environment_id
23
+ params.merge!("application_id" => application_id, "environment_id" => environment_id)
24
+ merge_attributes(self.connection.create_environment_variable(params).body["environment_variable"])
25
+ else
26
+ merge_attributes(self.connection.update_environment_variable(params).body["environment_variable"])
27
+ end
28
+ end
29
+ end
@@ -53,6 +53,12 @@ class Ey::Core::Client::Request < Ey::Core::Model
53
53
  case type
54
54
  when /address/
55
55
  self.connection.addresses.get!(resource_id)
56
+ when /auto_scaling_group/
57
+ self.connection.auto_scaling_groups.get!(resource_id)
58
+ when /auto_scaling_policy/
59
+ self.connection.auto_scaling_policies.get(resource_id)
60
+ when /auto_scaling_alarm/
61
+ self.connection.auto_scaling_alarms.get(resource_id)
56
62
  when /cluster_update/
57
63
  self.connection.cluster_updates.get!(resource_id)
58
64
  when /database_server_snapshot/
@@ -26,6 +26,7 @@ class Ey::Core::Client::Server < Ey::Core::Model
26
26
  attribute :updated_at, type: :time
27
27
  attribute :wait_for_chef, type: :boolean
28
28
  attribute :release_label
29
+ attribute :ip_id
29
30
 
30
31
  has_one :account
31
32
  has_one :address, collection: "addresses"
@@ -117,6 +118,7 @@ class Ey::Core::Client::Server < Ey::Core::Model
117
118
  "release_label" => self.release_label,
118
119
  "role" => self.role,
119
120
  "volume_size" => self.volume_size,
121
+ "ip_id" => self.ip_id
120
122
  }
121
123
  }
122
124
  connection.requests.new(connection.create_server(server_attributes).body["request"])
@@ -0,0 +1,24 @@
1
+ class Ey::Core::Client::SimpleAutoScalingPolicy < Ey::Core::Client::BaseAutoScalingPolicy
2
+ identity :id
3
+ attribute :auto_scaling_group_id, aliases: "auto_scaling_group", squash: ["id"]
4
+ attribute :cooldown, type: :integer
5
+ attribute :action_unit
6
+ attribute :action_type
7
+ attribute :action_value
8
+
9
+ has_many :auto_scaling_alarms
10
+
11
+ def policy_params
12
+ {
13
+ "cooldown" => cooldown,
14
+ "action_unit" => action_unit,
15
+ "action_type" => action_type,
16
+ "action_value" => action_value,
17
+ "type" => type
18
+ }
19
+ end
20
+
21
+ def policy_requires
22
+ requires :action_value, :action_type, :action_unit
23
+ end
24
+ end