ey-core 3.1.10 → 3.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ require 'ey-core/test_helpers/account_helpers'
2
+ require 'ey-core/test_helpers/alert_helpers'
3
+ require 'ey-core/test_helpers/client_helpers'
4
+ require 'ey-core/test_helpers/resource_helpers'
5
+
6
+ module Ey
7
+ module Core
8
+ module TestHelpers
9
+ include AccountHelpers
10
+ include AlertHelpers
11
+ include ClientHelpers
12
+ include ResourceHelpers
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,73 @@
1
+ module Ey
2
+ module Core
3
+ module TestHelpers
4
+ module AccountHelpers
5
+ def create_account(options={})
6
+ creator = options[:creator] || create_client
7
+ client = options[:client]
8
+
9
+ attributes = options[:account] || {}
10
+ attributes[:type] ||= "beta" # get around awsm billing requirements for tests
11
+ attributes[:name] ||= SecureRandom.hex(6)
12
+
13
+ if client
14
+ attributes[:owner] ||= begin
15
+ client.users.current
16
+ rescue Ey::Core::Response::NotFound
17
+ end
18
+ end
19
+ attributes[:owner] ||= create_user(client: client)
20
+
21
+ created_account = (client || creator).accounts.create!(attributes)
22
+
23
+ if client
24
+ client.accounts.get!(created_account.identity)
25
+ else
26
+ created_account
27
+ end
28
+ end
29
+
30
+ def create_user(options={})
31
+ creator = options[:creator] || create_client
32
+ client = options[:client]
33
+
34
+ attributes = options[:user] || {}
35
+ attributes[:name] ||= Faker::Name.name
36
+ attributes[:email] ||= Faker::Internet.email
37
+
38
+ created_user = creator.users.create!(attributes)
39
+
40
+ if client
41
+ client.users.get!(created_user.identity)
42
+ else
43
+ created_user
44
+ end
45
+ end
46
+
47
+ def create_provider(options={})
48
+ account = options[:account] || create_account(options)
49
+
50
+ attributes = options[:provider] || {}
51
+ attributes[:type] ||= :aws
52
+ attributes[:provisioned_id] ||= SecureRandom.hex(8)
53
+ attributes[:credentials] ||= case attributes[:type]
54
+ when :aws then
55
+ {
56
+ :instance_aws_secret_id => SecureRandom.hex(6),
57
+ :instance_aws_secret_key => SecureRandom.hex(6),
58
+ :aws_secret_id => SecureRandom.hex(6),
59
+ :aws_secret_key => SecureRandom.hex(6),
60
+ :aws_login => Faker::Internet.email,
61
+ :aws_pass => SecureRandom.hex(6),
62
+ }
63
+ when :azure then
64
+ {
65
+ }
66
+ end
67
+
68
+ account.providers.create!(attributes).resource!
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ module Ey
2
+ module Core
3
+ module TestHelpers
4
+ module AlertHelpers
5
+ def create_legacy_alert(client, attributes={})
6
+ attributes = Cistern::Hash.stringify_keys(attributes)
7
+
8
+ if server = attributes.delete("server")
9
+ attributes["server"] = client.url_for("/servers/#{server.id}")
10
+ end
11
+ client.data[:legacy_alerts][attributes["id"]] = attributes
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ module Ey
2
+ module Core
3
+ module TestHelpers
4
+ module ClientHelpers
5
+ def create_client(attributes={})
6
+ token = if (user = attributes.delete(:user)) && Ey::Core::Client.mocking?
7
+ core = Ey::Core::Client::Mock.data.values.find { |c| c[:users][user.identity] }
8
+ core[:users][user.identity]["token"]
9
+ end
10
+ token ||= begin
11
+ token_dotfile = YAML.load_file(File.expand_path("/../../../.token"), __FILE__) rescue {}
12
+ ENV["CORE_TOKEN"] || token_dotfile[ENV["CORE_URL"]] || "a4bf6558da8c1051536d1596b8931ebd346aff0b"
13
+ end
14
+
15
+ merged_attributes = attributes.merge(token: token, cache: true)
16
+ merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']
17
+
18
+ Ey::Core::Client.new(merged_attributes)
19
+ end
20
+
21
+ def create_server_client(server, attributes={})
22
+ unless core = Ey::Core::Client::Mock.data.values.find { |data| data[:servers][server.identity] }
23
+ raise "Failed to find server in mock data: #{server}"
24
+ end
25
+
26
+ token = core[:servers][server.identity]["token"]
27
+
28
+ merged_attributes = attributes.merge(token: token, cache: true)
29
+ merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']
30
+
31
+ Ey::Core::Client.new(merged_attributes)
32
+ end
33
+
34
+ def create_unauthenticated_client
35
+ Ey::Core::Client.new(token: nil)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ require 'ey-core/test_helpers'
2
+
3
+ World(Ey::Core::TestHelpers)
@@ -0,0 +1,193 @@
1
+ module Ey
2
+ module Core
3
+ module TestHelpers
4
+ module ResourceHelpers
5
+ def load_blueprint(options={})
6
+ application = create_application(account: account)
7
+ database_service = create_database_service(provider: account.providers.first)
8
+ environment = create_environment(account: account, application: application, database_service: database_service, environment: {name: "environment#{SecureRandom.hex(4)}"})
9
+
10
+ [database_service, environment]
11
+ end
12
+
13
+ def create_application(options={})
14
+ account = options.delete(:account) || create_account(options)
15
+ options = Cistern::Hash.stringify_keys(options)
16
+
17
+ options["name"] ||= "application#{SecureRandom.hex(4)}"
18
+ options["repository"] ||= "git://github.com/engineyard/todo.git"
19
+ options["type"] ||= "rails4"
20
+
21
+ account.applications.create!(options)
22
+ end
23
+
24
+ def create_server(client, options={})
25
+ options = Cistern::Hash.stringify_keys(options)
26
+
27
+ request = environment.servers.create(
28
+ "flavor" => "m3.medium",
29
+ "role" => "util",
30
+ )
31
+
32
+ request.resource!
33
+ end
34
+
35
+ def create_cost(client, options={})
36
+ account = options[:account] || create_account(client: client)
37
+ level = options[:level] || "summarized"
38
+ finality = options[:finality] || "estimated"
39
+ related_resource_type = options[:related_resource_type] || "account"
40
+ category = options[:category] || "non-server"
41
+ description = options[:description] || "AWS Other Services"
42
+ value = options[:value] || "1763"
43
+ environment = options[:environment] || nil
44
+
45
+ client.data[:costs] << {
46
+ billing_month: "2015-07",
47
+ data_type: "cost",
48
+ level: level,
49
+ finality: finality,
50
+ related_resource_type: related_resource_type,
51
+ category: category,
52
+ units: "USD cents",
53
+ description: description,
54
+ value: value,
55
+ account: client.url_for("accounts/#{account.identity}"),
56
+ environment: environment
57
+ }
58
+ end
59
+
60
+ def create_account_referral(client, options={})
61
+ referred = options.delete(:referred) || create_account(client: client)
62
+ referrer = options.delete(:referrer) || create_account(client: client)
63
+
64
+ account_referral_id = SecureRandom.uuid
65
+ referral = client.data[:account_referrals][account_referral_id] = {
66
+ "id" => account_referral_id,
67
+ "referrer" => client.url_for("accounts/#{referrer.identity}"),
68
+ "referred" => client.url_for("accounts/#{referred.identity}"),
69
+ }
70
+
71
+ client.account_referrals.new(referral)
72
+ end
73
+
74
+ def create_firewall(client, options={})
75
+ provider = options.fetch(:provider) { create_provider(client: client) }
76
+
77
+ firewall_params = options[:firewall] || {}
78
+ name = firewall_params.delete(:name) || SecureRandom.hex(6)
79
+ location = firewall_params.delete(:location) || "us-west-2"
80
+
81
+ client.firewalls.create!(
82
+ :name => name,
83
+ :location => location,
84
+ :provider => provider,
85
+ ).resource!
86
+ end
87
+
88
+ def create_database_service(options={})
89
+ provider = options[:provider] || create_provider(options.merge(client: client))
90
+
91
+ database_service_params = Hashie::Mash.new(
92
+ :name => Faker::Name.first_name,
93
+ :provider => provider,
94
+ ).merge(options.fetch(:database_service, {}))
95
+
96
+ database_server_params = Hashie::Mash.new(
97
+ :location => "us-west-2c",
98
+ :flavor => "db.m3.large",
99
+ :engine => "postgres",
100
+ :version => "9.3.5",
101
+ ).merge(options.fetch(:database_server, {}))
102
+
103
+ client.database_services.create!(database_service_params.merge(database_server: database_server_params)).resource!
104
+ end
105
+
106
+ def create_environment(options={})
107
+ account = options[:account] || create_account(options)
108
+
109
+ unless account.providers.first || options[:provider]
110
+ create_provider(account: account)
111
+ end
112
+
113
+ environment = options[:environment] || {}
114
+ application = options[:application] || create_application(account: account)
115
+ database_service = options[:database_service]
116
+ configuration = Cistern::Hash.stringify_keys(options[:configuration] || {})
117
+ configuration["type"] = "production-cluster" if configuration["type"] == "production"
118
+ configuration["type"] ||= "solo"
119
+ environment[:name] ||= options.fetch(:name, SecureRandom.hex(3))
120
+ environment[:region] ||= "us-west-2"
121
+
122
+ environment.merge!(application_id: application.id, account: account)
123
+ environment.merge!(database_service: database_service) if database_service
124
+ environment = client.environments.create!(environment)
125
+
126
+ unless options[:boot] == false
127
+ request = environment.boot(configuration: configuration, application_id: application.id)
128
+ request.ready!
129
+ end
130
+ environment
131
+ end
132
+
133
+ def create_provider_location(client, attributes={})
134
+ attributes = Cistern::Hash.stringify_keys(attributes)
135
+
136
+ if provider = attributes.delete("provider")
137
+ attributes["provider"] = client.url_for("/providers/#{provider.id}")
138
+ end
139
+
140
+ attributes["id"] ||= client.uuid
141
+ client.data[:provider_locations][attributes["id"]] = attributes
142
+
143
+ client.provider_locations.new(attributes)
144
+ end
145
+
146
+ def create_server_event(client, attributes={})
147
+ attributes = Cistern::Hash.stringify_keys(attributes)
148
+
149
+ attributes.fetch("type")
150
+
151
+ if server = attributes.delete("server")
152
+ attributes["server"] = client.url_for("/servers/#{server.id}")
153
+ end
154
+
155
+ event_id = attributes["id"] ||= SecureRandom.uuid
156
+
157
+ client.server_events.new(
158
+ client.data[:server_events][event_id] = attributes
159
+ )
160
+ end
161
+
162
+ def create_logical_database(options={})
163
+ database_service = options.fetch(:database_service) { create_database_service(options) }
164
+
165
+ database_service.databases.create!(
166
+ :name => SecureRandom.hex(6),
167
+ :username => "ey#{SecureRandom.hex(6)}",
168
+ :password => SecureRandom.hex(8),
169
+ ).resource!
170
+ end
171
+
172
+ def create_untracked_server(options={})
173
+ provider = options.fetch(:provider) { create_provider(options) }
174
+
175
+ untracked_server = options[:untracked_server] || {}
176
+
177
+ provisioner_id = untracked_server[:provisioner_id] || SecureRandom.uuid
178
+ location = untracked_server[:location] || "us-west-2b"
179
+ provisioned_id = untracked_server[:provisioned_id] || "i-#{SecureRandom.hex(4)}"
180
+ state = untracked_server[:state] || "found"
181
+
182
+ client.untracked_servers.create(
183
+ :location => location,
184
+ :provider => provider,
185
+ :provisioned_id => provisioned_id,
186
+ :provisioner_id => provisioner_id,
187
+ :state => state,
188
+ )
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,5 @@
1
+ require 'ey-core/test_helpers'
2
+
3
+ RSpec.configure do |config|
4
+ config.include(Ey::Core::TestHelpers)
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Ey
2
2
  module Core
