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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60c37b8856b7cd6b06d2996a64d376bbb170f75f
4
- data.tar.gz: 17060911ccff177a709c111a1916fc8d42b3dadb
3
+ metadata.gz: '01976d3d26f0fd5a47e947832532b2db2053d854'
4
+ data.tar.gz: 3ee031e086e2385ca94d78e8f06578bd3adbce35
5
5
  SHA512:
6
- metadata.gz: 3911ac7f2dab3d27fa225e563e9abb46f6ab2b4a95ee82153a70668480f56a751a2623c731a24cfbc17efc0615c6f7d56e210af24b01ceeb458833aee45a8ba3
7
- data.tar.gz: fb4d4e6c23f50159d54c784e07fd62c63998b33d9930a67c57e1e364fc7a0fd917f9e4d11c58b31a3ae0108278dfe09504162f35b17ad8a6d47e17209f07138d
6
+ metadata.gz: 0fc5f5e9e0c221aa2d852bacc71d99391d365fb6e2f98896ea4678306f9c64bf2e3c84d0b3257e6f86658f17391ee0d3bcac8a54c4468d555d2cb48e0509e20f
7
+ data.tar.gz: a8e3e8cc838919fe69e503e49ff13866f7a7a899783c2ab73d50cebeb0e2f4f0713d37bd35081ba7feddc9578adfc2be764ec35d6c60cf0750343cdf38c71b2d
@@ -2,12 +2,20 @@
2
2
 
3
3
  ## [Unreleased](https://github.com/engineyard/core-client-rb/tree/HEAD)
4
4
 
