ey-core 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 269d550338f16307307e6d1bbcf9c515c63fdd0f
4
- data.tar.gz: 8629dc4f02afc87b6d1787038c7af137f08b5b07
3
+ metadata.gz: 211941aaeeb4aa4287a63a54d47cabc37637e69f
4
+ data.tar.gz: bc49c5e7785bc9ce59b86ae8bd61d4870ae097a6
5
5
  SHA512:
6
- metadata.gz: a7deba35785bcbf0e54472e455f0a0617c8c199af99c55a4b51c1d00fb0b4948bb386e3798752991939d194ad3794dec8c15e7cdffcab6c1dd2c4982bc9e629d
7
- data.tar.gz: 314171d0e20483463062e695a1f45abe1688658d67979d821bcd827d4b35fdf98ec0792371abe9ef08e06e6e43611845c3ac7c22b1e5ccc8563e0f4375eabcb6
6
+ metadata.gz: 0af79f96731322e573b6a543cccfd65bb0ff3c5815cea46eadc698f5b7e8554408003f1eeb49d83abf0d0eb36039c979a980bb2532ceafc9ae2bc29292a8cf58
7
+ data.tar.gz: d67529719c20a554a4ed226ca2dfc8d5f1fc2061734de03b8d9647e552a47971d4de01b20590216e6c4965621ce4987d825b66c58b9c98744c82b7ad62737e8e
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- Uses [cistern](https://github.com/lanej/cistern) to wrap RESTful resources nicely. See [rdoc](https://docbox.engineyard.com/core/branch/master/index.html).
21
+ Uses [cistern](https://github.com/lanej/cistern) to wrap RESTful resources nicely.
22
22
 
23
23
  ```ruby
24
24
  client.users.current # =>
@@ -68,10 +68,6 @@ Ey::Core::Client.reset!
68
68
 
69
69
  By default, specs are run against the core mock. In order to run them against awsm mocked mode instead, run `MOCK_CORE=false bundle exec rspec`
70
70
 
71
- ## Releasing
72
-
73
- $ gem install gem-release
74
- $ gem bump -trv (major|minor|patch) --host https://geminst:XXX@nextgem.engineyard.com/
75
71
 
76
72
  ## Contributing
77
73
 
@@ -114,6 +114,8 @@ class Ey::Core::Client < Cistern::Service
114
114
  model :user
115
115
  model :volume
116
116
 
117
+ request :apply_environment_updates
118
+ request :apply_server_updates
117
119
  request :attach_address
118
120
  request :authorized_channel
119
121
  request :boot_environment
@@ -265,6 +267,8 @@ class Ey::Core::Client < Cistern::Service
265
267
  request :get_support_trial
266
268
  request :get_task
267
269
  request :get_tasks
270
+ request :get_token
271
+ request :get_tokens
268
272
  request :get_untracked_server
269
273
  request :get_untracked_servers
270
274
  request :get_user
@@ -136,6 +136,7 @@ class Ey::Core::Client::Mock
136
136
  :features => {},
137
137
  :firewall_rules => {},
138
138
  :firewalls => {},
139
+ :instance_updates => {},
139
140
  :keypair_deployments => {},
140
141
  :keypairs => {},
141
142
  :legacy_alerts => {},
@@ -160,6 +161,7 @@ class Ey::Core::Client::Mock
160
161
  :support_trials => {},
161
162
  :tasks => {},
162
163
  :temp_files => {},
164
+ :tokens => {},
163
165
  :untracked_servers => {},
164
166
  :users => {},
165
167
  :volumes => {},
@@ -3,6 +3,7 @@ class Ey::Core::Client::Tokens < Ey::Core::Collection
3
3
  model Ey::Core::Client::Token
4
4
 
5
5
  self.model_root = "token"
6
+ self.model_request = :get_token
6
7
  self.collection_root = "tokens"
8
+ self.collection_request = :get_tokens
7
9
  end
8
-
@@ -51,6 +51,10 @@ class Ey::Core::Client::Environment < Ey::Core::Model
51
51
  connection.requests.new(response.body["request"])
52
52
  end
53
53
 
54
+ def apply(type="main")
55
+ connection.requests.new(self.connection.apply_environment_updates("id" => self.id, "type" => type).body["request"])
56
+ end
57
+
54
58
  def deprovision
55
59
  connection.requests.new(self.connection.deprovision_environment("id" => self.id).body["request"])
56
60
  end
@@ -21,6 +21,8 @@ class Ey::Core::Client::Server < Ey::Core::Model
21
21
  attribute :ssh_port, type: :integer
22
22
  attribute :state
23
23
  attribute :updated_at, type: :time
24
+ attribute :wait_for_chef, type: :boolean
25
+ attribute :release_label
24
26
 
25
27
  has_one :account
26
28
  has_one :address, collection: "addresses"
@@ -34,6 +36,12 @@ class Ey::Core::Client::Server < Ey::Core::Model
34
36
 
35
37
  attr_accessor :mnt_volume_size, :volume_size, :iops, :snapshot_id
36
38
 
39
+ def apply(type="main")
40
+ requires :identity
41
+
42
+ connection.requests.new(self.connection.apply_server_updates("id" => self.identity, "type" => type).body["request"])
43
+ end
44
+
37
45
  def reboot
38
46
  requires :identity
39
47
 
@@ -48,6 +56,7 @@ class Ey::Core::Client::Server < Ey::Core::Model
48
56
 
49
57
  server_attributes = {
50
58
  "environment" => environment.id,
59
+ "wait_for_chef" => self.wait_for_chef,
51
60
  "snapshot" => self.snapshot_id,
52
61
  "server" => {
53
62
  "flavor" => self.flavor_id,
@@ -57,6 +66,7 @@ class Ey::Core::Client::Server < Ey::Core::Model
57
66
  "name" => self.name,
58
67
  "role" => self.role,
59
68
  "volume_size" => self.volume_size,
69
+ "release_label" => self.release_label,
60
70
  }
61
71
  }
62
72
  connection.requests.new(connection.create_server(server_attributes).body["request"])
@@ -1,8 +1,12 @@
1
1
  class Ey::Core::Client::Token < Ey::Core::Model
2
2
 
3
- identity :auth_id
3
+ identity :id
4
4
 
5
+ attribute :auth_id
5
6
  attribute :on_behalf_of
7
+ attribute :last_seen_at, type: :time
8
+ attribute :expires_at, type: :time
9
+ attribute :revoked_at, type: :time
6
10
 
7
11
  def save!
8
12
  params = {
@@ -10,6 +10,7 @@ class Ey::Core::Client::User < Ey::Core::Model
10
10
 
11
11
  has_many :accounts
12
12
  has_many :keypairs
13
+ has_many :tokens
13
14
 
14
15
  attr_accessor :password
15
16
 
@@ -0,0 +1,54 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def apply_environment_updates(options={})
4
+ id = options.delete("id")
5
+ url = options.delete("url")
6
+
7
+ request(
8
+ :path => "environments/#{id}/apply",
9
+ :method => :post,
10
+ :url => url,
11
+ :body => options,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def apply_environment_updates(options={})
18
+ id = options.delete("id")
19
+ servers = get_servers("environment" => id).body["servers"]
20
+ request_id = self.uuid
21
+
22
+ servers.each do |server|
23
+ update_id = self.uuid
24
+ self.data[:instance_updates][update_id] = {
25
+ "id" => update_id,
26
+ "instance_id" => server["id"],
27
+ "data" => {
28
+ "type" => options["type"] || "main",
29
+ }
30
+ }
31
+ end
32
+
33
+ request = {
34
+ "id" => request_id,
35
+ "type" => "configure_environment",
36
+ "successful" => true,
37
+ "started_at" => Time.now,
38
+ "finished_at" => Time.now,
39
+ "resource_url" => nil,
40
+ "resource" => nil,
41
+ }
42
+
43
+ self.data[:requests][request_id] = request
44
+
45
+ response_hash = request.dup
46
+ response_hash.delete("resource")
47
+
48
+ response(
49
+ :body => {"request" => response_hash},
50
+ :status => 201,
51
+ )
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,52 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def apply_server_updates(options={})
4
+ id = options.delete("id")
5
+ url = options.delete("url")
6
+
7
+ request(
8
+ :path => "servers/#{id}/apply",
9
+ :method => :post,
10
+ :url => url,
11
+ :body => options,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def apply_server_updates(options={})
18
+ id = options.delete("id")
19
+ server = self.data[:servers][id]
20
+ request_id = self.uuid
21
+ update_id = self.uuid
22
+
23
+ self.data[:instance_updates][update_id] = {
24
+ "id" => update_id,
25
+ "instance_id" => server["id"],
26
+ "data" => {
27
+ "type" => options["type"] || "main",
28
+ }
29
+ }
30
+
31
+ request = {
32
+ "id" => request_id,
33
+ "type" => "instance_update",
34
+ "successful" => true,
35
+ "started_at" => Time.now,
36
+ "finished_at" => Time.now,
37
+ "resource_url" => nil,
38
+ "resource" => nil,
39
+ }
40
+
41
+ self.data[:requests][request_id] = request
42
+
43
+ response_hash = request.dup
44
+ response_hash.delete("resource")
45
+
46
+ response(
47
+ :body => {"request" => response_hash},
48
+ :status => 201,
49
+ )
50
+ end
51
+ end
52
+ end
@@ -20,18 +20,26 @@ class Ey::Core::Client
20
20
  )
21
21
  end
22
22
 
23
- resource_id = self.uuid
23
+ resource_id = self.uuid
24
+ token_id = self.uuid
25
+ token_auth_id = self.uuid
24
26
 
25
27
  resource = params["user"].dup
26
- resource["token"] = SecureRandom.hex(20)
27
28
 
28
29
  resource.merge!({
29
30
  "id" => resource_id,
30
31
  "accounts" => url_for("/users/#{resource_id}/accounts"),
31
32
  "memberships" => url_for("/users/#{resource_id}/memberships"),
32
33
  "keypairs" => url_for("/users/#{resource_id}/keypairs"),
34
+ "tokens" => url_for("/users/#{resource_id}/tokens"),
33
35
  })
34
36
 
37
+ self.data[:tokens][token_id] = {
38
+ "id" => token_id,
39
+ "auth_id" => token_auth_id,
40
+ "on_behalf_of" => url_for("/users/#{resource_id}"),
41
+ }
42
+
35
43
  self.data[:users][resource_id] = resource
36
44
 
37
45
  response(
@@ -0,0 +1,21 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_token(options={})
4
+ id = options.delete("id")
5
+ url = options.delete("url")
6
+
7
+ request(
8
+ :path => "tokens/#{id}",
9
+ :url => url,
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def get_token(options={})
16
+ response(
17
+ :body => {"token" => self.find(:tokens, resource_identity(options))},
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def get_tokens(params={})
4
+ query = Ey::Core.paging_parameters(params)
5
+ url = params.delete("url")
6
+
7
+ request(
8
+ :params => params,
9
+ :query => query,
10
+ :path => "/tokens",
11
+ :url => url,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_tokens(params={})
18
+ extract_url_params!(params)
19
+ find(:users, resource_identity(params["user"]))
20
+
21
+ params["on_behalf_of"] = params.delete("user")
22
+
23
+ headers, tokens_page = search_and_page(params, :tokens, search_keys: %w(on_behalf_of))
24
+
25
+ response(
26
+ :body => {"tokens" => tokens_page},
27
+ :status => 200,
28
+ :headers => headers,
29
+ )
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  module Ey
2
2
  module Core
3
- VERSION = "3.0.2"
3
+ VERSION = "3.0.3"
4
4
  end
5
5
  end
@@ -70,6 +70,24 @@ describe 'as a user' do
70
70
  let!(:name) { Faker::Name.first_name }
71
71
  let!(:environment) { create_environment(account: account, application: app, environment: {name: name}) }
72
72
 
73
+ it "applies main" do
74
+ expect(environment.apply.ready!).to be_successful
75
+
76
+ if Ey::Core::Client.mocking?
77
+ expect(client.data[:instance_updates].count).to eq(environment.servers.count)
78
+ expect(client.data[:instance_updates].values.map { |iu| iu["data"]["type"] }).to eq(["main"] * environment.servers.count)
79
+ end
80
+ end
81
+
82
+ it "applies custom" do
83
+ expect(environment.apply("custom").ready!).to be_successful
84
+
85
+ if Ey::Core::Client.mocking?
86
+ expect(client.data[:instance_updates].count).to eq(environment.servers.count)
87
+ expect(client.data[:instance_updates].values.map { |iu| iu["data"]["type"] }).to eq(["custom"] * environment.servers.count)
88
+ end
89
+ end
90
+
73
91
  it "destroys an environment" do
74
92
  expect {
75
93
  environment.destroy.ready!
@@ -19,6 +19,14 @@ describe 'servers' do
19
19
  expect(reboot_request.successful).to be true
20
20
  end
21
21
 
22
+ it "applies" do
23
+ expect(server.apply.ready!).to be_successful
24
+
25
+ if Ey::Core::Client.mocking?
26
+ expect(client.data[:instance_updates].count).to eq(1)
27
+ end
28
+ end
29
+
22
30
  it "does not destroy" do
23
31
  expect {
24
32
  server.destroy
@@ -7,13 +7,31 @@ describe 'tokens' do
7
7
  context "with a user" do
8
8
  let!(:user) { client.users.create!(name: Faker::Name.name, email: Faker::Internet.email) }
9
9
 
10
- it "should generate a token" do
10
+ it "generates a token" do
11
11
  token = client.tokens.create!(on_behalf_of: user)
12
12
  expect(token.auth_id).not_to be_nil
13
13
  end
14
14
 
15
- # other endpoint: upgrade, which takes a limited token and upgrades to full_access.
15
+ it "lists tokens" do
16
+ tokens = user.tokens.all
17
+ expect(tokens).not_to be_empty
18
+ end
19
+
20
+ it "gets a token" do
21
+ token = user.tokens.first
22
+ expect(token.reload).to be
23
+ end
16
24
 
25
+ context "with multiple users" do
26
+ let!(:other_user) { client.users.create(name: Faker::Name.name, email: Faker::Internet.email) }
27
+
28
+ it "only shows the correct tokens" do
29
+ expect(user.tokens.all.count).to eq(1)
30
+ expect(other_user.tokens.all.count).to eq(1)
31
+ expect(user.tokens.first.on_behalf_of).to eq(client.url_for("/users/#{user.identity}"))
32
+ expect(other_user.tokens.first.on_behalf_of).to eq(client.url_for("/users/#{other_user.identity}"))
33
+ end
34
+ end
17
35
  end
18
36
  end
19
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ey-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-11 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -252,6 +252,8 @@ files:
252
252
  - lib/ey-core/models/volume.rb
253
253
  - lib/ey-core/request.rb
254
254
  - lib/ey-core/request_failure.rb
255
+ - lib/ey-core/requests/apply_environment_updates.rb
256
+ - lib/ey-core/requests/apply_server_updates.rb
255
257
  - lib/ey-core/requests/attach_address.rb
256
258
  - lib/ey-core/requests/authorized_channel.rb
257
259
  - lib/ey-core/requests/boot_environment.rb
@@ -406,6 +408,8 @@ files:
406
408
  - lib/ey-core/requests/get_support_trial.rb
407
409
  - lib/ey-core/requests/get_task.rb
408
410
  - lib/ey-core/requests/get_tasks.rb
411
+ - lib/ey-core/requests/get_token.rb
412
+ - lib/ey-core/requests/get_tokens.rb
409
413
  - lib/ey-core/requests/get_untracked_server.rb
410
414
  - lib/ey-core/requests/get_untracked_servers.rb
411
415
  - lib/ey-core/requests/get_user.rb