3
- VERSION = "3.1.10"
3
+ VERSION = "3.1.11"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ require 'ey-core/test_helpers/rspec'
metadata CHANGED
@@ -1,144 +1,164 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ey-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.10
4
+ version: 3.1.11
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Josh Lane
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-08-03 00:00:00.000000000 Z
12
+ date: 2016-08-08 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: addressable
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '2.2'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2.2'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: awesome_print
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - ">="
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - ">="
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: belafonte
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - ">="
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - ">="
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: cistern
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - "~>"
67
+ - - ~>
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0.12'
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - "~>"
75
+ - - ~>
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0.12'
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: colorize
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - ">="
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: '0'
76
86
  type: :runtime
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - ">="
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: '0'
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: ey-hmac
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - "~>"
99
+ - - ~>
88
100
  - !ruby/object:Gem::Version
89
101
  version: '2.0'
90
102
  type: :runtime
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - "~>"
107
+ - - ~>
95
108
  - !ruby/object:Gem::Version
96
109
  version: '2.0'
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: escape
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
- - - ">="
115
+ - - ! '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
- - - ">="
123
+ - - ! '>='
109
124
  - !ruby/object:Gem::Version
110
125
  version: '0'
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: faraday
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
- - - "~>"
131
+ - - ~>
116
132
  - !ruby/object:Gem::Version
