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
@@ -0,0 +1,39 @@
1
+ Given %(each of my accounts has several applications) do
2
+ known_accounts.each do |account|
3
+ known_apps.push(
4
+ create_application(account: account, name: "#{account.name}_1")
5
+ )
6
+
7
+ known_apps.push(
8
+ create_application(account: account, name: "#{account.name}_2")
9
+ )
10
+ end
11
+ end
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
+
20
+ Then %(I see the name and ID for all of my applications) do
21
+ known_apps.each do |app|
22
+ expect(output_text).to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
23
+ end
24
+ end
25
+
26
+ Then %(I see the applications in the one account) do
27
+ account_named('one').applications.all.each do |app|
28
+ expect(output_text).to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
29
+ end
30
+ end
31
+
32
+ Then %(I do not see applications from other accounts) do
33
+ two = account_named('two').applications.all.to_a
34
+ three = account_named('three').applications.all.to_a
35
+
36
+ (two + three).each do |app|
37
+ expect(output_text).not_to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ Then %(I should see my user ID) do
2
+ expect(output_text).to match(/#{Regexp.escape(current_user.id)}/)
3
+ end
4
+
5
+ Then %(I should see my email address) do
6
+ expect(output_text).to match(/#{Regexp.escape(current_user.email)}/)
7
+ end
8
+
9
+ Then %(I should see my name) do
10
+ expect(output_text).to match(/#{Regexp.escape(current_user.name)}/)
11
+ end
@@ -0,0 +1,3 @@
1
+ Then %(I am advised that this command has been deprecated) do
2
+ expect(output_text).to match(/.*This command is deprecated.*/)
3
+ end
@@ -0,0 +1,3 @@
1
+ Then %(I see the docker login command) do
2
+ expect(output_text).to match("docker login -u foo -p bar https://012345678901.dkr.ecr.us-east-1.amazonaws.com")
3
+ end
@@ -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
@@ -0,0 +1,52 @@
1
+ Given %(each of my applications has an environment) do
2
+ known_accounts.each do |account|
3
+ account.applications.each do |app|
4
+ known_environments.push(
5
+ create_environment(
6
+ account: account,
7
+ application: app,
8
+ environment: {
9
+ name: "#{app.name}_env"
10
+ }
11
+ )
12
+ )
13
+ end
14
+ end
15
+ end
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
+
32
+ Then %(I see the name and ID for all of my environments) do
33
+ known_environments.each do |environment|
34
+ expect(output_text).to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
35
+ end
36
+ end
37
+
38
+ Then %(I see the environments in the one account) do
39
+ account_named('one').environments.all.each do |environment|
40
+ expect(output_text).to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
41
+ end
42
+ end
43
+
44
+ Then %(I do not see environments from other accounts) do
45
+ two = account_named('two').environments.all.to_a
46
+ three = account_named('three').environments.all.to_a
47
+
48
+ (two + three).each do |environment|
49
+ expect(output_text).not_to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
50
+ end
51
+
52
+ end
@@ -0,0 +1,3 @@
1
+ Then %(I see the current ey-core version) do
2
+ expect(output_text).to include(Ey::Core::VERSION)
3
+ end
@@ -0,0 +1,89 @@
1
+ module AccountHelpers
2
+ def account_named(name)
3
+ client.accounts.first(name: name)
4
+ end
5
+
6
+ def known_accounts
7
+ begin
8
+ recall_fact(:known_accounts)
9
+ rescue
10
+ memorize_fact(:known_accounts, [])
11
+ end
12
+ end
13
+
14
+ def first_account
15
+ known_accounts.first.reload
16
+ end
17
+
18
+ def last_account
19
+ known_accounts.last.reload
20
+ end
21
+
22
+ def create_account(options={})
23
+ creator = options[:creator] || create_client
24
+ client = options[:client]
25
+
26
+ attributes = options[:account] || {}
27
+ attributes[:type] ||= "beta" # get around awsm billing requirements for tests
28
+ attributes[:name] ||= SecureRandom.hex(6)
29
+
30
+ if client
31
+ attributes[:owner] ||= begin
32
+ client.users.current
33
+ rescue Ey::Core::Response::NotFound
34
+ end
35
+ end
36
+ attributes[:owner] ||= create_user(client: client)
37
+
38
+ created_account = (client || creator).accounts.create!(attributes)
39
+
40
+ if client
41
+ client.accounts.get!(created_account.identity)
42
+ else
43
+ created_account
44
+ end
45
+ end
46
+
47
+ def create_user(options={})
48
+ creator = options[:creator] || create_client
49
+ client = options[:client]
50
+
51
+ attributes = options[:user] || {}
52
+ attributes[:name] ||= Faker::Name.name
53
+ attributes[:email] ||= Faker::Internet.email
54
+
55
+ created_user = creator.users.create!(attributes)
56
+
57
+ if client
58
+ client.users.get!(created_user.identity)
59
+ else
60
+ created_user
61
+ end
62
+ end
63
+
64
+ def create_provider(options={})
65
+ account = options[:account] || create_account(options)
66
+
67
+ attributes = options[:provider] || {}
68
+ attributes[:type] ||= :aws
69
+ attributes[:provisioned_id] ||= SecureRandom.hex(8)
70
+ attributes[:credentials] ||= case attributes[:type]
71
+ when :aws then
72
+ {
73
+ :instance_aws_secret_id => SecureRandom.hex(6),
74
+ :instance_aws_secret_key => SecureRandom.hex(6),
75
+ :aws_secret_id => SecureRandom.hex(6),
76
+ :aws_secret_key => SecureRandom.hex(6),
77
+ :aws_login => Faker::Internet.email,
78
+ :aws_pass => SecureRandom.hex(6),
79
+ }
80
+ when :azure then
81
+ {
82
+ }
83
+ end
84
+
85
+ account.providers.create!(attributes).resource!
86
+ end
87
+ end
88
+
89
+ World(AccountHelpers)
@@ -0,0 +1,19 @@
1
+ module AppHelpers
2
+ def known_apps
3
+ begin
4
+ recall_fact(:known_apps)
5
+ rescue
6
+ memorize_fact(:known_apps, [])
7
+ end
8
+ end
9
+
10
+ def first_app
11
+ known_apps.first.reload
12
+ end
13
+
14
+ def last_app
15
+ known_apps.last.reload
16
+ end
17
+ end
18
+
19
+ World(AppHelpers)
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1 @@
1
+ require 'faker'
@@ -0,0 +1,36 @@
1
+ module ClientHelpers
2
+ def create_client(attributes={})
3
+ token = if (user = attributes.delete(:user)) && Ey::Core::Client.mocking?
4
+ core = Ey::Core::Client::Mock.data.values.find { |c| c[:users][user.identity] }
5
+ core[:users][user.identity]["token"]
6
+ end
7
+ token ||= begin
8
+ token_dotfile = YAML.load_file(File.expand_path("/../../../.token"), __FILE__) rescue {}
9
+ ENV["CORE_TOKEN"] || token_dotfile[ENV["CORE_URL"]] || "a4bf6558da8c1051536d1596b8931ebd346aff0b"
10
+ end
11
+
12
+ merged_attributes = attributes.merge(token: token, cache: true)
13
+ merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']
14
+
15
+ Ey::Core::Client.new(merged_attributes)
16
+ end
17
+
18
+ def create_server_client(server, attributes={})
19
+ unless core = Ey::Core::Client::Mock.data.values.find { |data| data[:servers][server.identity] }
20
+ raise "Failed to find server in mock data: #{server}"
21
+ end
22
+
23
+ token = core[:servers][server.identity]["token"]
24
+
25
+ merged_attributes = attributes.merge(token: token, cache: true)
26
+ merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']
27
+
28
+ Ey::Core::Client.new(merged_attributes)
29
+ end
30
+
31
+ def create_unauthenticated_client
32
+ Ey::Core::Client.new(token: nil)
33
+ end
34
+ end
35
+
36
+ World(ClientHelpers)
@@ -0,0 +1,42 @@
1
+ require 'yaml'
2
+
3
+ module ConfigFileHelpers
4
+ def config_file_location
5
+ File.expand_path(File.join(aruba.current_directory, '.ey-core'))
6
+ end
7
+
8
+ def write_config_file(hash = {})
9
+ c = File.open(config_file_location, 'w')
10
+ c.write(hash.to_yaml)
11
+ c.close
12
+ end
13
+
14
+ def read_config_file
15
+ begin
16
+ YAML.load_file(File.read(config_file_location))
17
+ rescue
18
+ {}
19
+ end
20
+ end
21
+
22
+ def nuke_config_file
23
+ FileUtils.rm_f(config_file_location) if File.exist?(config_file_location)
24
+ end
25
+
26
+ def add_config_option(hash = {})
27
+ current = read_config_file
28
+ write_config_file(current.merge(hash))
29
+ end
30
+
31
+ def remove_config_option(key)
32
+ current = read_config_file
33
+ current.delete(key)
34
+ write_config_file(current)
35
+ end
36
+ end
37
+
38
+ World(ConfigFileHelpers)
39
+
40
+ After do
41
+ nuke_config_file
42
+ end
@@ -0,0 +1,19 @@
1
+ module CoreHelpers
2
+ def client
3
+ begin
4
+ recall_fact(:client)
5
+ rescue
6
+ memorize_fact(:client, create_client)
7
+ end
8
+ end
9
+
10
+ def current_user
11
+ client.users.current
12
+ end
13
+
14
+ def current_user_hash
15
+ client.current_user
16
+ end
17
+ end
18
+
19
+ World(CoreHelpers)
@@ -0,0 +1,19 @@
1
+ module DeploymentHelpers
2
+ def known_deployments
3
+ begin
4
+ recall_fact(:known_deployments)
5
+ rescue
6
+ memorize_fact(:known_deployments, [])
7
+ end
8
+ end
9
+
10
+ def first_deployment
11
+ known_deployments.first.reload
12
+ end
13
+
14
+ def last_deployment
15
+ known_deployments.last.reload
16
+ end
17
+ end
18
+
19
+ World(DeploymentHelpers)
@@ -0,0 +1,40 @@
1
+ #require 'simplecov'
2
+ #SimpleCov.coverage_dir 'coverage/features'
3
+ #SimpleCov.minimum_coverage 95
4
+ #SimpleCov.start do
5
+ #add_filter '/spec/'
6
+ #add_filter '/features/'
7
+ #add_filter '/mock/'
8
+ #add_group 'Libraries', 'lib'
9
+ #add_group 'CLI', 'lib/ey-core/cli/'
10
+ #add_group 'CLI Helpers', 'lib/ey-core/cli/helpers'
11
+ #end
12
+
13
+ require 'aruba/cucumber'
14
+ require 'factis/cucumber'
15
+ require 'ey-core'
16
+ require 'ey-core/version'
17
+ require 'ey-core/cli/main'
18
+
19
+ EXE_DIR = File.expand_path(File.join(File.dirname(__FILE__), '/../../exe'))
20
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
21
+
22
+ Aruba.configure do |config|
23
+ config.command_search_paths = config.command_search_paths << EXE_DIR
24
+ config.home_directory = File.join(config.root_directory, config.working_directory)
25
+ config.command_launcher = :in_process
26
+ config.main_class = Ey::Core::Cli::Main
27
+ end
28
+
29
+ Before do
30
+ # Using "announce" causes massive warnings on 1.9.2
31
+ @puts = true
32
+ @original_rubylib = ENV['RUBYLIB']
33
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
34
+ #ENV['CORE_URL'] ||= "http://api-development.localdev.engineyard.com:9292"
35
+ end
36
+
37
+ After do
38
+ ENV['RUBYLIB'] = @original_rubylib
39
+ #ENV.delete('CORE_URL')
40
+ end