fixed some things with hashing the paste method and sending data to es

This commit is contained in:
booboy 2019-02-01 20:38:14 -06:00
parent 107c1ff559
commit ba20e8dc41

View file

@ -130,10 +130,10 @@ class Pastebinner
##### PREPARING THE PASTES FOR SERIALIZATION FOR ES CONFORMING TO PER INDEX SEARCHING ##### PREPARING THE PASTES FOR SERIALIZATION FOR ES CONFORMING TO PER INDEX SEARCHING
##### SEE - https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_custom_type_field ##### SEE - https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html#_custom_type_field
def puts_to_es(es_uri, payload) def http_to_es(es_uri, payload, method)
header = { 'Content-type': 'application/json' } header = { 'Content-type': 'application/json' }
response = RestClient::Request.execute( response = RestClient::Request.execute(
method: :put, method: method,
url: es_uri, url: es_uri,
headers: header, headers: header,
payload: payload) payload: payload)
@ -145,31 +145,23 @@ class Pastebinner
url: es_uri + index) url: es_uri + index)
end end
def hash_pastes(keys, pb) def hash_pastes(keys)
keys.map do |key| keys.map do |key|
raw_paste = pb.raw_paste_data(key).body raw_paste = self.raw_paste_data(key).body
raw_paste_metadata = pb.raw_paste_metadata(key).body raw_paste_metadata = self.raw_paste_metadata(key).body
hash = pb.hash_paste(raw_paste, raw_paste_metadata) hash = self.hash_paste(raw_paste, raw_paste_metadata)
end end
end end
def hash_paste(raw_paste, raw_paste_metadata) def hash_paste(raw_paste_data, raw_paste_metadata)
{ "paste_metadata": raw_paste_metadata, { "paste_metadata": raw_paste_metadata,
"paste_text": raw_paste } "paste_text": raw_paste_data }
end
def post_to_es(es_uri, payload)
header = { 'Content-type': 'application/json' }
response = RestClient::Request.execute(
method: :post,
url: es_uri,
headers: header,
payload: payload)
end end
def send_es_bulk(esi_uri, json_data) def send_es_bulk(esi_uri, json_data)
json_data.each do |data| method = :post
self.post_to_es(esi_uri, data) json_data.each do |payload|
self.http_to_es(esi_uri, payload, method)
end end
end end