Browse Source

Handle correctly missing port

master
Aeris 3 years ago
parent
commit
66fc57c4d8
4 changed files with 16 additions and 11 deletions
  1. 2
    2
      app/controllers/check_controller.rb
  2. 1
    2
      app/workers/check_worker.rb
  3. 1
    1
      app/workers/ssh_worker.rb
  4. 12
    6
      lib/datastore.rb

+ 2
- 2
app/controllers/check_controller.rb View File

@@ -23,7 +23,7 @@ class CheckController < ApplicationController

protected
def enqueue_host
Datastore.pending self.type, @id
Datastore.pending self.type, @id, @port
self.worker.perform_async *(@port.blank? ? [@host] : [@host, @port])
@result = OpenStruct.new pending: true , date: Time.now
end
@@ -37,6 +37,6 @@ class CheckController < ApplicationController
redirect_to action: :index
return false
end
@result = Datastore.host self.type, @id
@result = Datastore.host self.type, @host, @port
end
end

+ 1
- 2
app/workers/check_worker.rb View File

@@ -35,8 +35,7 @@ class CheckWorker
rescue CryptCheck::Tls::Server::TLSNotAvailableException
{ no_tls: true }
end
host = "#{host}:#{port}" if port
Datastore.post self.type, host, result
Datastore.post self.type, host, port, result
end

protected

+ 1
- 1
app/workers/ssh_worker.rb View File

@@ -16,6 +16,6 @@ class SSHWorker
rescue CryptCheck::Ssh::Server::SshNotAvailableException
{ no_tls: true }
end
Datastore.post :ssh, "#{host}:#{port}", result
Datastore.post :ssh, host, port, result
end
end

+ 12
- 6
lib/datastore.rb View File

@@ -2,19 +2,25 @@ class Datastore
@@index = Stretcher::Server.new(ENV['ES_URL']).index :cryptcheck
@@index.create unless @@index.exists?

def self.host(type, name)
result = @@index.type(type).get name
def self.host(type, host, port)
result = @@index.type(type).get self.key(host, port)
result.date = Time.parse result.date
result
rescue Stretcher::RequestError::NotFound
end

def self.pending(type, name)
self.post type, name, { pending: true }
def self.pending(type, host, port)
self.post type, host, port, { pending: true }
end

def self.post(type, name, data)
def self.post(type, host, port, data)
data[:date] = DateTime.now
@@index.type(type).put name, data
@@index.type(type).put self.key(host, port), data
end

private
def self.key(host, port)
host = "#{host}:#{port}" if port
host
end
end

Loading…
Cancel
Save