117
133
  version: '0.9'
118
134
  type: :runtime
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
- - - "~>"
139
+ - - ~>
123
140
  - !ruby/object:Gem::Version
124
141
  version: '0.9'
125
142
  - !ruby/object:Gem::Dependency
126
143
  name: faraday_middleware
127
144
  requirement: !ruby/object:Gem::Requirement
145
+ none: false
128
146
  requirements:
129
- - - "~>"
147
+ - - ~>
130
148
  - !ruby/object:Gem::Version
131
149
  version: '0.9'
132
150
  type: :runtime
133
151
  prerelease: false
134
152
  version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
135
154
  requirements:
136
- - - "~>"
155
+ - - ~>
137
156
  - !ruby/object:Gem::Version
138
157
  version: '0.9'
139
158
  - !ruby/object:Gem::Dependency
140
159
  name: rack
141
160
  requirement: !ruby/object:Gem::Requirement
161
+ none: false
142
162
  requirements:
143
163
  - - '='
144
164
  - !ruby/object:Gem::Version
@@ -146,6 +166,7 @@ dependencies:
146
166
  type: :runtime
147
167
  prerelease: false
148
168
  version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
149
170
  requirements:
150
171
  - - '='
151
172
  - !ruby/object:Gem::Version
@@ -153,183 +174,209 @@ dependencies:
153
174
  - !ruby/object:Gem::Dependency
