ey-core 3.4.4 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -3
  3. data/bin/ey-core +8 -0
  4. data/features/environment_variables.feature +54 -0
  5. data/features/step_definitions/accounts_steps.rb +14 -0
  6. data/features/step_definitions/applications_steps.rb +7 -14
  7. data/features/step_definitions/environment_variables_steps.rb +51 -0
  8. data/features/step_definitions/environments_steps.rb +15 -0
  9. data/features/support/environment_variable_helpers.rb +20 -0
  10. data/features/support/resource_helpers.rb +12 -0
  11. data/lib/ey-core/cli/environment_variables.rb +71 -0
  12. data/lib/ey-core/cli/helpers/core.rb +29 -0
  13. data/lib/ey-core/cli/main.rb +2 -0
  14. data/lib/ey-core/cli/servers.rb +34 -17
  15. data/lib/ey-core/client.rb +23 -0
  16. data/lib/ey-core/client/mock.rb +3 -0
  17. data/lib/ey-core/collections/auto_scaling_alarms.rb +8 -0
  18. data/lib/ey-core/collections/auto_scaling_policies.rb +33 -0
  19. data/lib/ey-core/collections/environment_variables.rb +8 -0
  20. data/lib/ey-core/models/address.rb +2 -0
  21. data/lib/ey-core/models/application.rb +1 -0
  22. data/lib/ey-core/models/auto_scaling_alarm.rb +54 -0
  23. data/lib/ey-core/models/auto_scaling_group.rb +26 -0
  24. data/lib/ey-core/models/base_auto_scaling_policy.rb +61 -0
  25. data/lib/ey-core/models/environment.rb +53 -47
  26. data/lib/ey-core/models/environment_variable.rb +29 -0
  27. data/lib/ey-core/models/request.rb +4 -0
  28. data/lib/ey-core/models/simple_auto_scaling_policy.rb +24 -0
  29. data/lib/ey-core/models/step_auto_scaling_policy.rb +24 -0
  30. data/lib/ey-core/models/target_auto_scaling_policy.rb +24 -0
  31. data/lib/ey-core/requests/create_account.rb +5 -0
  32. data/lib/ey-core/requests/create_address.rb +1 -0
  33. data/lib/ey-core/requests/create_application.rb +8 -7
  34. data/lib/ey-core/requests/create_auto_scaling_alarm.rb +69 -0
  35. data/lib/ey-core/requests/create_auto_scaling_policy.rb +68 -0
  36. data/lib/ey-core/requests/create_environment.rb +2 -1
  37. data/lib/ey-core/requests/create_environment_variable.rb +39 -0
  38. data/lib/ey-core/requests/create_user.rb +8 -6
  39. data/lib/ey-core/requests/destroy_auto_scaling_alarm.rb +49 -0
  40. data/lib/ey-core/requests/destroy_auto_scaling_policy.rb +49 -0
  41. data/lib/ey-core/requests/get_applications.rb +1 -1
  42. data/lib/ey-core/requests/get_auto_scaling_alarm.rb +27 -0
  43. data/lib/ey-core/requests/get_auto_scaling_alarms.rb +34 -0
  44. data/lib/ey-core/requests/get_auto_scaling_policies.rb +46 -0
  45. data/lib/ey-core/requests/get_auto_scaling_policy.rb +27 -0
  46. data/lib/ey-core/requests/get_environment_variable.rb +19 -0
  47. data/lib/ey-core/requests/get_environment_variables.rb +29 -0
  48. data/lib/ey-core/requests/get_environments.rb +1 -1
  49. data/lib/ey-core/requests/update_auto_scaling_alarm.rb +45 -0
  50. data/lib/ey-core/requests/update_auto_scaling_policy.rb +46 -0
  51. data/lib/ey-core/requests/update_environment_variable.rb +25 -0
  52. data/lib/ey-core/test_helpers.rb +2 -0
  53. data/lib/ey-core/test_helpers/auto_scaling_helpers.rb +35 -0
  54. data/lib/ey-core/version.rb +1 -1
  55. data/spec/addresses_spec.rb +2 -1
  56. data/spec/auto_scaling_alarms_spec.rb +40 -0
  57. data/spec/auto_scaling_policies_spec.rb +94 -0
  58. data/spec/spec_helper.rb +7 -0
  59. metadata +37 -2
