ey-core 3.4.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -1
- data/ey-core.gemspec +3 -0
- data/features/accounts.feature +13 -0
- data/features/applications.feature +29 -0
- data/features/current_user.feature +14 -0
- data/features/environments.feature +30 -0
- data/features/init.feature +6 -0
- data/features/login.feature +6 -0
- data/features/scp.feature +6 -0
- data/features/step_definitions/accounts_steps.rb +23 -0
- data/features/step_definitions/applications_steps.rb +46 -0
- data/features/step_definitions/current_user_steps.rb +11 -0
- data/features/step_definitions/deprecated_command_steps.rb +3 -0
- data/features/step_definitions/environments_steps.rb +37 -0
- data/features/step_definitions/version_steps.rb +3 -0
- data/features/support/account_helpers.rb +89 -0
- data/features/support/app_helpers.rb +19 -0
- data/features/support/aruba.rb +1 -0
- data/features/support/boilerplate.rb +1 -0
- data/features/support/client_helpers.rb +36 -0
- data/features/support/config_file_helpers.rb +42 -0
- data/features/support/core.rb +19 -0
- data/features/support/deployment_helpers.rb +19 -0
- data/features/support/env.rb +40 -0
- data/features/support/environment_helpers.rb +23 -0
- data/features/support/fake_kernel.rb +23 -0
- data/features/support/io.rb +5 -0
- data/features/support/mock_api.rb +21 -0
- data/features/support/output_helpers.rb +7 -0
- data/features/support/resource_helpers.rb +189 -0
- data/features/support/server_helpers.rb +27 -0
- data/features/version.feature +8 -0
- data/features/whoami.feature +14 -0
- data/lib/ey-core/version.rb +1 -1
- metadata +215 -56
- checksums.yaml +0 -7
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require "bundler/gem_tasks"
|
3
|
+
require 'cucumber/rake/task'
|
3
4
|
|
4
5
|
namespace :spec do
|
5
6
|
task :mocked do
|
@@ -12,4 +13,6 @@ end
|
|
12
13
|
|
13
14
|
task :spec => ["spec:mocked", "spec:unmocked"]
|
14
15
|
|
15
|
-
|
16
|
+
Cucumber::Rake::Task.new
|
17
|
+
|
18
|
+
task default: ["spec:mocked", :cucumber]
|
data/ey-core.gemspec
CHANGED
@@ -45,4 +45,7 @@ Gem::Specification.new do |gem|
|
|
45
45
|
gem.add_development_dependency "rspec", "~> 3.0"
|
46
46
|
gem.add_development_dependency "ffaker"
|
47
47
|
gem.add_development_dependency "rake"
|
48
|
+
gem.add_development_dependency "aruba", "~> 0.11"
|
49
|
+
gem.add_development_dependency "cucumber", "~> 2.1"
|
50
|
+
gem.add_development_dependency "factis", "~> 1.0"
|
48
51
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Accounts
|
2
|
+
In order to know what Engine Yard accounts I can access
|
3
|
+
As a User
|
4
|
+
I want to be able to list the accounts with 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'm associated with several accounts
|
10
|
+
|
11
|
+
Scenario: Listing my accounts
|
12
|
+
When I run `ey-core accounts`
|
13
|
+
Then I see the name and ID of each of my accounts
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Feature: Applications
|
2
|
+
In order to determine what I can work with
|
3
|
+
As a User
|
4
|
+
I want to be able to list the applications that live in my accounts
|
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 each of my accounts has several applications
|
15
|
+
|
16
|
+
Scenario: Listing all of my applications
|
17
|
+
When I run `ey-core applications`
|
18
|
+
Then I see the name and ID for all of my applications
|
19
|
+
|
20
|
+
Scenario Outline: Listing applications for a specific account
|
21
|
+
When I run `ey-core applications <Account Flag> one`
|
22
|
+
Then I see the applications in the one account
|
23
|
+
But I do not see applications from other accounts
|
24
|
+
|
25
|
+
Examples:
|
26
|
+
| Account Flag |
|
27
|
+
| -a |
|
28
|
+
| --account |
|
29
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: Current User
|
2
|
+
In order to ensure that I'm logged into the right account
|
3
|
+
As a User
|
4
|
+
I want to be able to see my user information
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given I'm an Engine Yard user
|
8
|
+
And ey-core is configured with my cloud token
|
9
|
+
|
10
|
+
Scenario: Getting the current user information
|
11
|
+
When I run `ey-core current_user`
|
12
|
+
Then I should see my user ID
|
13
|
+
And I should see my email address
|
14
|
+
And I should see my name
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Feature: Environments
|
2
|
+
In order to know what Engine Yard environments I can access
|
3
|
+
As a User
|
4
|
+
I want to be able to list the environments with 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 each of my accounts has several applications
|
15
|
+
And each of my applications has an environment
|
16
|
+
|
17
|
+
Scenario: Listing all of my environments
|
18
|
+
When I run `ey-core environments`
|
19
|
+
Then I see the name and ID for all of my environments
|
20
|
+
|
21
|
+
Scenario Outline: Listing environments for a specific account
|
22
|
+
When I run `ey-core environments <Account Flag> one`
|
23
|
+
Then I see the environments in the one account
|
24
|
+
But I do not see environments from other accounts
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
| Account Flag |
|
28
|
+
| -a |
|
29
|
+
| --account |
|
30
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Given %(I'm an Engine Yard user) do
|
2
|
+
memorize_fact(:me, create_user(client: client))
|
3
|
+
true
|
4
|
+
end
|
5
|
+
|
6
|
+
Given %(ey-core is configured with my cloud token) do
|
7
|
+
add_config_option(
|
8
|
+
'https://api.engineyard.com/' => current_user_hash['token']
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
Given %(I'm associated with several accounts) do
|
13
|
+
account1 = create_account(client: client, owner: current_user)
|
14
|
+
account2 = create_account(client: client, owner: current_user)
|
15
|
+
memorize_fact(:accounts, [account1, account2])
|
16
|
+
end
|
17
|
+
|
18
|
+
Then %(I see the name and ID of each of my accounts) do
|
19
|
+
recall_fact(:accounts).each do |account|
|
20
|
+
expect(output_text).to include(account.id)
|
21
|
+
expect(output_text).to include(account.name)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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
|
+
Given %(each of my accounts has several applications) do
|
16
|
+
known_accounts.each do |account|
|
17
|
+
known_apps.push(
|
18
|
+
create_application(account: account, name: "#{account.name}_1")
|
19
|
+
)
|
20
|
+
|
21
|
+
known_apps.push(
|
22
|
+
create_application(account: account, name: "#{account.name}_2")
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Then %(I see the name and ID for all of my applications) do
|
28
|
+
known_apps.each do |app|
|
29
|
+
expect(output_text).to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Then %(I see the applications in the one account) do
|
34
|
+
account_named('one').applications.all.each do |app|
|
35
|
+
expect(output_text).to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Then %(I do not see applications from other accounts) do
|
40
|
+
two = account_named('two').applications.all.to_a
|
41
|
+
three = account_named('three').applications.all.to_a
|
42
|
+
|
43
|
+
(two + three).each do |app|
|
44
|
+
expect(output_text).not_to match(/#{Regexp.escape(app.id.to_s)}\s+\|\s+#{Regexp.escape(app.name)}/)
|
45
|
+
end
|
46
|
+
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,37 @@
|
|
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
|
+
Then %(I see the name and ID for all of my environments) do
|
18
|
+
known_environments.each do |environment|
|
19
|
+
expect(output_text).to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Then %(I see the environments in the one account) do
|
24
|
+
account_named('one').environments.all.each do |environment|
|
25
|
+
expect(output_text).to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Then %(I do not see environments from other accounts) do
|
30
|
+
two = account_named('two').environments.all.to_a
|
31
|
+
three = account_named('three').environments.all.to_a
|
32
|
+
|
33
|
+
(two + three).each do |environment|
|
34
|
+
expect(output_text).not_to match(/#{Regexp.escape(environment.id.to_s)}\s+\|\s+#{Regexp.escape(environment.name)}/)
|
35
|
+
end
|
36
|
+
|
37
|
+
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
|