1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[GleSYS] add support for SSH key management

This commit is contained in:
Tobias Nygren 2015-03-26 09:43:51 +01:00
parent f16fae7b0b
commit 8150e0f1d7
8 changed files with 189 additions and 0 deletions

View file

@ -14,6 +14,8 @@ module Fog
model :template
collection :ips
model :ip
collection :ssh_keys
model :ssh_key
request_path 'fog/glesys/requests/compute'
@ -40,6 +42,11 @@ module Fog
request :ip_add
request :ip_remove
# SSH keys
request :ssh_key_list
request :ssh_key_add
request :ssh_key_remove
class Mock
def initialize(options={})
@api_url = options[:glesys_api_url] || API_URL

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -240,6 +240,59 @@ class Glesys
}
}
end
module SshKeys
ADD = {
'debug' => {
'input' => {
'sshkey' => String,
'description' => String
}
},
'sshkey' => {
'id' => Integer,
'account' => String,
'description' => String,
'data' => String
},
'status' => {
'timestamp' => String,
'code' => Integer,
'text' => String,
'transactionid' => Fog::Nullable::String
}
}
REMOVE = {
'debug' => {
'input' => {
'sshkeyids' => String,
}
},
'status' => {
'timestamp' => String,
'code' => Integer,
'text' => String,
'transactionid' => Fog::Nullable::String
}
}
LIST = {
'debug' => {
'input' => []
},
'sshkeys' => [
{
'id' => Integer,
'account' => String,
'description' => String,
'data' => String,
}
],
'status' => {
'timestamp' => String,
'code' => Integer,
'text' => String
}
}
end
module Templates
LIST = {
'debug' => {

View file

@ -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