@@ -17,7 +17,7 @@ class Ey::Core::Client
17
17
  def get_applications(params={})
18
18
  extract_url_params!(params)
19
19
 
20
- headers, applications_page = search_and_page(params, :applications, search_keys: %w[type repository account name environment])
20
+ headers, applications_page = search_and_page(params, :applications, search_keys: %w[id type repository account name environment])
21
21
 
22
22
  response(
23
23
  :body => {"applications" => applications_page},
@@ -0,0 +1,27 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_alarm(params = {})
4
+ id = params["id"]
5
+ url = params["url"]
6
+
7
+ request(
8
+ :method => :get,
9
+ :path => "auto_scaling_alarms/#{id}",
10
+ :url => url
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def get_auto_scaling_alarm(params = {})
17
+ response(
18
+ :body => {
19
+ "auto_scaling_alarm" => self.find(
20
+ :auto_scaling_alarms,
21
+ resource_identity(params)
22
+ )
23
+ },
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_alarms(params = {})
4
+ query = Ey::Core.paging_parameters(params)
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :params => params,
9
+ :path => "/auto_scaling_alarms",
10
+ :query => params,
11
+ :url => url,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_auto_scaling_alarms(params = {})
18
+ extract_url_params!(params)
19
+
20
+ headers, auto_scaling_alarms_page = search_and_page(
21
+ params,
22
+ :auto_scaling_alarms,
23
+ search_keys: %w{ id auto_scaling_policy },
24
+ resources: data[:auto_scaling_alarms]
25
+ )
26
+
27
+ response(
28
+ :body => { "auto_scaling_alarms" => auto_scaling_alarms_page },
29
+ :status => 200,
30
+ :headers => headers
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_policies(params = {})
4
+ query = Ey::Core.paging_parameters(params)
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :params => params,
9
+ :path => "/auto_scaling_policies",
10
+ :query => params,
11
+ :url => url,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_auto_scaling_policies(params = {})
18
+ extract_url_params!(params)
19
+
20
+ resources = data[:auto_scaling_policies].select { |_key, policy| filter_policy(params, policy) }
21
+ params.delete("types")
22
+
23
+ headers, auto_scaling_policies_page = search_and_page(
24
+ params,
25
+ :auto_scaling_policies,
26
+ search_keys: %w{ id auto_scaling_group },
27
+ resources: resources
28
+ )
29
+
30
+ response(
31
+ :body => { "auto_scaling_policies" => auto_scaling_policies_page },
32
+ :status => 200,
33
+ :headers => headers
34
+ )
35
+ end
36
+
37
+ private
38
+
39
+ def filter_policy(params, item)
40
+ return false if params["auto_scaling_group"] != item["auto_scaling_group"]
41
+
42
+ types = params["types"]
43
+ types.is_a?(::Array) && types.include?(item["type"])
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_auto_scaling_policy(params = {})
4
+ id = params["id"]
5
+ url = params["url"]
6
+
7
+ request(
8
+ :method => :get,
9
+ :path => "auto_scaling_policies/#{id}",
10
+ :url => url
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def get_auto_scaling_policy(params = {})
17
+ response(
18
+ :body => {
19
+ "auto_scaling_policy" => self.find(
20
+ :auto_scaling_policies,
21
+ resource_identity(params)
22
+ )
23
+ },
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_environment_variable(params={})
4
+ id = params.delete("id")
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :path => "environment_variables/#{id}",
9
+ :url => url,
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def get_environment_variable(params={})
16
+ response(body: {"environment_variable" => find(:environment_variables, resource_identity(params))})
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_environment_variables(params={})
4
+ query = Ey::Core.paging_parameters(params)
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :params => params,
9
+ :path => "/environment_variables",
10
+ :query => params,
11
+ :url => url,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_environment_variables(params={})
18
+ extract_url_params!(params)
19
+
20
+ headers, environment_variables_page = search_and_page(params, :environment_variables, search_keys: %w(environment application))
21
+
22
+ response(
23
+ :body => {"environment_variables" => environment_variables_page},
24
+ :status => 200,
25
+ :headers => headers
26
+ )
27
+ end
28
+ end
29
+ end
@@ -17,7 +17,7 @@ class Ey::Core::Client
17
17
  def get_environments(params={})
18
18
  extract_url_params!(params)
19
19
 
20
- headers, environments_page = search_and_page(params, :environments, search_keys: %w[account name])
20
+ headers, environments_page = search_and_page(params, :environments, search_keys: %w[id account name])
21
21
 
22
22
  response(
23
23
  :body => {"environments" => environments_page},
@@ -0,0 +1,45 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def update_auto_scaling_alarm(params = {})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/auto_scaling_alarms/#{id}",
9
+ :body => { "auto_scaling_alarm" => params.fetch("auto_scaling_alarm") },
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def update_auto_scaling_alarm(params = {})
16
+ resource_id = params.delete("id")
17
+ now = Time.now
18
+ resource = find(:auto_scaling_alarms, resource_id)
19
+ .merge(params["auto_scaling_alarm"])
20
+ .merge("updated_at" => now)
21
+ resource.merge!(params)
22
+
23
+ request = {
24
+ "id" => self.uuid,
25
+ "type" => "update_auto_scaling_alarm",
26
+ "successful" => true,
27
+ "created_at" => now - 5,
28
+ "started_at" => now - 3,
29
+ "finished_at" => now,
30
+ "updated_at" => now,
31
+ "message" => nil,
32
+ "read_channel" => nil,
33
+ "resource" => [:auto_scaling_alarms, resource_id, resource],
34
+ "resource_url" => url_for("/auto_scaling_alarms/#{resource_id}")
35
+ }
36
+
37
+ self.data[:requests][request["id"]] = request
38
+
39
+ response(
40
+ body: { "request" => request },
41
+ status: 200
42
+ )
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def update_auto_scaling_policy(params = {})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/auto_scaling_policies/#{id}",
9
+ :body => { "auto_scaling_policy" => params.fetch("auto_scaling_policy") },
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def update_auto_scaling_policy(params = {})
16
+ resource_id = params.delete("id")
17
+ now = Time.now
18
+
19
+ resource = find(:auto_scaling_policies, resource_id)
20
+ .merge(params["auto_scaling_policy"])
21
+ .merge("updated_at" => now)
22
+ resource.merge!(params)
23
+
24
+ request = {
25
+ "id" => self.uuid,
26
+ "type" => "update_auto_scaling_policy",
27
+ "successful" => true,
28
+ "created_at" => now - 5,
29
+ "updated_at" => now,
30
+ "started_at" => now - 3,
31
+ "finished_at" => now,
32
+ "message" => nil,
33
+ "read_channel" => nil,
34
+ "resource" => [:auto_scaling_policies, resource_id, resource],
35
+ "resource_url" => url_for("/auto_scaling_policies/#{resource_id}")
36
+ }
37
+
38
+ self.data[:requests][request["id"]] = request
39
+
40
+ response(
41
+ body: { "request" => request },
42
+ status: 200
43
+ )
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def update_environment_variable(_params={})
4
+ params = Cistern::Hash.stringify_keys(_params)
5
+ id = params.delete("id")
6
+ body = { environment_variable: params }
7
+
8
+ request(
9
+ :method => :put,
10
+ :path => "/environment_variables/#{id}",
11
+ :body => body
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def update_environment_variable(_params={})
18
+ params = Cistern::Hash.stringify_keys(_params).merge!("updated_at" => Time.now)
19
+ environment_variable = find(:environment_variables, params.delete("id"))
20
+ environment_variable.merge!(params)
21
+
22
+ response(:body => { "environment_variable" => environment_variable })
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,7 @@ require 'ey-core/test_helpers/account_helpers'
2
2
  require 'ey-core/test_helpers/alert_helpers'
3
3
  require 'ey-core/test_helpers/client_helpers'
4
4
  require 'ey-core/test_helpers/resource_helpers'
5
+ require 'ey-core/test_helpers/auto_scaling_helpers'
5
6
 
6
7
  module Ey
7
8
  module Core
@@ -10,6 +11,7 @@ module Ey
10
11
  include AlertHelpers
11
12
  include ClientHelpers
12
13
  include ResourceHelpers
14
+ include AutoScalingHelpers
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,35 @@
1
+ module Ey
2
+ module Core
3
+ module TestHelpers
4
+ module AutoScalingHelpers
5
+ def create_auto_scaling_group(options = {})
6
+ environment = options[:environment] || create_environment
7
+
8
+ groups = client.auto_scaling_groups
9
+
10
+ groups.create!(
11
+ minimum_size: 2,
12
+ maximum_size: 6,
13
+ environment: environment
14
+ ).resource!
15
+ end
16
+
17
+ def create_auto_scaling_policy(options = {})
18
+ group = options.delete(:auto_scaling_group) || create_auto_scaling_group
19
+ policies = client.auto_scaling_policies
20
+
21
+ policies.create!(
22
+ {
23
+ auto_scaling_group_id: group.id,
24
+ action_value: 2,
25
+ action_unit: "instances",
26
+ action_type: "add",
27
+ name: SecureRandom.hex(16),
28
+ type: "simple"
29
+ }.merge(options)
30
+ ).resource!
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Ey
2
2
  module Core
3
- VERSION = "3.4.4"
3
+ VERSION = "3.5.0"
4
4
  end
5
5
  end
@@ -6,12 +6,13 @@ describe 'addresses' do
6
6
  let!(:provider) { create_provider(account: account) }
7
7
 
8
8
  it "creates an address" do
9
- request = client.addresses.create!(provider: provider, location: "us-west-2")
9
+ request = client.addresses.create!(provider: provider, location: "us-west-2", scope: "vpc")
10
10
  address = request.resource!
11
11
  expect(address.id).not_to be_nil
12
12
  expect(address.ip_address).not_to be_nil
13
13
  expect(address.provisioned_id).not_to be_nil
14
14
  expect(address.provider).to eq(provider)
15
+ expect(address.scope).to eq("vpc")
15
16
  end
16
17
 
17
18
  context "with an address" do
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Auto scaling alarms" do
4
+ let!(:client) { create_client }
5
+ let!(:account) { create_account(client: client) }
6
+ let(:policy) { create_auto_scaling_policy }
7
+
8
+ let(:params) do
9
+ {
10
+ "name" => SecureRandom.hex(16),
11
+ "aggregation_type" => "avg",
12
+ "metric_type" => "cpu",
13
+ "operand" => "gt",
14
+ "trigger_value" => 0.5,
15
+ "number_of_periods" => 1,
16
+ "period_length" => 30,
17
+ "auto_scaling_policy_id" => policy.id
18
+ }
19
+ end
20
+
21
+ let!(:alarm) { client.auto_scaling_alarms.create!(params).resource! }
22
+
23
+ it "creates a new alarm for an auto scaling policy" do
24
+ expect(alarm).not_to be_nil
25
+ expect(policy.auto_scaling_alarms).not_to be_empty
26
+ expect(client.auto_scaling_alarms).not_to be_empty
27
+ end
28
+
29
+ it "updates an alarm" do
30
+ expect do
31
+ alarm.update("name" => "new name")
32
+ end.to change { alarm.name }.to("new name")
33
+ end
34
+
35
+ it "destroys auto scalig alarm by it's id" do
36
+ expect do
37
+ alarm.destroy!
38
+ end.to change { policy.reload.auto_scaling_alarms.count }.from(1).to(0)
39
+ end
40
+ end