瀏覽代碼

Handle correctly missing port

master
Aeris 3 年之前
父節點
當前提交
66fc57c4d8
共有 4 個檔案被更改,包括 16 行新增11 行删除
  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 查看文件

@@ -23,7 +23,7 @@ class CheckController < ApplicationController
23 23
 
24 24
 	protected
25 25
 	def enqueue_host
26
-		Datastore.pending self.type, @id
26
+		Datastore.pending self.type, @id, @port
27 27
 		self.worker.perform_async *(@port.blank? ? [@host] : [@host, @port])
28 28
 		@result = OpenStruct.new pending: true , date: Time.now
29 29
 	end
@@ -37,6 +37,6 @@ class CheckController < ApplicationController
37 37
 			redirect_to action: :index
38 38
 			return false
39 39
 		end
40
-		@result = Datastore.host self.type, @id
40
+		@result = Datastore.host self.type, @host, @port
41 41
 	end
42 42
 end

+ 1
- 2
app/workers/check_worker.rb 查看文件

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

+ 1
- 1
app/workers/ssh_worker.rb 查看文件

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

+ 12
- 6
lib/datastore.rb 查看文件

@@ -2,19 +2,25 @@ class Datastore
2 2
 	@@index = Stretcher::Server.new(ENV['ES_URL']).index :cryptcheck
3 3
 	@@index.create unless @@index.exists?
4 4
 
5
-	def self.host(type, name)
6
-		result = @@index.type(type).get name
5
+	def self.host(type, host, port)
6
+		result = @@index.type(type).get self.key(host, port)
7 7
 		result.date = Time.parse result.date
8 8
 		result
9 9
 	rescue Stretcher::RequestError::NotFound
10 10
 	end
11 11
 
12
-	def self.pending(type, name)
13
-		self.post type, name, { pending: true }
12
+	def self.pending(type, host, port)
13
+		self.post type, host, port, { pending: true }
14 14
 	end
15 15
 
16
-	def self.post(type, name, data)
16
+	def self.post(type, host, port, data)
17 17
 		data[:date] = DateTime.now
18
-		@@index.type(type).put name, data
18
+		@@index.type(type).put self.key(host, port), data
19
+	end
20
+
21
+	private
22
+	def self.key(host, port)
23
+		host = "#{host}:#{port}" if port
24
+		host
19 25
 	end
20 26
 end

Loading…
取消
儲存