norad_beacon 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: defdd19d1e84401ef7c56d7ebed4e587dd05f440
4
- data.tar.gz: fa4789a131a798d87d0cc5bad20ec14c207f8ade
3
+ metadata.gz: 2947fc7310fe218b9a224ac924a54d8bdbf2ae1c
4
+ data.tar.gz: c63ab35803595c7d6ad1ef93d680e12aed830cef
5
5
  SHA512:
6
- metadata.gz: b7307db47ad21b46594f237c3e3da64f9ac7cbadaaebc8657d81559af7e55145789407087a0363e436d136c67b0434595d1ea0edfad4831ba8b2690a9e2a53aa
7
- data.tar.gz: 2b1516c17d15e51b904f7ad48be50ff46c8c25e6e7513fd399305bc6e6308e7438eaf1944e9c67699948ee51ca45af68955aede69c384f6170a29cf0f953c4da
6
+ metadata.gz: 930d9699e9537f1a92e141e243e5c9565abe47c43f3342c74d60971c3b8d3ce47fd92a0982114aa9a23123feaa2481c3ef32d1ac1a6415dd72781dd56f632540
7
+ data.tar.gz: 5cb41b6a56aecc5668ff55ff1db53e0f751dc80b12f7fba287726a052ae12b3976555ff06c931c7690d1e18531543782f817009a1db619ce49a80bcbef8b0209
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'https://rubygems.org'
3
4
 
4
5
  # Specify your gem's dependencies in norad.gemspec
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'bundler/gem_tasks'
3
4
  require 'rspec/core/rake_task'
4
5
  require 'rubocop/rake_task'
@@ -1,19 +1,36 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'httparty'
3
4
 
4
5
  module NoradBeacon
5
- # Class to post results
6
+ # Class to post http payloads
6
7
  class NoradAPI
7
8
  include HTTParty
8
9
  @norad_root = ENV.fetch('NORAD_ROOT')
9
10
 
10
- def self.post_results(results)
11
- auth_header = { 'NORAD-SIGNATURE' => results.compute_signature }
12
- address = @norad_root + results.url
13
- post(
14
- address,
15
- body: results.payload, headers: { 'Content-Type' => 'application/json' }.merge(auth_header)
16
- )
11
+ class << self
12
+ def post_payload(http_payload)
13
+ http_req http_payload, :post
14
+ end
15
+
16
+ def delete_payload(http_payload)
17
+ http_req http_payload, :delete
18
+ end
19
+
20
+ alias post_results post_payload
21
+
22
+ private
23
+
24
+ def http_req(http_payload, verb)
25
+ auth_header = { 'NORAD-SIGNATURE' => http_payload.compute_signature }
26
+ address = @norad_root + http_payload.url
27
+ send(
28
+ verb,
29
+ address,
30
+ body: http_payload.payload,
31
+ headers: { 'Content-Type' => 'application/json' }.merge(auth_header)
32
+ )
33
+ end
17
34
  end
18
35
  end
19
36
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'safe_yaml'
3
4
 
4
5
  SafeYAML::OPTIONS[:default_mode] = :safe
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class NoradBeaconError < StandardError
3
4
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'openssl'
5
+
6
+ module NoradBeacon
7
+ class HttpPayload
8
+ attr_accessor :url
9
+
10
+ def initialize(url = nil)
11
+ @data = {}
12
+ @url = url || url_from_env
13
+ end
14
+
15
+ def add(obj)
16
+ @data.merge!(obj.to_h)
17
+ end
18
+
19
+ def payload
20
+ @payload ||= @data.merge(timestamp: Time.now.to_i).to_json
21
+ end
22
+
23
+ def compute_signature
24
+ OpenSSL::HMAC.hexdigest('sha256', ENV['NORAD_SECRET'], payload)
25
+ end
26
+
27
+ private
28
+
29
+ def url_from_env
30
+ ''
31
+ end
32
+ end
33
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'childprocess'
3
4
 
4
5
  module NoradBeacon
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'json'
3
4
  require 'openssl'
4
5
 
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'json'
3
4
  require 'openssl'
4
5
 
5
6
  module NoradBeacon
6
- class ResultSet
7
- attr_accessor :url
8
-
9
- def initialize(assessment_url = nil)
7
+ class ResultSet < HttpPayload
8
+ def initialize(url = nil)
9
+ super(url)
10
10
  @results = []
11
- @url = assessment_url || JSON.parse(ENV.fetch('ASSESSMENT_PATHS')).first['assessment']
12
11
  end
13
12
 
14
13
  def add(result)
@@ -19,8 +18,10 @@ module NoradBeacon
19
18
  @payload ||= { results: @results, timestamp: Time.now.to_i }.to_json
20
19
  end
21
20
 
22
- def compute_signature
23
- OpenSSL::HMAC.hexdigest('sha256', ENV['NORAD_SECRET'], payload)
21
+ private
22
+
23
+ def url_from_env
24
+ JSON.parse(ENV.fetch('ASSESSMENT_PATHS')).first['assessment']
24
25
  end
25
26
  end
26
27
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'childprocess'
3
4
 
4
5
  module NoradBeacon
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module NoradBeacon
3
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
4
5
  end
data/lib/norad_beacon.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'norad_beacon/version'
3
4
  require 'norad_beacon/runner'
4
5
  require 'norad_beacon/multi_runner'
6
+ require 'norad_beacon/http_payload'
5
7
  require 'norad_beacon/result'
6
8
  require 'norad_beacon/resultset'
7
9
  require 'norad_beacon/exceptions'
data/norad_beacon.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  lib = File.expand_path('../lib', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require 'norad_beacon/version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norad_beacon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hitchcock
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-02-10 00:00:00.000000000 Z
13
+ date: 2017-07-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -165,6 +165,7 @@ files:
165
165
  - lib/norad_beacon/api.rb
166
166
  - lib/norad_beacon/container_options.rb
167
167
  - lib/norad_beacon/exceptions.rb
168
+ - lib/norad_beacon/http_payload.rb
168
169
  - lib/norad_beacon/multi_runner.rb
169
170
  - lib/norad_beacon/result.rb
170
171
  - lib/norad_beacon/resultset.rb
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  version: '0'
192
193
  requirements: []
193
194
  rubyforge_project:
194
- rubygems_version: 2.6.10
195
+ rubygems_version: 2.6.11
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: Gem to help with posting blackbox results to Norad.