154
175
  name: faye
155
176
  requirement: !ruby/object:Gem::Requirement
177
+ none: false
156
178
  requirements:
157
- - - ">="
179
+ - - ! '>='
158
180
  - !ruby/object:Gem::Version
159
181
  version: '0'
160
182
  type: :runtime
161
183
  prerelease: false
162
184
  version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
163
186
  requirements:
164
- - - ">="
187
+ - - ! '>='
165
188
  - !ruby/object:Gem::Version
166
189
  version: '0'
167
190
  - !ruby/object:Gem::Dependency
168
191
  name: highline
169
192
  requirement: !ruby/object:Gem::Requirement
193
+ none: false
170
194
  requirements:
171
- - - ">="
195
+ - - ! '>='
172
196
  - !ruby/object:Gem::Version
173
197
  version: '0'
174
198
  type: :runtime
175
199
  prerelease: false
176
200
  version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
177
202
  requirements:
178
- - - ">="
203
+ - - ! '>='
179
204
  - !ruby/object:Gem::Version
180
205
  version: '0'
181
206
  - !ruby/object:Gem::Dependency
182
207
  name: json
183
208
  requirement: !ruby/object:Gem::Requirement
209
+ none: false
184
210
  requirements:
185
- - - "<"
211
+ - - <
186
212
  - !ruby/object:Gem::Version
187
213
  version: '2.0'
188
214
  type: :runtime
189
215
  prerelease: false
190
216
  version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
191
218
  requirements:
192
- - - "<"
219
+ - - <
193
220
  - !ruby/object:Gem::Version
194
221
  version: '2.0'
195
222
  - !ruby/object:Gem::Dependency
196
223
  name: mime-types
197
224
  requirement: !ruby/object:Gem::Requirement
225
+ none: false
198
226
  requirements:
199
- - - "~>"
227
+ - - ~>
200
228
  - !ruby/object:Gem::Version
201
229
  version: '2.99'
202
230
  type: :runtime
203
231
  prerelease: false
204
232
  version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
205
234
  requirements:
206
- - - "~>"
235
+ - - ~>
207
236
  - !ruby/object:Gem::Version
208
237
  version: '2.99'
209
238
  - !ruby/object:Gem::Dependency
210
239
  name: oj
211
240
  requirement: !ruby/object:Gem::Requirement
241
+ none: false
212
242
  requirements:
213
- - - ">="
243
+ - - ! '>='
214
244
  - !ruby/object:Gem::Version
215
245
  version: '0'
216
246
  type: :runtime
217
247
  prerelease: false
218
248
  version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
219
250
  requirements:
220
- - - ">="
251
+ - - ! '>='
221
252
  - !ruby/object:Gem::Version
222
253
  version: '0'
223
254
  - !ruby/object:Gem::Dependency
224
255
  name: oj_mimic_json
225
256
  requirement: !ruby/object:Gem::Requirement
257
+ none: false
226
258
  requirements:
227
- - - ">="
259
+ - - ! '>='
228
260
  - !ruby/object:Gem::Version
229
261
  version: '0'
230
262
  type: :runtime
231
263
  prerelease: false
232
264
  version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
233
266
  requirements:
234
- - - ">="
267
+ - - ! '>='
235
268
  - !ruby/object:Gem::Version
236
269
  version: '0'
237
270
  - !ruby/object:Gem::Dependency
238
271
  name: pry
239
272
  requirement: !ruby/object:Gem::Requirement
273
+ none: false
240
274
  requirements:
241
- - - ">="
275
+ - - ! '>='
242
276
  - !ruby/object:Gem::Version
243
277
  version: '0'
