Class: Cabal::API::ClusterService

Inherits:
Object
  • Object
show all
Defined in:
lib/cabal/api/cluster_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_warehouse: STORAGE[:public], private_warehouse: STORAGE[:private]) ⇒ ClusterService

Returns a new instance of ClusterService.



11
12
13
14
15
# File 'lib/cabal/api/cluster_service.rb', line 11

def initialize(public_warehouse: STORAGE[:public], private_warehouse: STORAGE[:private])
  @public_keys = Sekrat.manager(warehouse: public_warehouse)

  @private_keys = Sekrat.manager(warehouse: private_warehouse, crypter: Sekrat::Crypter::Aes)
end

Instance Attribute Details

#private_keysObject

Returns the value of attribute private_keys.



9
10
11
# File 'lib/cabal/api/cluster_service.rb', line 9

def private_keys
  @private_keys
end

#public_keysObject

Returns the value of attribute public_keys.



9
10
11
# File 'lib/cabal/api/cluster_service.rb', line 9

def public_keys
  @public_keys
end

Instance Method Details

#create(name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/cabal/api/cluster_service.rb', line 17

def create(name)
  sshkey = SSHKey.generate(
    type: 'RSA',
    bits: 2048,
    comment: "#{name}-cabal"
  )

  write_public_key(name, sshkey) && write_private_key(name, sshkey)
end

#namesObject



27
28
29
# File 'lib/cabal/api/cluster_service.rb', line 27

def names
  public_keys.ids
end

#private_key(name) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/cabal/api/cluster_service.rb', line 39

def private_key(name)
  begin
    private_keys.get(name, public_key(name))
  rescue
    nil
  end
end

#public_key(name) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/cabal/api/cluster_service.rb', line 31

def public_key(name)
  begin
    public_keys.get(name, name)
  rescue
    nil
  end
end