5
- [Full Changelog](https://github.com/engineyard/core-client-rb/compare/v2.8.4...HEAD)
5
+ [Full Changelog](https://github.com/engineyard/core-client-rb/compare/v3.5.0...HEAD)
6
6
 
7
7
  **Merged pull requests:**
8
8
 
9
- - \[ENG-193\] Create untracked addresses via smithy [\#34](https://github.com/engineyard/core-client-rb/pull/34) ([omgitsads](https://github.com/omgitsads))
10
- - remove usage of hmac client in specs [\#33](https://github.com/engineyard/core-client-rb/pull/33) ([lanej](https://github.com/lanej))
9
+ ## [v3.5.0](https://github.com/engineyard/core-client-rb/tree/v3.5.0) (2018-04-04)
10
+ [Full Changelog](https://github.com/engineyard/core-client-rb/compare/v3.4.4...v3.5.0)
11
+
12
+ **Merged pull requests:**
13
+
14
+ - Add support for autoscaling policies [\#110](https://github.com/engineyard/core-client-rb/pull/101) ([thorn](https://github.com/thorn))
15
+ - Add support for environment variables [\#90](https://github.com/engineyard/core-client-rb/pull/90) ([rzaharenkov](https://github.com/rzaharenkov))
16
+ - Add ability to send configuration options together with blueprint [\#104](https://github.com/engineyard/core-client-rb/pull/104) ([ramonpm](https://github.com/ramonpm))
17
+ - Add support for address.scope parameter for EIP [\#102](https://github.com/engineyard/core-client-rb/pull/102) ([thorn](https://github.com/thorn))
18
+ - Various fixes for `servers` command [\#103](https://github.com/engineyard/core-client-rb/pull/103) ([binarypaladin](https://github.com/binarypaladin))
11
19
 
12
20
  ## [v2.8.4](https://github.com/engineyard/core-client-rb/tree/v2.8.4) (2015-08-12)
13
21
  [Full Changelog](https://github.com/engineyard/core-client-rb/compare/v2.8.3...v2.8.4)
@@ -1,4 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
+
3
+ git_path = File.expand_path("../../.git", __FILE__)
4
+
5
+ if File.exist? git_path
6
+ lib_dir = File.expand_path("../../lib", __FILE__)
7
+ $LOAD_PATH.unshift( lib_dir )
8
+ end
9
+
2
10
  require File.expand_path('../../lib/ey-core/cli/main', __FILE__)
3
11
 
4
12
  Ey::Core::Cli::Main.new(ARGV).execute!
@@ -0,0 +1,54 @@
1
+ Feature: Environment Variables
2
+ In order to know current values of environment variables assigned to my Engine Yard environments
3
+ As a User
4
+ I want to be able to list the environment variables for environments which I'm associated
5
+
6
+ Background:
7
+ Given I'm an Engine Yard user
8
+ And ey-core is configured with my cloud token
9
+ And I have the following accounts:
10
+ | Account Name |
11
+ | one |
12
+ | two |
13
+ | three |
14
+ And I have the following applications:
15
+ | Account Name | Application Name |
16
+ | one | blog_app |
17
+ | two | todo_app |
18
+ And I have the following environments:
19
+ | Application Name | Environment Name |
20
+ | blog_app | staging |
21
+ | blog_app | production |
22
+ | todo_app | staging |
23
+ And I have the following environment variables:
24
+ | Name | Value | Application Name | Environment Name | Sensitive |
25
+ | SECRET_BASE | abc= | blog_app | staging | false |
26
+ | DB_PASSWORD | 123qweasd!! | blog_app | staging | true |
27
+ | SECRET_BASE | qwe= | blog_app | production | false |
28
+ | DB_PASSWORD | 987qweasd!! | blog_app | production | true |
29
+ | DB_PASSWORD | my_secure_password | todo_app | staging | true |
30
+
31
+ Scenario: Listing all of my environment variables
32
+ When I run `ey-core environment_variables`
33
+ Then I see the name and value for all of my environments as well as name of associated environment and application
34
+
35
+ Scenario Outline: Listing environment variables for a specific environment
36
+ When I run `ey-core environment_variables <Environment Flag> staging`
37
+ Then I see the environment variables associated with `staging` environment
38
+ But I do not see environment variables associated with any other environments different from `staging`
39
+
40
+ Examples:
41
+ | Environment Flag |
42
+ | -e |
43
+ | --environment |
44
+
45
+ Scenario Outline: Listing environment variables for a specific application
46
+ When I run `ey-core environment_variables <Application Flag> blog_app`
47
+ Then I see the environment variables associated with `blog_app` application
48
+ But I do not see environment variables associated with any other applications different from `blog_app`
49
+
50
+ Examples:
51
+ | Application Flag |
52
+ | -a |
53
+ | --application |
54
+
@@ -15,6 +15,20 @@ Given %(I'm associated with several accounts) do
15
15
  memorize_fact(:accounts, [account1, account2])
16
16
  end
17
17
 
18
+ Given %r(^I have the following accounts:$) do |account_names|
19
+ account_names.hashes.each do |account_hash|
20
+ known_accounts.push(
21
+ create_account(
22
+ client: client,
23
+ owner: current_user,
24
+ account: {
25
+ name: account_hash['Account Name']
26
+ }
27
+ )
28
+ )
29
+ end
30
+ end
31
+
18
32
  Then %(I see the name and ID of each of my accounts) do
19
33
  recall_fact(:accounts).each do |account|
20
34
  expect(output_text).to include(account.id)
@@ -1,17 +1,3 @@
1
- Given %r(^I have the following accounts:$) do |account_names|
2
- account_names.hashes.each do |account_hash|
3
- known_accounts.push(
4
- create_account(
5
- client: client,
6
- owner: current_user,
7
- account: {
8
- name: account_hash['Account Name']
9
- }
10
- )
11
- )
12
- end
13
- end
14
-
15
1
  Given %(each of my accounts has several applications) do
16
2
  known_accounts.each do |account|
17
3
  known_apps.push(
@@ -24,6 +10,13 @@ Given %(each of my accounts has several applications) do
24
10
  end
25
11
  end
26
12
 
13
+ Given(/^I have the following applications:$/) do |applications|
14
+ applications.hashes.each do |application_hash|
15
+ account = known_accounts.find { |acc| acc.name == application_hash['Account Name'] }
16
+ known_apps.push(create_application(account: account, name: application_hash['Application Name']))
17
+ end
18
+ end
19
+
27
20
  Then %(I see the name and ID for all of my applications) do
28
21
  known_apps.each do |app|
29
22
  expect(output_text).to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
@@ -0,0 +1,51 @@
1
+ Given(/^I have the following environment variables:$/) do |variables|
2
+ variables.hashes.each do |variable_hash|
3
+ application = known_apps.find { |app| app.name == variable_hash['Application Name'] }
4
+ environment = known_environments.find { |env| env.name == variable_hash['Environment Name'] }
5
+ known_environment_variables.push(
6
+ create_environment_variable(
7
+ application: application,
8
+ environment: environment,
9
+ environment_variable: {
10
+ name: variable_hash['Name'],
11
+ value: variable_hash['Value'],
12
+ sensitive: variable_hash['Sensitive']
13
+ }
14
+ )
15
+ )
16
+ end
17
+ end
18
+
19
+ Then(/^I see the name and value for all of my environments as well as name of associated environment and application$/) do
20
+ known_environment_variables.each do |environment_variable|
21
+ expect(output_text).to match(match_environment_variable_regexp(environment_variable))
22
+ end
23
+ end
24
+
25
+ Then(/^I see the environment variables associated with `(\w+)` environment$/) do |environment_name|
26
+ known_environment_variables.each do |environment_variable|
27
+ next unless environment_variable.environment_name == environment_name
28
+ expect(output_text).to match(match_environment_variable_regexp(environment_variable))
29
+ end
30
+ end
31
+
32
+ Then(/^I do not see environment variables associated with any other environments different from `(\w+)`$/) do |environment_name|
33
+ known_environment_variables.each do |environment_variable|
34
+ next if environment_variable.environment_name == environment_name
35
+ expect(output_text).not_to match(match_environment_variable_regexp(environment_variable))
36
+ end
37
+ end
38
+
39
+ Then(/^I see the environment variables associated with `(\w+)` application$/) do |application_name|
40
+ known_environment_variables.each do |environment_variable|
41
+ next unless environment_variable.application_name == application_name
42
+ expect(output_text).to match(match_environment_variable_regexp(environment_variable))
43
+ end
44
+ end
45
+
46
+ Then(/^I do not see environment variables associated with any other applications different from `(\w+)`$/) do |application_name|
47
+ known_environment_variables.each do |environment_variable|
48
+ next if environment_variable.application_name == application_name
49
+ expect(output_text).not_to match(match_environment_variable_regexp(environment_variable))
50
+ end
51
+ end
@@ -14,6 +14,21 @@ Given %(each of my applications has an environment) do
14
14
  end
15
15
  end
16
16
 
17
+ Given(/^I have the following environments:$/) do |environments|
18
+ environments.hashes.each do |environment_hash|
19
+ application = known_apps.find { |app| app.name == environment_hash['Application Name'] }
20
+ known_environments.push(
21
+ create_environment(
22
+ account: application.account,
23
+ application: application,
24
+ environment: {
25
+ name: environment_hash['Environment Name']
26
+ }
27
+ )
28
+ )
29
+ end
30
+ end
31
+
17
32
  Then %(I see the name and ID for all of my environments) do
18
33
  known_environments.each do |environment|
19
34
  expect(output_text).to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
@@ -0,0 +1,20 @@
1
+ module EnvironmentVariableHelpers
2
+ ENVIRONMENT_VARIABLE_DISPLAY_FIELDS = %i[id name value environment_name application_name]
3
+
4
+ def known_environment_variables
5
+ begin
6
+ recall_fact(:environment_variables)
7
+ rescue
8
+ memorize_fact(:environment_variables, [])
9
+ end
10
+ end
11
+
12
+ def match_environment_variable_regexp(environment_variable)
13
+ regexp_parts = ENVIRONMENT_VARIABLE_DISPLAY_FIELDS.map do |field|
14
+ Regexp.escape(environment_variable.send(field).to_s)
15
+ end
16
+ Regexp.new(regexp_parts.join("(\s+)\\|(\s+)"))
17
+ end
18
+ end
19
+
20
+ World(EnvironmentVariableHelpers)
@@ -127,6 +127,18 @@ module ResourceHelpers
127
127
  environment
128
128
  end
129
129
 
130
+ def create_environment_variable(options={})
131
+ application = options[:application] || create_application
132
+ environment = options[:environment] || create_environment
133
+
134
+ environment_variable = options[:environment_variable] || {}
135
+ environment_variable.merge!(application_id: application.id, environment: environment.id)
136
+ environment_variable[:name] ||= SecureRandom.hex(8)
137
+ environment_variable[:value] ||= SecureRandom.hex(32)
138
+
139
+ client.environment_variables.create!(environment_variable)
140
+ end
141
+
130
142
  def create_provider_location(client, attributes={})
131
143
  attributes = Cistern::Hash.stringify_keys(attributes)
132
144
 
@@ -0,0 +1,71 @@
1
+ require 'ey-core/cli/subcommand'
2
+ require 'ey-core/cli/helpers/stream_printer'
3
+
4
+ module Ey
5
+ module Core
6
+ module Cli
7
+ class EnvironmentVariables < Subcommand
8
+ MASK = '****'.freeze
9
+ SYMBOLS_TO_DISPLAY = 4
10
+ MAX_LENGTH_TO_DISPLAY = 30
11
+
12
+ include Ey::Core::Cli::Helpers::StreamPrinter
13
+
14
+ title "environment_variables"
15
+ summary "Retrieve a list of Engine Yard environment variables for environments that you have access to."
16
+
17
+ option :environment,
18
+ short: 'e',
19
+ long: 'environment',
20
+ description: 'Filter by environmeent name or id',
21
+ argument: 'Environment'
22
+
23
+ option :application,
24
+ short: 'a',
25
+ long: 'application',
26
+ description: 'Filter by application name or id',
27
+ argument: 'Application'
28
+
29
+ switch :display_sensitive,
30
+ short: 's',
31
+ long: 'display_sensitive',
32
+ description: 'Determines whether values of sensitive variables should be printed',
33
+ argument: 'Display Sensitive'
34
+
35
+ def handle
36
+ environment_variables = if option(:application)
37
+ core_applications(option(:application)).flat_map(&:environment_variables)
38
+ elsif option(:environment)
39
+ core_environments(option(:environment)).flat_map(&:environment_variables)
40
+ else
41
+ core_environment_variables
42
+ end
43
+
44
+ stream_print("ID" => 10, "Name" => 30, "Value" => 50, "Environment" => 30, "Application" => 30) do |printer|
45
+ environment_variables.each_entry do |ev|
46
+ printer.print(ev.id, ev.name, print_variable_value(ev), ev.environment_name, ev.application_name)
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def print_variable_value(environment_variable)
54
+ if environment_variable.sensitive && !switch_active?(:display_sensitive)
55
+ hide_sensitive_data(environment_variable.value)
56
+ else
57
+ environment_variable.value
58
+ end
59
+ end
60
+
61
+ def hide_sensitive_data(value)
62
+ if value.length > SYMBOLS_TO_DISPLAY
63
+ MASK + value[-SYMBOLS_TO_DISPLAY, SYMBOLS_TO_DISPLAY]
64
+ else
65
+ MASK
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -173,6 +173,35 @@ module Ey
173
173
  end
174
174
  end
175
175
 
176
+ # Fetches a list of environments by given name or ID.
177
+ #
178
+ # @param environment_name_or_id [String] name or ID of environment.
179
+ #
180
+ # @return [Array<Ey::Core::Client::Environment>] list of environments.
181
+ def core_environments(environment_name_or_id)
182
+ core_client.environments.all(name: environment_name_or_id).tap do |result|
183
+ result << core_client.environments.get(environment_name_or_id) if result.empty?
184
+ end.to_a.compact
185
+ end
186
+
187
+ # Fetches a list of applications by given name or ID.
188
+ #
189
+ # @param application_name_or_id [String] name or ID of application.
190
+ #
191
+ # @return [Array<Ey::Core::Client::Environment>] list of environments.
192
+ def core_applications(application_name_or_id)
193
+ core_client.applications.all(name: application_name_or_id).tap do |result|
194
+ result << core_client.applications.get(application_name_or_id) if result.empty?
195
+ end.to_a.compact
196
+ end
197
+
198
+ # Fetches a list of environment variables available for current user.
199
+ #
200
+ # @return [Array<Ey::Core::Client::EnvironmentVariable>] list of environment variables.
201
+ def core_environment_variables
202
+ core_client.environment_variables
203
+ end
204
+
176
205
  def write_core_yaml(token=nil)
177
206
  core_yaml[core_url] = token if token
178
207
  File.open(self.class.core_file, "w") {|file|
@@ -14,6 +14,7 @@ require 'ey-core/cli/console'
14
14
  require 'ey-core/cli/current_user'
15
15
  require 'ey-core/cli/deploy'
16
16
  require 'ey-core/cli/environments'
17
+ require 'ey-core/cli/environment_variables'
17
18
  require 'ey-core/cli/help'
18
19
  require 'ey-core/cli/init'
19
20
  require 'ey-core/cli/login'
@@ -45,6 +46,7 @@ module Ey
45
46
  mount CurrentUser
46
47
  mount Deploy
47
48
  mount Environments
49
+ mount EnvironmentVariables
48
50
  mount Help
49
51
  mount Init
50
52
  mount Login
@@ -4,36 +4,53 @@ module Ey
4
4
  module Core
5
5
  module Cli
6
6
  class Servers < Subcommand
7
- title "servers"
8
- summary "List servers you have access to"
7
+ title 'servers'
8
+ summary 'List servers you have access to'
9
9
 
10
10
  option :account,
11
11
  short: 'c',
12
12
  long: 'account',
13
13
  description: 'Filter by account name or id',
14
- argument: 'Account'
14
+ argument: 'account'
15
15
 
16
16
  option :environment,
17
- short: "-e",
18
- long: "environment",
19
- description: "Filter by environment.",
20
- argument: "environment"
17
+ short: 'e',
18
+ long: 'environment',
19
+ description: 'Filter by environment.',
20
+ argument: 'environment'
21
+
22
+ option :role,
23
+ short: 'r',
24
+ long: 'role',
25
+ description: 'Filter by server role.',
26
+ argument: 'role'
21
27
 
22
28
  def handle
23
- puts TablePrint::Printer.
24
- new(servers, [{id: {width: 10}}, :role, :provisioned_id]).
25
- table_print
29
+ puts TablePrint::Printer.new(
30
+ servers,
31
+ [
32
+ { id: { width: 10 } },
33
+ :role,
34
+ :provisioned_id,
35
+ { public_hostname: { width: 50 } }
36
+ ]
37
+ ).table_print
26
38
  end
27
39
 
28
40
  private
29
41
  def servers
30
- if option(:account)
31
- core_client.servers.all(account: core_account)
32
- elsif environment = option(:environment)
33
- (core_client.environments.get(environment) || core_client.environments.first(name: environment)).servers.all
34
- else
35
- core_client.servers.all
36
- end
42
+ filter_opts = {}
43
+
44
+ operator =
45
+ if option(:environment)
46
+ core_account.environments.first(name: option(:environment))
47
+ else
48
+ filter_opts[:account] = core_account.id if option(:account)
49
+ core_client
50
+ end
51
+
52
+ filter_opts[:role] = option(:role).split(',') if option(:role)
53
+ operator ? operator.servers.all(filter_opts) : nil
37
54
  end
38
55
  end
39
56
  end