244
278
  type: :runtime
245
279
  prerelease: false
246
280
  version_requirements: !ruby/object:Gem::Requirement
281
+ none: false
247
282
  requirements:
248
- - - ">="
283
+ - - ! '>='
249
284
  - !ruby/object:Gem::Version
250
285
  version: '0'
251
286
  - !ruby/object:Gem::Dependency
252
287
  name: sshkey
253
288
  requirement: !ruby/object:Gem::Requirement
289
+ none: false
254
290
  requirements:
255
- - - "~>"
291
+ - - ~>
256
292
  - !ruby/object:Gem::Version
257
293
  version: '1.6'
258
294
  type: :runtime
259
295
  prerelease: false
260
296
  version_requirements: !ruby/object:Gem::Requirement
297
+ none: false
261
298
  requirements:
262
- - - "~>"
299
+ - - ~>
263
300
  - !ruby/object:Gem::Version
264
301
  version: '1.6'
265
302
  - !ruby/object:Gem::Dependency
266
303
  name: table_print
267
304
  requirement: !ruby/object:Gem::Requirement
305
+ none: false
268
306
  requirements:
269
- - - ">="
307
+ - - ! '>='
270
308
  - !ruby/object:Gem::Version
271
309
  version: '0'
272
310
  type: :runtime
273
311
  prerelease: false
274
312
  version_requirements: !ruby/object:Gem::Requirement
313
+ none: false
275
314
  requirements:
276
- - - ">="
315
+ - - ! '>='
277
316
  - !ruby/object:Gem::Version
278
317
  version: '0'
279
318
  - !ruby/object:Gem::Dependency
280
319
  name: pry-nav
281
320
  requirement: !ruby/object:Gem::Requirement
321
+ none: false
282
322
  requirements:
283
- - - ">="
323
+ - - ! '>='
284
324
  - !ruby/object:Gem::Version
285
325
  version: '0'
286
326
  type: :development
287
327
  prerelease: false
288
328
  version_requirements: !ruby/object:Gem::Requirement
329
+ none: false
289
330
  requirements:
290
- - - ">="
331
+ - - ! '>='
291
332
  - !ruby/object:Gem::Version
292
333
  version: '0'
293
334
  - !ruby/object:Gem::Dependency
294
335
  name: rspec
295
336
  requirement: !ruby/object:Gem::Requirement
337
+ none: false
296
338
  requirements:
297
- - - "~>"
339
+ - - ~>
298
340
  - !ruby/object:Gem::Version
299
341
  version: '3.0'
300
342
  type: :development
301
343
  prerelease: false
302
344
  version_requirements: !ruby/object:Gem::Requirement
345
+ none: false
303
346
  requirements:
304
- - - "~>"
347
+ - - ~>
305
348
  - !ruby/object:Gem::Version
306
349
  version: '3.0'
307
350
  - !ruby/object:Gem::Dependency
308
351
  name: ffaker
309
352
  requirement: !ruby/object:Gem::Requirement
353
+ none: false
310
354
  requirements:
311
- - - ">="
355
+ - - ! '>='
312
356
  - !ruby/object:Gem::Version
313
357
  version: '0'
314
358
  type: :development
315
359
  prerelease: false
316
360
  version_requirements: !ruby/object:Gem::Requirement
361
+ none: false
317
362
  requirements:
318
- - - ">="
363
+ - - ! '>='
319
364
  - !ruby/object:Gem::Version
320
365
  version: '0'
321
366
  - !ruby/object:Gem::Dependency
322
367
  name: rake
323
368
  requirement: !ruby/object:Gem::Requirement
369
+ none: false
324
370
  requirements:
325
- - - ">="
371
+ - - ! '>='
326
372
  - !ruby/object:Gem::Version
327
373
  version: '0'
328
374
  type: :development
329
375
  prerelease: false
330
376
  version_requirements: !ruby/object:Gem::Requirement
377
+ none: false
331
378
  requirements:
332
- - - ">="
379
+ - - ! '>='
333
380
  - !ruby/object:Gem::Version
334
381
  version: '0'
335
382
  description: Engine Yard Core API Ruby Client
@@ -341,10 +388,10 @@ executables:
341
388
  extensions: []
342
389
  extra_rdoc_files: []
343
390
  files:
344
- - ".gitignore"
345
- - ".ruby-gemset"
346
- - ".ruby-version"
347
- - ".travis.yml"
391
+ - .gitignore
392
+ - .ruby-gemset
393
+ - .ruby-version
394
+ - .travis.yml
348
395
  - CHANGELOG.md
349
396
  - Gemfile
350
397
  - Guardfile
