2012-02-10 10:10:49 -05:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Joyent
|
|
|
|
class Mock
|
|
|
|
#
|
|
|
|
# https://us-west-1.api.joyentcloud.com/docs#CreateKey
|
|
|
|
#
|
|
|
|
def create_key(params)
|
|
|
|
name = params[:name]
|
|
|
|
key = params[:key]
|
2012-02-21 04:29:36 -05:00
|
|
|
|
2012-02-10 10:10:49 -05:00
|
|
|
record = {
|
|
|
|
"name" => name,
|
|
|
|
"key" => key,
|
2012-02-21 04:29:36 -05:00
|
|
|
"created" => Time.now.utc,
|
|
|
|
"updated" => Time.now.utc
|
2012-02-10 10:10:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
self.data[:keys][name] = record
|
|
|
|
|
|
|
|
response = Excon::Response.new
|
|
|
|
response.status = 201
|
|
|
|
response.body = record
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end # Mock
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
# Creates a new SSH Key
|
|
|
|
# ==== Parameters
|
|
|
|
# * name<~String> - Name to assign to this key
|
|
|
|
# * key<~String> - OpenSSH formatted public key
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'name'<~String> - Name for this key
|
|
|
|
# * 'key'<~String> - OpenSSH formatted public key
|
|
|
|
#
|
|
|
|
def create_key(params={})
|
|
|
|
raise ArgumentError, "error creating key: [name] is required" unless params[:name]
|
|
|
|
raise ArgumentError, "error creating key: [key] is required" unless params[:key]
|
|
|
|
|
|
|
|
request(
|
|
|
|
:method => "POST",
|
|
|
|
:path => "/my/keys",
|
2012-02-21 04:29:36 -05:00
|
|
|
:body => { "name" => params[:name], "key" => params[:key] },
|
2012-02-10 10:10:49 -05:00
|
|
|
:expects => 201
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|