Class: Hcloud::SSHKeyResource
Instance Attribute Summary
#base_path, #client, #parent
Instance Method Summary
collapse
#each, #initialize, #limit, #mj, #order, #page, #per_page
Instance Method Details
#[](arg) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/hcloud/ssh_key_resource.rb', line 30
def [](arg)
case arg
when Integer
begin
find(arg)
rescue Error::NotFound
end
when String
find_by(name: arg)
end
end
|
#all ⇒ Object
3
4
5
6
7
|
# File 'lib/hcloud/ssh_key_resource.rb', line 3
def all
mj("ssh_keys") do |j|
j.flat_map{|x| x["ssh_keys"].map{ |x| SSHKey.new(x, self, client) } }
end
end
|
#create(name:, public_key:) ⇒ Object
9
10
11
12
|
# File 'lib/hcloud/ssh_key_resource.rb', line 9
def create(name:, public_key:)
j = Oj.load(request("ssh_keys", j: {name: name, public_key: public_key}).run.body)
SSHKey.new(j["ssh_key"], self, client)
end
|
#find(id) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/hcloud/ssh_key_resource.rb', line 14
def find(id)
SSHKey.new(
Oj.load(request("ssh_keys/#{id}").run.body)["ssh_key"],
self,
client
)
end
|
#find_by(name:) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/hcloud/ssh_key_resource.rb', line 22
def find_by(name:)
x = Oj.load(request("ssh_keys", q: {name: name}).run.body)["ssh_keys"]
return nil if x.none?
x.each do |s|
return SSHKey.new(s, self, client)
end
end
|