hetzner-k3s 0.5.0 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hetzner
2
4
  class SSHKey
3
5
  def initialize(hetzner_client:, cluster_name:)
@@ -11,34 +13,34 @@ module Hetzner
11
13
  puts
12
14
 
13
15
  if (public_ssh_key = find_public_ssh_key)
14
- puts "SSH key already exists, skipping."
16
+ puts 'SSH key already exists, skipping.'
15
17
  puts
16
- return public_ssh_key["id"]
18
+ return public_ssh_key['id']
17
19
  end
18
20
 
19
- puts "Creating SSH key..."
21
+ puts 'Creating SSH key...'
20
22
 
21
- response = hetzner_client.post("/ssh_keys", ssh_key_config).body
23
+ response = hetzner_client.post('/ssh_keys', ssh_key_config).body
22
24
 
23
- puts "...SSH key created."
25
+ puts '...SSH key created.'
24
26
  puts
25
27
 
26
- JSON.parse(response)["ssh_key"]["id"]
28
+ JSON.parse(response)['ssh_key']['id']
27
29
  end
28
30
 
29
31
  def delete(public_ssh_key_path:)
30
32
  @public_ssh_key_path = public_ssh_key_path
31
33
 
32
34
  if (public_ssh_key = find_public_ssh_key)
33
- if public_ssh_key["name"] == cluster_name
34
- puts "Deleting ssh_key..."
35
- hetzner_client.delete("/ssh_keys", public_ssh_key["id"])
36
- puts "...ssh_key deleted."
35
+ if public_ssh_key['name'] == cluster_name
36
+ puts 'Deleting ssh_key...'
37
+ hetzner_client.delete('/ssh_keys', public_ssh_key['id'])
38
+ puts '...ssh_key deleted.'
37
39
  else
38
40
  puts "The SSH key existed before creating the cluster, so I won't delete it."
39
41
  end
40
42
  else
41
- puts "SSH key no longer exists, skipping."
43
+ puts 'SSH key no longer exists, skipping.'
42
44
  end
43
45
 
44
46
  puts
@@ -46,36 +48,33 @@ module Hetzner
46
48
 
47
49
  private
48
50
 
49
- attr_reader :hetzner_client, :cluster_name, :public_ssh_key_path
50
-
51
- def public_ssh_key
52
- @public_ssh_key ||= File.read(public_ssh_key_path).chop
53
- end
51
+ attr_reader :hetzner_client, :cluster_name, :public_ssh_key_path
54
52
 
55
- def ssh_key_config
56
- {
57
- name: cluster_name,
58
- public_key: public_ssh_key
59
- }
60
- end
53
+ def public_ssh_key
54
+ @public_ssh_key ||= File.read(public_ssh_key_path).chop
55
+ end
61
56
 
62
- def fingerprint
63
- @fingerprint ||= ::SSHKey.fingerprint(public_ssh_key)
64
- end
57
+ def ssh_key_config
58
+ {
59
+ name: cluster_name,
60
+ public_key: public_ssh_key
61
+ }
62
+ end
65
63
 
66
- def find_public_ssh_key
67
- key = hetzner_client.get("/ssh_keys")["ssh_keys"].detect do |ssh_key|
68
- ssh_key["fingerprint"] == fingerprint
69
- end
64
+ def fingerprint
65
+ @fingerprint ||= ::SSHKey.fingerprint(public_ssh_key)
66
+ end
70
67
 
71
- unless key
72
- key = hetzner_client.get("/ssh_keys")["ssh_keys"].detect do |ssh_key|
73
- ssh_key["name"] == cluster_name
74
- end
75
- end
68
+ def find_public_ssh_key
69
+ key = hetzner_client.get('/ssh_keys')['ssh_keys'].detect do |ssh_key|
70
+ ssh_key['fingerprint'] == fingerprint
71
+ end
76
72
 
77
- key
73
+ key ||= hetzner_client.get('/ssh_keys')['ssh_keys'].detect do |ssh_key|
74
+ ssh_key['name'] == cluster_name
78
75
  end
79
76
 
77
+ key
78
+ end
80
79
  end
81
80
  end
data/lib/hetzner/infra.rb CHANGED
@@ -1,2 +1,6 @@
1
- module Hetzner::Infra
1
+ # frozen_string_literal: true
2
+
3
+ module Hetzner
4
+ module Infra
5
+ end
2
6
  end