fog-ecloud 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fog/compute/ecloud.rb +12 -1
- data/lib/fog/compute/ecloud/models/ssh_key.rb +24 -0
- data/lib/fog/compute/ecloud/models/ssh_keys.rb +19 -3
- data/lib/fog/compute/ecloud/requests/get_ssh_key.rb +1 -1
- data/lib/fog/compute/ecloud/requests/ssh_key_create.rb +77 -0
- data/lib/fog/compute/ecloud/requests/ssh_key_delete.rb +18 -0
- data/lib/fog/compute/ecloud/requests/ssh_key_edit.rb +43 -0
- data/lib/fog/ecloud/version.rb +1 -1
- data/tests/compute/models/ssh_key_tests.rb +31 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46a64b15ab3ff353edc6229933d67550309b34d7
|
4
|
+
data.tar.gz: b681e30075993fd7082e217c3b7e2fb6d7e6dc99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6dcd86fb9737e4c468698f515957f1861ca438d588c4b0f94ac06815f7e3ff733a2d28bd44711d5562c521765ed9040bdd187d477a0718b7bc75d3a72fe7337
|
7
|
+
data.tar.gz: 7d23e7506ae33631fbd4680916dd23d0d56ded1f7e0b51f14bc6617e9c7778464879c059f85c8bead278b09d3d902135141fc4d81d0692905efd908161b4f25a
|
data/lib/fog/compute/ecloud.rb
CHANGED
@@ -229,6 +229,9 @@ module Fog
|
|
229
229
|
request :rows_edit
|
230
230
|
request :rows_movedown
|
231
231
|
request :rows_moveup
|
232
|
+
request :ssh_key_create
|
233
|
+
request :ssh_key_delete
|
234
|
+
request :ssh_key_edit
|
232
235
|
request :trusted_network_groups_create
|
233
236
|
request :trusted_network_groups_delete
|
234
237
|
request :trusted_network_groups_edit
|
@@ -287,7 +290,7 @@ module Fog
|
|
287
290
|
@connection_options = options[:connection_options] || {}
|
288
291
|
@host = options[:ecloud_host] || API_URL
|
289
292
|
@persistent = options[:persistent] || false
|
290
|
-
@version = options[:ecloud_version] || "
|
293
|
+
@version = options[:ecloud_version] || "2015-05-01"
|
291
294
|
@authentication_method = options[:ecloud_authentication_method] || :cloud_api_auth
|
292
295
|
@access_key = options[:ecloud_access_key]
|
293
296
|
@private_key = options[:ecloud_private_key]
|
@@ -352,10 +355,18 @@ module Fog
|
|
352
355
|
|
353
356
|
# if Authorization and x-tmrk-authorization are used, the x-tmrk-authorization takes precendence.
|
354
357
|
def set_extra_headers_for(params)
|
358
|
+
length_required = ["PUT", "POST", "DELETE"]
|
355
359
|
params[:headers] = {
|
356
360
|
"x-tmrk-version" => @version,
|
357
361
|
"Date" => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S GMT"),
|
358
362
|
}.merge(params[:headers] || {})
|
363
|
+
if length_required.include?(params[:method]) && !params[:headers]["Content-Length"]
|
364
|
+
body_size = 0
|
365
|
+
if params[:body]
|
366
|
+
body_size = params[:body].size
|
367
|
+
end
|
368
|
+
params[:headers].merge!("Content-Length" => body_size)
|
369
|
+
end
|
359
370
|
if params[:method] == "POST" || params[:method] == "PUT"
|
360
371
|
params[:headers].merge!("Content-Type" => "application/xml") unless params[:headers]["Content-Type"]
|
361
372
|
params[:headers].merge!("Accept" => "application/xml")
|
@@ -9,6 +9,30 @@ module Fog
|
|
9
9
|
attribute :other_links, :aliases => :Links
|
10
10
|
attribute :default, :aliases => :Default, :type => :boolean
|
11
11
|
attribute :finger_print, :aliases => :FingerPrint
|
12
|
+
attribute :private_key, :aliases => :PrivateKey
|
13
|
+
|
14
|
+
def delete
|
15
|
+
service.ssh_key_delete(href).body
|
16
|
+
end
|
17
|
+
alias_method :destroy, :delete
|
18
|
+
|
19
|
+
def edit(options = {})
|
20
|
+
# Make sure we only pass what we should
|
21
|
+
new_options = {}
|
22
|
+
new_options[:uri] = href
|
23
|
+
if options[:Name].nil?
|
24
|
+
new_options[:Name] = name
|
25
|
+
else
|
26
|
+
new_options[:Name] = options[:Name]
|
27
|
+
end
|
28
|
+
if options[:Default].nil?
|
29
|
+
new_options[:Default] = default
|
30
|
+
else
|
31
|
+
new_options[:Default] = options[:Default]
|
32
|
+
end
|
33
|
+
|
34
|
+
service.ssh_key_edit(new_options)
|
35
|
+
end
|
12
36
|
|
13
37
|
def id
|
14
38
|
href.scan(/\d+/)[0]
|
@@ -14,12 +14,28 @@ module Fog
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def get(uri)
|
17
|
-
if data = service.get_ssh_key(uri)
|
18
|
-
new(data
|
17
|
+
if data = service.get_ssh_key(uri).body
|
18
|
+
new(data)
|
19
19
|
end
|
20
|
-
rescue
|
20
|
+
rescue Excon::Errors::NotFound
|
21
21
|
nil
|
22
22
|
end
|
23
|
+
|
24
|
+
def create(options = {})
|
25
|
+
# Make sure we only pass what we should
|
26
|
+
new_options = {}
|
27
|
+
new_options[:Name] = options[:Name] unless options[:Name].nil?
|
28
|
+
new_options[:Default] = options[:Default] || false
|
29
|
+
new_options[:uri] = href + "/action/createSshKey"
|
30
|
+
|
31
|
+
data = service.ssh_key_create(new_options)
|
32
|
+
object = service.ssh_keys.new(data)
|
33
|
+
object
|
34
|
+
end
|
35
|
+
|
36
|
+
def environment_id
|
37
|
+
href.scan(/\d+/)[0]
|
38
|
+
end
|
23
39
|
end
|
24
40
|
end
|
25
41
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Ecloud
|
4
|
+
class Real
|
5
|
+
include Shared
|
6
|
+
|
7
|
+
def ssh_key_create(data)
|
8
|
+
validate_data([:Name], data)
|
9
|
+
|
10
|
+
request(
|
11
|
+
:body => generate_ssh_key_create_request(data),
|
12
|
+
:expects => 201,
|
13
|
+
:method => "POST",
|
14
|
+
:headers => {},
|
15
|
+
:uri => data[:uri],
|
16
|
+
:parse => true
|
17
|
+
).body
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_ssh_key_create_request(data)
|
23
|
+
xml = Builder::XmlMarkup.new
|
24
|
+
xml.CreateSshKey(:name => data[:Name]) do
|
25
|
+
xml.Default data[:Default]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Mock
|
31
|
+
include Shared
|
32
|
+
|
33
|
+
def ssh_key_create(data)
|
34
|
+
validate_data([:Name], data)
|
35
|
+
ssh_key_id = Fog::Mock.random_numbers(7).to_i
|
36
|
+
ssh_key_fingerprint = ""
|
37
|
+
(1..15).each do
|
38
|
+
ssh_key_fingerprint = ssh_key_fingerprint + Fog::Mock.random_hex(2) + ":"
|
39
|
+
end
|
40
|
+
ssh_key_fingerprint = ssh_key_fingerprint + Fog::Mock.random_hex(2)
|
41
|
+
ssh_private_key = Fog::Mock.random_base64(512)
|
42
|
+
org_id = self.data[:organization_id]
|
43
|
+
org_name = self.data[:organization_name]
|
44
|
+
|
45
|
+
ssh_key = {
|
46
|
+
:href => "/cloudapi/ecloud/admin/sshKeys/#{ssh_key_id}",
|
47
|
+
:Name => data[:Name],
|
48
|
+
:type => "application/vnd.tmrk.cloud.admin.sshKey",
|
49
|
+
:Links => {
|
50
|
+
:Link => {
|
51
|
+
:href => "/cloudapi/ecloud/admin/organizations/#{org_id}",
|
52
|
+
:name => org_name,
|
53
|
+
:type => "application/vnd.tmrk.cloud.admin.organization",
|
54
|
+
:rel => "up",
|
55
|
+
},
|
56
|
+
:Link => {
|
57
|
+
:href => "/cloudapi/ecloud/organizations/#{org_id}",
|
58
|
+
:name => org_name,
|
59
|
+
:type => "application/vnd.tmrk.cloud.organization",
|
60
|
+
:rel => "up",
|
61
|
+
},
|
62
|
+
},
|
63
|
+
:Default => data[:Default] || false,
|
64
|
+
:FingerPrint => ssh_key_fingerprint,
|
65
|
+
:PrivateKey => ssh_private_key,
|
66
|
+
}
|
67
|
+
|
68
|
+
ssh_key_response = response(:body => ssh_key)
|
69
|
+
|
70
|
+
self.data[:ssh_keys][ssh_key_id] = ssh_key
|
71
|
+
|
72
|
+
ssh_key_response.body
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Ecloud
|
4
|
+
class Real
|
5
|
+
basic_request :ssh_key_delete, 204, "DELETE"
|
6
|
+
end
|
7
|
+
|
8
|
+
class Mock
|
9
|
+
def ssh_key_delete(uri)
|
10
|
+
ssh_key_id = id_from_uri(uri)
|
11
|
+
|
12
|
+
data[:ssh_keys].delete(ssh_key_id)
|
13
|
+
response(:body => nil, :status => 204)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Ecloud
|
4
|
+
class Real
|
5
|
+
include Shared
|
6
|
+
|
7
|
+
def ssh_key_edit(data)
|
8
|
+
request(
|
9
|
+
:body => generate_ssh_key_edit_request(data),
|
10
|
+
:expects => 200,
|
11
|
+
:method => "PUT",
|
12
|
+
:headers => {},
|
13
|
+
:uri => data[:uri],
|
14
|
+
:parse => true
|
15
|
+
).body
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generate_ssh_key_edit_request(data)
|
21
|
+
xml = Builder::XmlMarkup.new
|
22
|
+
xml.SshKey(:name => data[:Name]) do
|
23
|
+
xml.Default data[:Default]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Mock
|
29
|
+
def ssh_key_edit(options)
|
30
|
+
ssh_key_id = id_from_uri(options[:uri]).to_i
|
31
|
+
if data[:ssh_keys][ssh_key_id]
|
32
|
+
data[:ssh_keys][ssh_key_id][:Name] = options[:Name]
|
33
|
+
data[:ssh_keys][ssh_key_id][:Default] = options[:Default]
|
34
|
+
ssh_key = data[:ssh_keys][ssh_key_id]
|
35
|
+
response(:body => Fog::Ecloud.slice(ssh_key, :id, :admin_organization)).body
|
36
|
+
else
|
37
|
+
response(:expects => 200, :status => 404)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/fog/ecloud/version.rb
CHANGED
@@ -7,13 +7,42 @@ Shindo.tests("Fog::Compute[:#{provider}] | ssh_keys", [provider.to_s]) do
|
|
7
7
|
@admin_organization.reload
|
8
8
|
@ssh_keys = @admin_organization.ssh_keys
|
9
9
|
|
10
|
-
tests(
|
10
|
+
tests("#all").succeeds do
|
11
11
|
returns(false) { @ssh_keys.empty? }
|
12
12
|
end
|
13
13
|
|
14
|
-
tests(
|
14
|
+
tests("#get").succeeds do
|
15
15
|
ssh_key = @ssh_keys.first
|
16
16
|
|
17
17
|
returns(false) { @ssh_keys.get(ssh_key.href).nil? }
|
18
|
+
returns(false) { @ssh_keys.get("/notfound" + ssh_key.href).nil? }
|
19
|
+
end
|
20
|
+
|
21
|
+
tests("#create").succeeds do
|
22
|
+
new_key = @ssh_keys.create(:Name => "testing")
|
23
|
+
@key_id = new_key.id || nil
|
24
|
+
returns(false) { new_key.nil? }
|
25
|
+
raises(ArgumentError) { @ssh_keys.create }
|
26
|
+
end
|
27
|
+
|
28
|
+
tests("#edit").succeeds do
|
29
|
+
the_key = @ssh_keys.get(@key_id)
|
30
|
+
returns(false) { the_key.nil? }
|
31
|
+
|
32
|
+
the_key.edit(:Name => "more testing")
|
33
|
+
the_key.reload
|
34
|
+
returns(false) { the_key.name != "more testing" }
|
35
|
+
|
36
|
+
the_key.edit(:Default => true)
|
37
|
+
the_key.reload
|
38
|
+
returns(true) { the_key.default }
|
39
|
+
end
|
40
|
+
|
41
|
+
tests("#delete").succeeds do
|
42
|
+
the_key = @ssh_keys.get(@key_id)
|
43
|
+
returns(false) { the_key.nil? }
|
44
|
+
the_key.delete
|
45
|
+
the_key = @ssh_keys.get(@key_id)
|
46
|
+
returns(false) { !the_key.nil? }
|
18
47
|
end
|
19
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-ecloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Henrique Lopes Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-core
|
@@ -382,6 +382,9 @@ files:
|
|
382
382
|
- lib/fog/compute/ecloud/requests/rows_edit.rb
|
383
383
|
- lib/fog/compute/ecloud/requests/rows_movedown.rb
|
384
384
|
- lib/fog/compute/ecloud/requests/rows_moveup.rb
|
385
|
+
- lib/fog/compute/ecloud/requests/ssh_key_create.rb
|
386
|
+
- lib/fog/compute/ecloud/requests/ssh_key_delete.rb
|
387
|
+
- lib/fog/compute/ecloud/requests/ssh_key_edit.rb
|
385
388
|
- lib/fog/compute/ecloud/requests/trusted_network_groups_create.rb
|
386
389
|
- lib/fog/compute/ecloud/requests/trusted_network_groups_delete.rb
|
387
390
|
- lib/fog/compute/ecloud/requests/trusted_network_groups_edit.rb
|