@@ -720,6 +767,13 @@ files:
720
767
  - lib/ey-core/response.rb
721
768
  - lib/ey-core/response_cache.rb
722
769
  - lib/ey-core/subscribable.rb
770
+ - lib/ey-core/test_helpers.rb
771
+ - lib/ey-core/test_helpers/account_helpers.rb
772
+ - lib/ey-core/test_helpers/alert_helpers.rb
773
+ - lib/ey-core/test_helpers/client_helpers.rb
774
+ - lib/ey-core/test_helpers/cucumber.rb
775
+ - lib/ey-core/test_helpers/resource_helpers.rb
776
+ - lib/ey-core/test_helpers/rspec.rb
723
777
  - lib/ey-core/token_authentication.rb
724
778
  - lib/ey-core/version.rb
725
779
  - spec/account_trial_spec.rb
@@ -774,14 +828,11 @@ files:
774
828
  - spec/spec_helper.rb
775
829
  - spec/ssl_certificates_spec.rb
776
830
  - spec/storages_spec.rb
777
- - spec/support/account_helper.rb
778
- - spec/support/alert_helper.rb
779
831
  - spec/support/cli_helpers.rb
780
- - spec/support/client_helper.rb
781
832
  - spec/support/core.rb
782
833
  - spec/support/coverage.rb
783
834
  - spec/support/fake_kernel.rb
784
- - spec/support/resource_helper.rb
835
+ - spec/support/helpers.rb
785
836
  - spec/support/timecop.rb
786
837
  - spec/support_trial_spec.rb
787
838
  - spec/tokens_spec.rb
@@ -790,26 +841,27 @@ files:
790
841
  homepage: ''
791
842
  licenses:
792
843
  - MIT
793
- metadata: {}
794
844
  post_install_message:
795
845
  rdoc_options: []
796
846
  require_paths:
797
847
  - lib
798
848
  required_ruby_version: !ruby/object:Gem::Requirement
849
+ none: false
799
850
  requirements:
800
- - - ">="
851
+ - - ! '>='
801
852
  - !ruby/object:Gem::Version
802
853
  version: '0'
803
854
  required_rubygems_version: !ruby/object:Gem::Requirement
855
+ none: false
804
856
  requirements:
805
- - - ">="
857
+ - - ! '>='
806
858
  - !ruby/object:Gem::Version
807
859
  version: '0'
808
860
  requirements: []
809
861
  rubyforge_project:
810
- rubygems_version: 2.4.5
862
+ rubygems_version: 1.8.23.2
811
863
  signing_key:
812
- specification_version: 4
864
+ specification_version: 3
813
865
  summary: Client library providing real and mock functionality for accessing Engine
814
866
  Yard's Core API
815
867
  test_files:
@@ -865,14 +917,11 @@ test_files:
865
917
  - spec/spec_helper.rb
866
918
  - spec/ssl_certificates_spec.rb
867
919
  - spec/storages_spec.rb
868
- - spec/support/account_helper.rb
869
- - spec/support/alert_helper.rb
870
920
  - spec/support/cli_helpers.rb
871
- - spec/support/client_helper.rb
872
921
  - spec/support/core.rb
873
922
  - spec/support/coverage.rb
874
923
  - spec/support/fake_kernel.rb
875
- - spec/support/resource_helper.rb
924
+ - spec/support/helpers.rb
876
925
  - spec/support/timecop.rb
877
926
  - spec/support_trial_spec.rb
878
927
  - spec/tokens_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 0a2ccdb43d93c2b71693f033656d4a22d2d27c0e
