Module: ForemanRemoteExecution::SmartProxyExtensions

Defined in:
app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



3
4
5
6
7
8
# File 'app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb', line 3

def self.prepended(base)
  base.instance_eval do
    has_many :host_proxy_invocations, :dependent => :destroy
    has_many :template_invocations, :dependent => :nullify
  end
end

Instance Method Details

#ca_pubkeyObject



14
15
16
# File 'app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb', line 14

def ca_pubkey
  self[:ca_pubkey] || update_ca_pubkey
end

#drop_host_from_known_hosts(host) ⇒ Object



35
36
37
# File 'app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb', line 35

def drop_host_from_known_hosts(host)
  ::ProxyAPI::RemoteExecutionSSH.new(:url => url).drop_from_known_hosts(host)
end

#pubkeyObject



10
11
12
# File 'app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb', line 10

def pubkey
  self[:pubkey] || update_pubkey
end

#refreshObject



39
40
41
42
43
44
# File 'app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb', line 39

def refresh
  errors = super
  update_pubkey
  update_ca_pubkey
  errors
end

#update_ca_pubkeyObject



26
27
28
29
30
31
32
33
# File 'app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb', line 26

def update_ca_pubkey
  return unless has_feature?(%w(SSH Script))

  # smart proxy is not required to have a CA pubkey, in which case an empty string is returned
  key = ::ProxyAPI::RemoteExecutionSSH.new(:url => url).ca_pubkey&.presence
  self.update_attribute(:ca_pubkey, key)
  key
end

#update_pubkeyObject



18
19
20
21
22
23
24
# File 'app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb', line 18

def update_pubkey
  return unless has_feature?(%w(SSH Script))

  key = ::ProxyAPI::RemoteExecutionSSH.new(:url => url).pubkey
  self.update_attribute(:pubkey, key) if key
  key
end