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
@@ -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},
@@ -5,7 +5,7 @@ class Ey::Core::Client
5
5
  url = params["url"]
6
6
 
7
7
  request(
8
- :path => "ssl_certificates/#{id}",
8
+ :path => "ssl-certificates/#{id}",
9
9
  :url => url,
10
10
  )
11
11
  end
@@ -0,0 +1,24 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def retrieve_docker_registry_credentials(account_id, location_id)
4
+ request(
5
+ :path => "/accounts/#{account_id}/docker-registry/#{location_id}/credentials"
6
+ )
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def retrieve_docker_registry_credentials(account_id, location_id)
12
+ response(
13
+ :body => {
14
+ 'docker_registry_credentials' => {
15
+ 'username' => 'foo',
16
+ 'password' => 'bar',
17
+ 'registry_endpoint' => "https://012345678901.dkr.ecr.#{location_id}.amazonaws.com",
18
+ 'expires_at' => (Time.now + 8 * 3600).to_i
19
+ }
20
+ }
21
+ )
22
+ end
23
+ end
24
+ end
@@ -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,45 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def update_auto_scaling_group(params = {})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/auto_scaling_groups/#{id}",
9
+ :body => { "auto_scaling_group" => params.fetch("auto_scaling_group") },
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def update_auto_scaling_group(params = {})
16
+ url = params.delete("url")
17
+
18
+ resource_id = params.delete("id")
19
+ resource = find(:auto_scaling_groups, resource_id).merge(params["auto_scaling_group"])
20
+
21
+ now = Time.now
22
+
23
+ request = {
24
+ "id" => self.uuid,
25
+ "type" => "update_auto_scaling_group",
26
+ "successful" => true,
27
+ "created_at" => now - 5,
28
+ "updated_at" => now,
29
+ "started_at" => now - 3,
30
+ "finished_at" => now,
31
+ "message" => nil,
32
+ "read_channel" => nil,
33
+ "resource" => [:auto_scaling_groups, resource_id, resource],
34
+ "resource_url" => url_for("/auto_scaling_groups/#{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.0"
3
+ VERSION = "3.6.1"
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
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'as a user' do
4
+ let!(:client) { create_client }
5
+
6
+ context "with an environment" do
7
+ let!(:account) { create_account(client: client) }
8
+ let!(:provider) { create_provider(account: account) }
9
+ let!(:app) { create_application(account: account, client: client) }
10
+ let!(:environment) { create_environment(client: client, account: account, application: app, configuration: { type: "production"}) }
11
+
12
+ it "adds an auto scaling group" do
13
+ expect {
14
+ client.auto_scaling_groups.create!(minimum_size: 2, maximum_size: 6, environment: environment).resource!
15
+ }.to change { environment.reload.auto_scaling_group }.from(nil).and change { client.auto_scaling_groups.count }.by(1)
16
+ end
17
+
18
+ context "with an auto scaling group" do
19
+ let!(:group) { client.auto_scaling_groups.create!(minimum_size: 2, maximum_size: 6, environment: environment).resource! }
20
+
21
+ it "destroys the auto scaling group" do
22
+ expect {
23
+ group.destroy.ready!
24
+ }.to change { group.reload.deleted_at }.from(nil).and change { client.environments.get(environment.id).auto_scaling_group }.to(nil)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,94 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Auto scaling policies" do
4
+ let!(:client) { create_client }
5
+ let!(:account) { create_account(client: client) }
6
+ let!(:environment) { create_environment(account: account) }
7
+ let(:auto_scaling_group) { create_auto_scaling_group(environment: environment.id) }
8
+ let(:simple_policy_params) do
9
+ {
10
+ name: SecureRandom.hex(16),
11
+ action_value: 2,
12
+ action_type: "add",
13
+ action_unit: "instances",
14
+ auto_scaling_group_id: auto_scaling_group.id,
15
+ type: "simple"
16
+ }
17
+ end
18
+
19
+ describe "common requests for all policy types" do
20
+ let!(:policy) { client.auto_scaling_policies.create!(simple_policy_params).resource! }
21
+
22
+ it "is able to retrieve auto scaling policy by it's id" do
23
+ found_policy = client.auto_scaling_policies.get(policy.id)
24
+ expect(found_policy).not_to be_nil
25
+ expect(found_policy.id).to eq(policy.id)
26
+ end
27
+
28
+ it "updates auto scaling policy" do
29
+ expect do
30
+ policy.update(name: "new name")
31
+ end.to change { policy.name }.to("new name")
32
+ end
33
+
34
+ it "destroys a policy by it's id" do
35
+ expect do
36
+ policy.destroy!
37
+ end.to change { auto_scaling_group.reload.simple_auto_scaling_policies.count }.from(1).to(0)
38
+ end
39
+ end
40
+
41
+ context "simple autoscaling policy" do
42
+ it "adds one to autoscaling group" do
43
+ expect {
44
+ client.auto_scaling_policies.create!(simple_policy_params)
45
+ }.to change { auto_scaling_group.reload.simple_auto_scaling_policies.count }.from(0).to(1)
46
+ .and not_change { auto_scaling_group.reload.step_auto_scaling_policies.count }
47
+ .and not_change { auto_scaling_group.reload.target_auto_scaling_policies.count }
48
+ end
49
+ end
50
+
51
+ context "target tracking auto scaling policy" do
52
+ let(:params) do
53
+ {
54
+ auto_scaling_group_id: auto_scaling_group.id,
55
+ name: SecureRandom.hex(16),
56
+ target_value: 0.7,
57
+ estimated_warmup: 200,
58
+ metric_type: "avg_cup",
59
+ disable_scale_in: false,
60
+ type: "target"
61
+ }
62
+ end
63
+
64
+ it "adds one to autoscaling group" do
65
+ expect {
66
+ client.auto_scaling_policies.create!(params)
67
+ }.to change { auto_scaling_group.reload.target_auto_scaling_policies.count }.from(0).to(1)
68
+ .and not_change { auto_scaling_group.reload.simple_auto_scaling_policies.count }
69
+ .and not_change { auto_scaling_group.reload.step_auto_scaling_policies.count }
70
+ end
71
+ end
72
+
73
+ context "step auto scaling policy" do
74
+ let(:params) do
75
+ {
76
+ auto_scaling_group_id: auto_scaling_group.id,
77
+ name: SecureRandom.hex(16),
78
+ estimated_warmup: 200,
79
+ action_unit: "instances",
80
+ action_type: "add",
81
+ steps: [{ metric_from: 50, metric_to: nil, action_value: 1 }],
82
+ type: "step"
83
+ }
84
+ end
85
+
86
+ it "adds one to autoscaling group" do
87
+ expect {
88
+ client.auto_scaling_policies.create!(params)
89
+ }.to change { auto_scaling_group.reload.step_auto_scaling_policies.count }.from(0).to(1)
90
+ .and not_change { auto_scaling_group.reload.simple_auto_scaling_policies.count }
91
+ .and not_change { auto_scaling_group.reload.target_auto_scaling_policies.count }
92
+ end
93
+ end
94
+ end