4
- data.tar.gz: 1ba3ed1d50111cdc4479e0b98fe96d26c4b94924
5
- SHA512:
6
- metadata.gz: 0cd9461689b956a7482504159fbeeb4a1b5ecaf52a28828f9eb88e3eb8596be9308e1fb9f179a3b434a4a0fd06bdb9719b97895bc4ff224335bba52a264cf708
7
- data.tar.gz: b2e59843b4c0420eec5f4a071504b9de63d2dd1f090f192471b113a5a9fc6c7cecb4729c305444b6ff76cc63da399c98db29e7e6d113a4f26d32d97431f6b5b0
@@ -1,71 +0,0 @@
1
- module AccountHelper
2
- def create_account(options={})
3
- creator = options[:creator] || create_client
4
- client = options[:client]
5
-
6
- attributes = options[:account] || {}
7
- attributes[:type] ||= "beta" # get around awsm billing requirements for tests
8
- attributes[:name] ||= SecureRandom.hex(6)
9
-
10
- if client
11
- attributes[:owner] ||= begin
12
- client.users.current
13
- rescue Ey::Core::Response::NotFound
14
- end
15
- end
16
- attributes[:owner] ||= create_user(client: client)
17
-
18
- created_account = (client || creator).accounts.create!(attributes)
19
-
20
- if client
21
- client.accounts.get!(created_account.identity)
22
- else
23
- created_account
24
- end
25
- end
26
-
27
- def create_user(options={})
28
- creator = options[:creator] || create_client
29
- client = options[:client]
30
-
31
- attributes = options[:user] || {}
32
- attributes[:name] ||= Faker::Name.name
33
- attributes[:email] ||= Faker::Internet.email
34
-
35
- created_user = creator.users.create!(attributes)
36
-
37
- if client
38
- client.users.get!(created_user.identity)
39
- else
40
- created_user
41
- end
42
- end
43
-
44
- def create_provider(options={})
45
- account = options[:account] || create_account(options)
46
-
47
- attributes = options[:provider] || {}
48
- attributes[:type] ||= :aws
49
- attributes[:provisioned_id] ||= SecureRandom.hex(8)
50
- attributes[:credentials] ||= case attributes[:type]
51
- when :aws then
52
- {
53
- :instance_aws_secret_id => SecureRandom.hex(6),
54
- :instance_aws_secret_key => SecureRandom.hex(6),
55
- :aws_secret_id => SecureRandom.hex(6),
56
- :aws_secret_key => SecureRandom.hex(6),
57
- :aws_login => Faker::Internet.email,
58
- :aws_pass => SecureRandom.hex(6),
59
- }
60
- when :azure then
61
- {
62
- }
63
- end
64
-
65
- account.providers.create!(attributes).resource!
66
- end
67
- end
68
-
69
- RSpec.configure do |config|
70
- config.include(AccountHelper)
71
- end
@@ -1,14 +0,0 @@
1
- module LegacyAlertHelper
2
- def create_legacy_alert(client, attributes={})
3
- attributes = Cistern::Hash.stringify_keys(attributes)
4
-
5
- if server = attributes.delete("server")
6
- attributes["server"] = client.url_for("/servers/#{server.id}")
7
- end
8
- client.data[:legacy_alerts][attributes["id"]] = attributes
9
- end
10
- end
11
-
12
- RSpec.configure do |config|
13
- config.include(LegacyAlertHelper)
14
- end
@@ -1,38 +0,0 @@
1
- module ClientHelper
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
- RSpec.configure do |config|
37
- config.include(ClientHelper)
38
- end
@@ -1,191 +0,0 @@
1
- module ResourceHelper
2
- def load_blueprint(options={})
3
- application = create_application(account: account)
4
- database_service = create_database_service(provider: account.providers.first)
5
- environment = create_environment(account: account, application: application, database_service: database_service, environment: {name: "environment#{SecureRandom.hex(4)}"})
6
-
7
- [database_service, environment]
8
- end
9
-
10
- def create_application(options={})
11
- account = options.delete(:account) || create_account(options)
12
- options = Cistern::Hash.stringify_keys(options)
13
-
14
- options["name"] ||= "application#{SecureRandom.hex(4)}"
15
- options["repository"] ||= "git://github.com/engineyard/todo.git"
16
- options["type"] ||= "rails4"
17
-
18
- account.applications.create!(options)
19
- end
20
-
21
- def create_server(client, options={})
22
- options = Cistern::Hash.stringify_keys(options)
23
-
24
- request = environment.servers.create(
25
- "flavor" => "m3.medium",
26
- "role" => "util",
27
- )
28
-
29
- request.resource!
30
- end
31
-
32
- def create_cost(client, options={})
33
- account = options[:account] || create_account(client: client)
34
- level = options[:level] || "summarized"
35
- finality = options[:finality] || "estimated"
36
- related_resource_type = options[:related_resource_type] || "account"
37
- category = options[:category] || "non-server"
38
- description = options[:description] || "AWS Other Services"
39
- value = options[:value] || "1763"
40
- environment = options[:environment] || nil
41
-
42
- client.data[:costs] << {
43
- billing_month: "2015-07",
44
- data_type: "cost",
45
- level: level,
46
- finality: finality,
47
- related_resource_type: related_resource_type,
48
- category: category,
49
- units: "USD cents",
50
- description: description,
51
- value: value,
52
- account: client.url_for("accounts/#{account.identity}"),
53
- environment: environment
54
- }
55
- end
56
-
57
- def create_account_referral(client, options={})
58
- referred = options.delete(:referred) || create_account(client: client)
59
- referrer = options.delete(:referrer) || create_account(client: client)
60
-
61
- account_referral_id = SecureRandom.uuid
62
- referral = client.data[:account_referrals][account_referral_id] = {
63
- "id" => account_referral_id,
64
- "referrer" => client.url_for("accounts/#{referrer.identity}"),
65
- "referred" => client.url_for("accounts/#{referred.identity}"),
66
- }
67
-
68
- client.account_referrals.new(referral)
69
- end
70
-
71
- def create_firewall(client, options={})
72
- provider = options.fetch(:provider) { create_provider(client: client) }
73
-
74
- firewall_params = options[:firewall] || {}
75
- name = firewall_params.delete(:name) || SecureRandom.hex(6)
76
- location = firewall_params.delete(:location) || "us-west-2"
77
-
78
- client.firewalls.create!(
79
- :name => name,
80
- :location => location,
81
- :provider => provider,
82
- ).resource!
83
- end
84
-
85
- def create_database_service(options={})
86
- provider = options[:provider] || create_provider(options.merge(client: client))
87
-
88
- database_service_params = Hashie::Mash.new(
89
- :name => Faker::Name.first_name,
90
- :provider => provider,
91
- ).merge(options.fetch(:database_service, {}))
92
-
93
- database_server_params = Hashie::Mash.new(
94
- :location => "us-west-2c",
95
- :flavor => "db.m3.large",
96
- :engine => "postgres",
97
- :version => "9.3.5",
98
- ).merge(options.fetch(:database_server, {}))
99
-
100
- client.database_services.create!(database_service_params.merge(database_server: database_server_params)).resource!
101
- end
102
-
103
- def create_environment(options={})
104
- account = options[:account] || create_account(options)
105
-
106
- unless account.providers.first || options[:provider]
107
- create_provider(account: account)
108
- end
109
-
110
- environment = options[:environment] || {}
111
- application = options[:application] || create_application(account: account)
112
- database_service = options[:database_service]
113
- configuration = Cistern::Hash.stringify_keys(options[:configuration] || {})
114
- configuration["type"] = "production-cluster" if configuration["type"] == "production"
115
- configuration["type"] ||= "solo"
116
- environment[:name] ||= options.fetch(:name, SecureRandom.hex(3))
117
- environment[:region] ||= "us-west-2"
118
-
119
- environment.merge!(application_id: application.id, account: account)
120
- environment.merge!(database_service: database_service) if database_service
121
- environment = client.environments.create!(environment)
122
-
123
- unless options[:boot] == false
124
- request = environment.boot(configuration: configuration, application_id: application.id)
125
- request.ready!
126
- end
127
- environment
128
- end
129
-
130
- def create_provider_location(client, attributes={})
131
- attributes = Cistern::Hash.stringify_keys(attributes)
132
-
133
- if provider = attributes.delete("provider")
134
- attributes["provider"] = client.url_for("/providers/#{provider.id}")
135
- end
136
-
137
- attributes["id"] ||= client.uuid
138
- client.data[:provider_locations][attributes["id"]] = attributes
139
-
140
- client.provider_locations.new(attributes)
141
- end
142
-
143
- def create_server_event(client, attributes={})
144
- attributes = Cistern::Hash.stringify_keys(attributes)
145
-
146
- attributes.fetch("type")
147
-
148
- if server = attributes.delete("server")
149
- attributes["server"] = client.url_for("/servers/#{server.id}")
150
- end
151
-
152
- event_id = attributes["id"] ||= SecureRandom.uuid
153
-
154
- client.server_events.new(
155
- client.data[:server_events][event_id] = attributes
156
- )
157
- end
158
-
159
- def create_logical_database(options={})
160
- database_service = options.fetch(:database_service) { create_database_service(options) }
161
-
162
- database_service.databases.create!(
163
- :name => SecureRandom.hex(6),
164
- :username => "ey#{SecureRandom.hex(6)}",
165
- :password => SecureRandom.hex(8),
166
- ).resource!
167
- end
168
-
169
- def create_untracked_server(options={})
170
- provider = options.fetch(:provider) { create_provider(options) }
171
-
172
- untracked_server = options[:untracked_server] || {}
173
-
174
- provisioner_id = untracked_server[:provisioner_id] || SecureRandom.uuid
175
- location = untracked_server[:location] || "us-west-2b"
176
- provisioned_id = untracked_server[:provisioned_id] || "i-#{SecureRandom.hex(4)}"
177
- state = untracked_server[:state] || "found"
178
-
179
- client.untracked_servers.create(
180
- :location => location,
181
- :provider => provider,
182
- :provisioned_id => provisioned_id,
183
- :provisioner_id => provisioner_id,
184
- :state => state,
185
- )
186
- end
187
- end
188
-
189
- RSpec.configure do |config|
190
- config.include(ResourceHelper)
191
- end