whowas 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: a92b53b7bef30819cd2501c2435b13b10be15708
4
- data.tar.gz: 4f038b70ab9fd3bd78a3132a8d82f012737a4c48
3
+ metadata.gz: 8f18c072668284649883a05ad1bbebe28c610a3b
4
+ data.tar.gz: 8f9e494556ac732fafbc724f3e2c4c1365733bd2
5
5
  SHA512:
6
- metadata.gz: 0ca98edc334537e9ead70ad1b847a7457d417535aa31179e71764e4f4414df0bb46b51a1388a3f161162a24b668f977078924e0371b0d346bbebf87bd90f4008
7
- data.tar.gz: 35a057c905f6d486312239c80449473071138ebe17144845b3f47cfe0d7439563df2289d933b4d5aa4564990b781cb76e6fa54996dea555947d3f4b6b0f53806
6
+ metadata.gz: 9446751954db0d0894d12f15ebd33fe07a9894f0283d482c49f9bac472ea6590c81bb16769d9d3d497032b885893608542a32ddaa8845d379c731636fb09a1f3
7
+ data.tar.gz: f8f7fdda8c3b564c8ddcc8d6b68f128d883fb80ecb069e8fed6076688f5fdebab31b75372f87d68a165bfa22715940ead1c139b8427c1e9a32d218391de4ba6b
@@ -11,8 +11,12 @@ module Whowas
11
11
  # Whowas.splunk_config is configured via define_setting in the initializer.
12
12
  # See configuration.rb for more information.
13
13
  def self.connection(config: Whowas.splunk_config)
14
- @@connection ||= ::Splunk::connect(config)
15
- rescue => e
14
+ if @@connection && @@connection.token
15
+ @@connection = ::Splunk::Service.new(config.merge(token: @@connection.token))
16
+ else
17
+ @@connection = ::Splunk::connect(config)
18
+ end
19
+ rescue StandardError => e
16
20
  raise Whowas::Errors::ServiceUnavailable, "#{self.class.name}: #{e}"
17
21
  end
18
22
 
@@ -47,6 +51,6 @@ module Whowas
47
51
  else
48
52
  ""
49
53
  end
50
- end
54
+ end
51
55
  end
52
56
  end
@@ -40,17 +40,16 @@ module Whowas
40
40
  define_setting :recipe_class, Whowas::Recipes
41
41
 
42
42
  # configuration defaults
43
- define_setting :splunk_config, nil
43
+ define_setting :splunk_config, nil
44
44
 
45
45
  def self.search(input)
46
+ validate_configuration
46
47
  recipe = recipe_class.select(input) || Whowas.recipe_table[:default]
47
48
  env = {input: input, results: []}
48
49
  self.send(recipe).call(env)
49
50
  env
50
51
  end
51
52
 
52
- private
53
-
54
53
  # Uses the recipe_table hash to match up the input to the correct recipe type.
55
54
  # If there is an IP address in the input, it tries to match the IP address
56
55
  # against any keys that are valid CIDR blocks.
@@ -58,5 +57,14 @@ module Whowas
58
57
  # Otherwise, it falls back to :default.
59
58
  def select_recipe(input)
60
59
  end
61
-
60
+
61
+ # Ensure that the user has configured the recipe table and initialized the whowas
62
+ # directory in the overarching app.
63
+ # Does not prove the app is properly configured -- this is the bare minimum, meant to
64
+ # be an alert for users who don't realize they have to configure anything at all.
65
+ def self.validate_configuration
66
+ if recipe_table == {} || !recipe_table.include?(:default)
67
+ raise Whowas::Errors::ConfigurationError, "Please configure Whowas as described at https://github.com/TuftsUniversity/whowas"
68
+ end
69
+ end
62
70
  end
@@ -5,6 +5,10 @@ module Whowas
5
5
  end
6
6
 
7
7
  module Errors
8
+ # Will be thrown when Whowas is not configured or configured improperly.
9
+ class ConfigurationError < Whowas::Error
10
+ end
11
+
8
12
  # Will be thrown when input is invalid.
9
13
  class InvalidInput < Whowas::Error
10
14
  end
@@ -1,3 +1,3 @@
1
1
  module Whowas
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whowas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jess Frisch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-13 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleware