tigre-client 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +5 -1
- data/lib/tigre-client/analysis.rb +2 -0
- data/lib/tigre-client/sample.rb +77 -7
- data/lib/tigre-client/version.rb +1 -1
- data/lib/tigre-client.rb +17 -13
- data/tigre-client.gemspec +1 -0
- metadata +13 -2
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tigre-client (0.3.
|
4
|
+
tigre-client (0.3.8)
|
5
5
|
faraday (~> 0.6.0)
|
6
|
+
right_aws (~> 2.1.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
@@ -16,6 +17,9 @@ GEM
|
|
16
17
|
json (1.5.1)
|
17
18
|
multipart-post (1.1.0)
|
18
19
|
rack (1.2.2)
|
20
|
+
right_aws (2.1.0)
|
21
|
+
right_http_connection (>= 1.2.5)
|
22
|
+
right_http_connection (1.3.0)
|
19
23
|
rspec (2.5.0)
|
20
24
|
rspec-core (~> 2.5.0)
|
21
25
|
rspec-expectations (~> 2.5.0)
|
data/lib/tigre-client/sample.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
1
3
|
module Tigre
|
2
4
|
class Sample
|
3
5
|
|
@@ -6,24 +8,92 @@ module Tigre
|
|
6
8
|
extend Tigre::TagComponents
|
7
9
|
|
8
10
|
# required params
|
9
|
-
# file_location => String path to the file
|
10
11
|
# md5 => String
|
11
12
|
# optional params
|
13
|
+
# file_location => String path to the file
|
12
14
|
# options => Hash
|
13
15
|
# :tags => String => I.E 'foo'
|
14
16
|
# :tags => String (comma seperated) => I.E 'foo,bar,baz'
|
15
17
|
# :tags => Array => ['foo', 'bar', 'baz']
|
18
|
+
# :dbts => Hash {:key1 => value, :key2 => value} where the key is what the name of the
|
19
|
+
# attribute is and the value should be a boolean
|
20
|
+
# :mutex_name_list => String (comma seperated) => I.E 'foo,bar,baz'
|
21
|
+
# :mutex_name_list => Array => ['foo', 'bar', 'baz']
|
16
22
|
def self.post(file_location, md5, options={})
|
17
|
-
|
18
|
-
raise ArguementError, "File_location or md5 parameter cannot be empty"
|
19
|
-
end
|
23
|
+
raise "md5 parameter cannot be empty" if md5 == ''
|
20
24
|
|
21
25
|
options[:tags] = package_array_list(options[:tags]) if options[:tags]
|
22
26
|
|
23
|
-
post_data = {:
|
24
|
-
|
27
|
+
post_data = {:md5 => md5}
|
28
|
+
|
29
|
+
unless file_location == ''
|
30
|
+
if Tigre.s3_enabled?
|
31
|
+
process_after = true
|
32
|
+
else
|
33
|
+
post_data[:file] = File.new(file_location)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
post_data[:metadatas] = self.get_metadatas(options)
|
38
|
+
|
39
|
+
result = Tigre.post_connection('/samples', post_data.merge(options))
|
40
|
+
|
41
|
+
case
|
42
|
+
when result[1] == 'success_nofile' && process_after
|
43
|
+
result = self.send_file_to_s3(md5, file_location)
|
44
|
+
when result[1] == 'success' && process_after && options[:force]
|
45
|
+
result = self.send_file_to_s3(md5, file_location)
|
46
|
+
end
|
47
|
+
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.get_metadatas(options)
|
52
|
+
hash = {}
|
53
|
+
if options[:dbts]
|
54
|
+
hash[:dbts] = options[:dbts]
|
55
|
+
end
|
56
|
+
|
57
|
+
if options[:mutex_name_list]
|
58
|
+
hash[:mutex_name_list] = package_array_list(options[:mutex_name_list])
|
59
|
+
end
|
60
|
+
hash.empty? ? nil : hash
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.send_file_to_s3(md5, file)
|
64
|
+
Tigre.logger.info 'Uploading file directly to S3'
|
65
|
+
s3 = RightAws::S3.new(Tigre.s3_key, Tigre.s3_secret)
|
66
|
+
bucket = s3.bucket(Tigre.s3_bucket)
|
67
|
+
file_name = [md5[0],md5[1],md5[2],md5[3],md5].join('/')
|
68
|
+
|
69
|
+
bucket.put(file_name, IO.binread(file))
|
70
|
+
|
71
|
+
Tigre.logger.info 'Updating sample with filename / filesize'
|
72
|
+
f = File.new(file, 'r')
|
73
|
+
digest_hash = self.calculate_checksums(f)
|
74
|
+
post_data = {:md5 => md5,
|
75
|
+
:sample => {:file_original_filename => File.basename(f),
|
76
|
+
:file_size => File.size(f),
|
77
|
+
:sha1 => digest_hash[:sha1],
|
78
|
+
:sha256 => digest_hash[:sha256]
|
79
|
+
}
|
80
|
+
}
|
81
|
+
Tigre.post_connection('/samples', post_data)
|
25
82
|
end
|
26
|
-
|
83
|
+
|
84
|
+
def self.calculate_checksums(file)
|
85
|
+
sha1 = Sample.calculate_file_digest(Digest::SHA1.new, file)
|
86
|
+
sha256 = Sample.calculate_file_digest(Digest::SHA2.new, file)
|
87
|
+
{:sha1 => sha1, :sha256 => sha256}
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.calculate_file_digest(digest, file)
|
91
|
+
File.open(file, "rb") do |f|
|
92
|
+
digest.update f.read(8192) until f.eof
|
93
|
+
end
|
94
|
+
digest.hexdigest
|
95
|
+
end
|
96
|
+
|
27
97
|
# required params
|
28
98
|
# md5 => String
|
29
99
|
# params_hash => Hash
|
data/lib/tigre-client/version.rb
CHANGED
data/lib/tigre-client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# 3rd party libs
|
2
2
|
require 'faraday'
|
3
3
|
require 'tigre-client/multipart_with_file'
|
4
|
+
require 'right_aws'
|
4
5
|
|
5
6
|
# common functionality libraries
|
6
7
|
require 'tigre-client/common/analysis_components'
|
@@ -15,15 +16,19 @@ require 'tigre-client/sample'
|
|
15
16
|
require 'tigre-client/url'
|
16
17
|
|
17
18
|
module Tigre
|
18
|
-
|
19
|
+
|
19
20
|
class << self
|
20
|
-
attr_accessor :token, :server, :endpoint, :conn, :logger
|
21
|
-
|
21
|
+
attr_accessor :token, :server, :endpoint, :conn, :logger, :s3_key, :s3_secret, :s3_bucket
|
22
|
+
|
22
23
|
def configure
|
23
24
|
yield self
|
24
25
|
true
|
25
26
|
end
|
26
|
-
|
27
|
+
|
28
|
+
def s3_enabled?
|
29
|
+
!Tigre.s3_key.nil? && !Tigre.s3_secret.nil? && !Tigre.s3_bucket.nil?
|
30
|
+
end
|
31
|
+
|
27
32
|
def build_get_connection
|
28
33
|
@conn = Faraday.new(:url => "#{Tigre.server}") do |builder|
|
29
34
|
builder.adapter :net_http
|
@@ -38,13 +43,13 @@ module Tigre
|
|
38
43
|
builder.adapter :net_http
|
39
44
|
end
|
40
45
|
end
|
41
|
-
|
46
|
+
|
42
47
|
def get_connection(uri_string)
|
43
48
|
build_get_connection
|
44
49
|
response = Tigre.conn.get(Tigre.endpoint + uri_string, 'API-TOKEN' => Tigre.token)
|
45
50
|
[response.status, response.body]
|
46
51
|
end
|
47
|
-
|
52
|
+
|
48
53
|
def post_connection(uri_string, data)
|
49
54
|
build_post_connection
|
50
55
|
response = Tigre.conn.post do |req|
|
@@ -54,11 +59,11 @@ module Tigre
|
|
54
59
|
end
|
55
60
|
[response.status, response.body]
|
56
61
|
end
|
57
|
-
|
62
|
+
|
58
63
|
# TODO do we need a post_connection and a post_file_connection?
|
59
64
|
# def post_file_connection(uri_string, data)
|
60
65
|
# build_post_connection
|
61
|
-
#
|
66
|
+
#
|
62
67
|
# response = Tigre.conn.post do |req|
|
63
68
|
# req.url Tigre.endpoint + uri_string
|
64
69
|
# req.headers['API-TOKEN'] = Tigre.token
|
@@ -66,10 +71,9 @@ module Tigre
|
|
66
71
|
# end
|
67
72
|
# [response.status, response.body]
|
68
73
|
# end
|
69
|
-
|
74
|
+
|
70
75
|
def put_connection(uri_string, data)
|
71
76
|
build_post_connection
|
72
|
-
|
73
77
|
response = Tigre.conn.put do |req|
|
74
78
|
req.url Tigre.endpoint + uri_string
|
75
79
|
req.headers['API-TOKEN'] = Tigre.token
|
@@ -77,7 +81,7 @@ module Tigre
|
|
77
81
|
end
|
78
82
|
[response.status, response.body]
|
79
83
|
end
|
80
|
-
|
84
|
+
|
81
85
|
end
|
82
|
-
|
86
|
+
|
83
87
|
end
|
data/tigre-client.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tigre-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Marcio Castilho
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-05-
|
14
|
+
date: 2011-05-09 00:00:00 -04:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,17 @@ dependencies:
|
|
47
47
|
version: 0.6.0
|
48
48
|
type: :runtime
|
49
49
|
version_requirements: *id003
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: right_aws
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 2.1.0
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id004
|
50
61
|
description: Tigre Client API Library
|
51
62
|
email:
|
52
63
|
- marcioc@sunbelt-software.com
|