ats 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7eb27ec01faf12a9d4ccf0ca36588f91b72305ce29c6dc6034fe9089f546bc53
4
- data.tar.gz: 941b422bf5a5e71ca0004dc6ad9b2d516a54b83db255fcb24e292844fe130322
3
+ metadata.gz: '04740022192a62e2fb065b8873ca75ccddc84f969ba9afc6177e5411eb2173eb'
4
+ data.tar.gz: 35ecaa6040870a7bc06f6ec2e5ffcecf1e6927ec2f52e1596104bf61d5a04424
5
5
  SHA512:
6
- metadata.gz: 165b94fb99a63af982466640a85abddcef4e32a2a23369e88371e09f19f8be124249b7891e542228f408ed292b09bf3acd11f3614f72aa3bf5695228a9e958da
7
- data.tar.gz: 78d3cfecdebf5b0e0ec64aac27319c2670e3fb98d46f6b6e4ed770d64b6e67d0dfa957e22988c0a1e918e670ac918af42fe288b81d981bf0a00b7ddbdbd1c416
6
+ metadata.gz: 2ccd500eebb79298b5e7bac5d775a2a658e943d1e575d6e5d96ce1c602e5b953a3bd00d6ff1653193b4062ae058ccacfe7dcd42f0214531ef3eef8bb987c2aef
7
+ data.tar.gz: b7c47c5c1f64a8786f209de07d73f00eb3e14e4b74248f215bd963dccdabac33676e2740e36f2110153a440ea779ffa5867cfc8cdef4ac013e713b1e9db07fb9
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.required_ruby_version = '>= 2.5.0'
26
26
 
27
27
  spec.add_dependency 'thor', '~> 0.20'
28
+ spec.add_dependency 'net-hippie', '0.1.8'
28
29
  spec.add_development_dependency "bundler", "~> 1.16"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
30
31
  spec.add_development_dependency "rspec", "~> 3.0"
data/lib/ats.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'base64'
2
2
  require 'json'
3
3
  require 'logger'
4
+ require 'net/hippie'
4
5
  require 'net/http'
5
6
  require 'yaml'
6
7
 
7
8
  require 'ats/configuration'
8
- require 'ats/http_api'
9
9
  require 'ats/version'
10
10
 
11
11
  require 'ats/amp4e/api'
@@ -7,14 +7,16 @@ module ATS
7
7
  'User-Agent' => "RubyGems/ATS #{ATS::VERSION}",
8
8
  }.freeze
9
9
 
10
- attr_reader :http, :port, :host, :scheme, :client_id, :client_secret
10
+ attr_reader :http, :port, :host, :scheme
11
+ attr_reader :bearer_token, :client_id, :client_secret
11
12
 
12
13
  def initialize(configuration:, debug: false)
13
- @http = HttpAPI.new(headers: HEADERS, debug: debug)
14
+ @http = Net::Hippie::Client.new(headers: HEADERS, verify_mode: debug ? OpenSSL::SSL::VERIFY_NONE : nil)
14
15
  @configuration = configuration
15
16
  @port = configuration[:port]
16
17
  @scheme = configuration[:scheme]
17
18
  @host = configuration[:host]
19
+ @bearer_token = configuration[:bearer_token]
18
20
  @client_id = configuration[:client_id]
19
21
  @client_secret = configuration[:client_secret]
20
22
  end
@@ -48,7 +50,11 @@ module ATS
48
50
  end
49
51
 
50
52
  def headers
51
- { AUTHORIZATION: "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}" }
53
+ if bearer_token
54
+ { AUTHORIZATION: "Bearer #{bearer_token}" }
55
+ else
56
+ { AUTHORIZATION: "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}" }
57
+ end
52
58
  end
53
59
  end
54
60
  end
@@ -26,6 +26,7 @@ module ATS
26
26
 
27
27
  def configuration
28
28
  ATS.configure do |x|
29
+ Net::Hippie.logger = Logger.new('/dev/null') unless options['debug']
29
30
  x.debug = options['debug']
