-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fog#3500 from tnn2/glesys_sshkeys
[GleSYS] add support for SSH key management
- Loading branch information
Showing
8 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Fog | ||
module Compute | ||
class Glesys | ||
class SshKey < Fog::Model | ||
identity :id | ||
|
||
attribute :description | ||
attribute :data | ||
|
||
def save | ||
requires :description, :data | ||
|
||
merge_attributes(service.ssh_key_add(:description => description, | ||
:sshkey => data | ||
).body["response"]["sshkey"]) | ||
true | ||
end | ||
|
||
def destroy | ||
requires :id | ||
|
||
service.ssh_key_remove(:sshkeyids => id) | ||
true | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "fog/glesys/models/compute/ssh_key" | ||
|
||
module Fog | ||
module Compute | ||
class Glesys | ||
class SshKeys < Fog::Collection | ||
model Fog::Compute::Glesys::SshKey | ||
|
||
def all | ||
data = service.ssh_key_list.body["response"]["sshkeys"] | ||
load(data) | ||
end | ||
|
||
def get(id) | ||
hash = service.ssh_key_list.body["response"]["sshkeys"].find{|a| a["id"] == id} | ||
hash.nil? ? nil : new(hash) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Fog | ||
module Compute | ||
class Glesys | ||
class Real | ||
def ssh_key_add(options) | ||
request("sshkey/add", options) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Fog | ||
module Compute | ||
class Glesys | ||
class Real | ||
def ssh_key_list(options = {}) | ||
request("sshkey/list", options) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Fog | ||
module Compute | ||
class Glesys | ||
class Real | ||
def ssh_key_remove(options) | ||
request("sshkey/remove", options) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Shindo.tests("Fog::Compute[:glesys] | ssh_key requests", ["glesys", "compute"]) do | ||
@testdescription = "My test key to be removed" | ||
@testdata = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDv+r/dCIDv+YazWsyc1WCixR+iOeaswTx1U45h6vh4/ fog-unittest@GleSYS" | ||
@testdata_malformed = "ssh-rot13 AAAAthis_is_not_an_ssh_key fog-unittest@GleSYS" | ||
|
||
tests("success") do | ||
tests("#ssh_key_add").formats(Glesys::Compute::Formats::SshKeys::ADD) do | ||
pending if Fog.mocking? | ||
@resp = Fog::Compute[:glesys].ssh_key_add(:description => @testdescription, :sshkey => @testdata) | ||
@resp.body["response"] | ||
end | ||
|
||
unless Fog.mocking? | ||
Fog::Compute[:glesys].ssh_keys.destroy(@resp.body["response"]["sshkey"]["id"]) | ||
@key = Fog::Compute[:glesys].ssh_keys.create(:description => @testdescription, :data => @testdata) | ||
end | ||
|
||
tests("#ssh_key_list").formats(Glesys::Compute::Formats::SshKeys::LIST) do | ||
pending if Fog.mocking? | ||
@resp = Fog::Compute[:glesys].ssh_key_list | ||
@resp.body["response"] | ||
end | ||
|
||
unless Fog.mocking? | ||
Fog::Compute[:glesys].ssh_keys.destroy(@key.id) | ||
@key = Fog::Compute[:glesys].ssh_keys.create(:description => @testdescription, :data => @testdata) | ||
end | ||
|
||
tests("#ssh_key_remove").formats(Glesys::Compute::Formats::SshKeys::REMOVE) do | ||
pending if Fog.mocking? | ||
@resp = Fog::Compute[:glesys].ssh_key_remove(:sshkeyids => @key.id) | ||
@resp.body["response"] | ||
end | ||
end | ||
|
||
tests("failure") do | ||
tests("#ssh_key_add with malformed key data").raises(Excon::Errors::HTTPStatusError) do | ||
pending if Fog.mocking? | ||
Fog::Compute[:glesys].ssh_key_add(:description => @testdescription, :data => @testdata_malformed) | ||
end | ||
|
||
tests("#ssh_key_remove with nonexistent/invalid key id").raises(Excon::Errors::HTTPStatusError) do | ||
pending if Fog.mocking? | ||
Fog::Compute[:glesys].ssh_key_remove(:id => -1) | ||
end | ||
end | ||
end |