30
31
  end
31
32
  end
@@ -10,7 +10,7 @@ module ATS
10
10
  attr_reader :http, :port, :host, :scheme, :bearer_token
11
11
 
12
12
  def initialize(configuration:, debug: false)
13
- @http = HttpAPI.new(headers: HEADERS, debug: debug)
13
+ @http = Net::Hippie::Client.new(headers: HEADERS, verify_mode: debug ? OpenSSL::SSL::VERIFY_NONE : nil)
14
14
  @configuration = configuration
15
15
  @port = configuration[:port]
16
16
  @scheme = configuration[:scheme]
@@ -9,7 +9,7 @@ module ATS
9
9
  attr_reader :http, :port, :host, :scheme, :api_key
10
10
 
11
11
  def initialize(configuration:, debug: false)
12
- @http = HttpAPI.new(headers: HEADERS, debug: debug)
12
+ @http = Net::Hippie::Client.new(headers: HEADERS, verify_mode: debug ? OpenSSL::SSL::VERIFY_NONE : nil)
13
13
  @configuration = configuration
14
14
  @port = configuration[:port]
15
15
  @scheme = configuration[:scheme]
@@ -1,3 +1,3 @@
1
1
  module ATS
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - mokha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-25 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.20'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-hippie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.8
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +118,6 @@ files:
104
118
  - lib/ats/cli/threat_grid/users.rb
105
119
  - lib/ats/cli/threat_grid/whoami.rb
106
120
  - lib/ats/configuration.rb
107
- - lib/ats/http_api.rb
108
121
  - lib/ats/shiro/api.rb
109
122
  - lib/ats/shiro/tokens.rb
110
123
  - lib/ats/threat_grid/api.rb
@@ -1,79 +0,0 @@
1
- require 'openssl'
2
-
3
- module ATS
4
- class HttpAPI
5
- def initialize(headers: {}, debug: false)
6
- @default_headers = headers
7
- @debug = debug
8
- end
9
-
10
- def execute(uri, request)
11
- http_for(uri).request(request)
12
- end
13
-
14
- def get(uri, headers: {}, body: {})
15
- request = get_for(uri, headers: headers, body: body)
16
- response = execute(uri, request)
17
- if block_given?
18
- yield request, response
19
- else
20
- response
21
- end
22
- end
23
-
24
- def post(uri, headers: {}, body: {})
25
- request = post_for(uri, headers: headers, body: body)
26
- response = execute(uri, request)
27
- if block_given?
28
- yield request, response
29
- else
30
- response
31
- end
32
- end
33
-
34
- def put(uri, headers: {}, body: {})
35
- request = put_for(uri, headers: headers, body: body)
36
- response = execute(uri, request)
37
- if block_given?
38
- yield request, response
39
- else
40
- response
41
- end
42
- end
43
-
44
- private
45
-
46
- def http_for(uri)
47
- http = Net::HTTP.new(uri.host, uri.port)
48
- http.read_timeout = 30
49
- http.use_ssl = uri.scheme == "https"
50
- if debug?
51
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52
- http.set_debug_output(ATS.logger)
53
- end
54
- http
55
- end
56
-
57
- def post_for(uri, headers: {}, body: {})
58
- Net::HTTP::Post.new(uri.path, @default_headers.merge(headers)).tap do |x|
59
- x.body = JSON.generate(body)
60
- end
61
- end
62
-
63
- def put_for(uri, headers: {}, body: {})
64
- Net::HTTP::Put.new(uri.path, @default_headers.merge(headers)).tap do |x|
65
- x.body = JSON.generate(body)
66
- end
67
- end
68
-
69
- def get_for(uri, headers: {}, body: {})
70
- Net::HTTP::Get.new(uri.path, @default_headers.merge(headers)).tap do |x|
71
- x.body = JSON.generate(body)
72
- end
73
- end
74
-
75
- def debug?
76
- @debug
77
- end
78
- end
79
- end