whowas 0.1.4 → 0.2.0

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: 23b13b6e3c208d2ed5d32406ee185c7d9042edb9
4
- data.tar.gz: 6d5ebc269ba4ad75720d5b71fe80c7c85d2bb01d
3
+ metadata.gz: a92b53b7bef30819cd2501c2435b13b10be15708
4
+ data.tar.gz: 4f038b70ab9fd3bd78a3132a8d82f012737a4c48
5
5
  SHA512:
6
- metadata.gz: 2d7885df76e22f2f4f4d3fe213387a001992ad446c43656971d19ffeeee67e1f2a8968294c8ffec0341926b4bc83456e24c1d4fd8732e851795a4beb21867606
7
- data.tar.gz: 0354e38f5de7f29de16db613edc10ad9e2dcf83ace7e19135b88125bd9c2efbccda0d56d0aba34df1f2b666a6187e24c40671e07d02a389b18ce42635d051525
6
+ metadata.gz: 0ca98edc334537e9ead70ad1b847a7457d417535aa31179e71764e4f4414df0bb46b51a1388a3f161162a24b668f977078924e0371b0d346bbebf87bd90f4008
7
+ data.tar.gz: 35a057c905f6d486312239c80449473071138ebe17144845b3f47cfe0d7439563df2289d933b4d5aa4564990b781cb76e6fa54996dea555947d3f4b6b0f53806
@@ -2,7 +2,7 @@ require "splunk-sdk-ruby"
2
2
 
3
3
  module Whowas
4
4
  class Splunk
5
- include Whowas::Api
5
+ include Whowas::Adapter
6
6
 
7
7
  @@connection = nil
8
8
 
@@ -13,7 +13,7 @@ module Whowas
13
13
  def self.connection(config: Whowas.splunk_config)
14
14
  @@connection ||= ::Splunk::connect(config)
15
15
  rescue => e
16
- raise Whowas::Errors::ServiceUnavailable, e
16
+ raise Whowas::Errors::ServiceUnavailable, "#{self.class.name}: #{e}"
17
17
  end
18
18
 
19
19
  def validate(input)
@@ -22,7 +22,7 @@ module Whowas
22
22
  input[:offset].is_a?(Integer) &&
23
23
  DateTime.parse(input[:timestamp]) &&
24
24
  true) ||
25
- (raise Whowas::Errors::InvalidInput, "Invalid input for Splunk API")
25
+ (raise Whowas::Errors::InvalidInput, "Invalid input for Splunk")
26
26
  end
27
27
 
28
28
  def format(input)
@@ -0,0 +1,13 @@
1
+ module Whowas
2
+ class AdapterGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ def create
6
+ copy_file "adapter.rb", "app/whowas/adapters/#{file_name}.rb"
7
+ end
8
+
9
+ def rename_class
10
+ gsub_file "app/whowas/adapters/#{file_name}.rb", /MyAdapter/, name.camelize
11
+ end
12
+ end
13
+ end
@@ -3,11 +3,11 @@ module Whowas
3
3
  source_root File.expand_path("../templates", __FILE__)
4
4
 
5
5
  def create
6
- copy_file "recipe.rb", "app/recipes/#{file_name}.rb"
6
+ copy_file "recipe.rb", "app/whowas/recipes/#{file_name}.rb"
7
7
  end
8
8
 
9
9
  def rename_method
10
- gsub_file "app/recipes/#{file_name}.rb", /name_this_recipe/, name.underscore
10
+ gsub_file "app/whowas/recipes/#{file_name}.rb", /name_this_recipe/, name.underscore
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -3,11 +3,11 @@ module Whowas
3
3
  source_root File.expand_path("../templates", __FILE__)
4
4
 
5
5
  def create
6
- copy_file "search_method.rb", "app/search_methods/#{file_name}.rb"
6
+ copy_file "search_method.rb", "app/whowas/search_methods/#{file_name}.rb"
7
7
  end
8
8
 
9
9
  def rename_class
10
- gsub_file "app/search_methods/#{file_name}.rb", /MySearchMethod/, name.camelize
10
+ gsub_file "app/whowas/search_methods/#{file_name}.rb", /MySearchMethod/, name.camelize
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,17 +1,18 @@
1
1
  module Whowas
2
- class MyApi
3
- # Whowas::Api provides the public interface to your API, accessed through the
4
- # "search" instance method.
5
- include Whowas::Api
2
+ class MyAdapter
3
+ # Whowas::Adapter provides the public interface to your adapter, accessed
4
+ # through the "search" instance method.
5
+ include Whowas::Adapter
6
6
 
7
- # All custom API code is defined in the private methods below. Naturally,
8
- # you can add private methods as needed for connecting to the API, etc.
7
+ # All custom adapter code is defined in the private methods below.
8
+ # Naturally, you can add private methods as needed for connecting to the
9
+ # adapter, etc.
9
10
  private
10
11
 
11
12
  ## Required
12
13
 
13
- # Sends a search query with provided input to your API and returns results
14
- # as a string.
14
+ # Sends a search query with provided input to your third-party API and
15
+ # returns results as a string.
15
16
  def search_api(input)
16
17
  ""
17
18
  end
@@ -27,7 +28,7 @@ module Whowas
27
28
  end
28
29
 
29
30
  # Transforms input one last time before API call.
30
- # Will be called on input for all search_methods using this API.
31
+ # Will be called on input for all search_methods using this adapter.
31
32
  # For search_method-specific transformations, use the format_input method
32
33
  # in your search_method.
33
34
  def format(input)
@@ -3,16 +3,16 @@ Whowas.configuration do |config|
3
3
  ## Recipe Table
4
4
  # You MUST define your default recipe and any other recipes you may use
5
5
  # here. Viable keys include "default", "ip_default", "mac_default", and
6
- # valid IP addresses or CIDR blocks.
6
+ # valid IP addresses or CIDR blocks. Recipes are messages sent to Whowas.
7
7
  #
8
8
  # An example of a full recipe table:
9
9
  #
10
10
  # config.recipe_table = {
11
- # "192.168.1.0/24": Whowas.home_wireless,
12
- # "10.0.0.0/8": Whowas.internal_wired,
13
- # ip_default: Whowas.other_ips,
14
- # mac_default: Whowas.search_by_mac,
15
- # default: Whowas.other_ips
11
+ # "192.168.1.0/24": "home_wireless",
12
+ # "10.0.0.0/8": "internal_wired",
13
+ # ip_default: "other_ips",
14
+ # mac_default: "search_by_mac",
15
+ # default: "other_ips"
16
16
  # }
17
17
  config.recipe_table = {}
18
18
 
@@ -22,7 +22,7 @@ Whowas.configuration do |config|
22
22
  config.recipe_class = Whowas::Recipes
23
23
 
24
24
  ## API configuration and credentials
25
- # If you are not using a bundled API, you can safely ignore this section.
25
+ # If you are not using a bundled adapter, you can safely ignore this section.
26
26
 
27
27
  # Splunk API configuration
28
28
  # The recommended method is to store your Splunk credentials in environment
@@ -37,4 +37,4 @@ Whowas.configuration do |config|
37
37
  # }
38
38
  #
39
39
  config.splunk_config = {}
40
- end
40
+ end
@@ -5,10 +5,10 @@ module Whowas
5
5
  # All you have to do is specify the search method classes in the order
6
6
  # they should be called. The output for each search method should match
7
7
  # the input of the next.
8
- Middleware::Builder.new do
8
+ ::Middleware::Builder.new do
9
9
  # use MySearchMethod1
10
10
  # use MySearchMethod2
11
11
  # use MySearchMethod3
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,8 +1,9 @@
1
1
  module Whowas
2
2
  class MySearchMethod
3
3
  # All required public methods are contained in the Middleware package. It
4
- # initializes the search method, calls search on the API with the provided
5
- # input, and returns the output to the next search method or the caller.
4
+ # initializes the search method, calls search on the adapter with the
5
+ # provided input, and returns the output to the next search method or the
6
+ # caller.
6
7
  #
7
8
  # The Searchable modules (Validatable, Formattable, and Parsable) are
8
9
  # technically optional but in practice necessary to ensure usable input and
@@ -10,9 +11,9 @@ module Whowas
10
11
  include Whowas::Middleware
11
12
  include Whowas::Searchable
12
13
 
13
- ## API
14
- # You MUST set this to the name of a bundled or custom API class.
15
- @@api = API_CLASS_HERE
14
+ ## ADAPTER
15
+ # You MUST set this to the name of a bundled or custom adapter class.
16
+ @@adapter = ADAPTER_CLASS_HERE
16
17
 
17
18
  private
18
19
 
@@ -44,15 +45,16 @@ module Whowas
44
45
  # mac addresses given as input to this search method should use colons as
45
46
  # separators, perform that transformation here.
46
47
  #
47
- # API-wide transformations to the input can be made in the API format method.
48
+ # Adapter-wide transformations to the input can be made in the adapter
49
+ # format method.
48
50
  def format_input(input)
49
51
  input
50
52
  end
51
53
 
52
54
  ## Parsable
53
55
 
54
- # Extract pieces of the results string from the API using regex to form the
55
- # input hash for the next search method or the final result.
56
+ # Extract pieces of the results string from the adapter using regex to form
57
+ # the input hash for the next search method or the final result.
56
58
  def output_formats
57
59
  {
58
60
  # username: /User <\K\w*/
@@ -1,6 +1,6 @@
1
1
  require "middleware"
2
2
 
3
- require "whowas/api"
3
+ require "whowas/adapter"
4
4
  require "whowas/configuration"
5
5
  require "whowas/errors"
6
6
  require "whowas/formattable"
@@ -11,8 +11,8 @@ require "whowas/searchable"
11
11
  require "whowas/validatable"
12
12
  require "whowas/version"
13
13
 
14
- # bundled apis
15
- require "apis/splunk"
14
+ # bundled adapters
15
+ require "adapters/splunk"
16
16
 
17
17
 
18
18
  module Whowas
@@ -45,7 +45,7 @@ module Whowas
45
45
  def self.search(input)
46
46
  recipe = recipe_class.select(input) || Whowas.recipe_table[:default]
47
47
  env = {input: input, results: []}
48
- recipe.call(env)
48
+ self.send(recipe).call(env)
49
49
  env
50
50
  end
51
51
 
@@ -1,6 +1,6 @@
1
1
  module Whowas
2
- module Api
3
- # All APIs use (api_instance).search as the only public method
2
+ module Adapter
3
+ # All adapters use (adapter_instance).search as the only public method
4
4
  # and follow the pattern below.
5
5
  # Validation and formatting are optional.
6
6
  # search_api must contain the core api search code and return the results.
@@ -12,7 +12,7 @@ module Whowas
12
12
 
13
13
  private
14
14
 
15
- # default methods for APIs to use or override
15
+ # default methods for adapters to use or override
16
16
  #:nocov:
17
17
  def validate(input)
18
18
  true
@@ -7,15 +7,11 @@ module Whowas
7
7
  # :nocov:
8
8
  private
9
9
  # This is a hook for the including class to use to modify the input before
10
- # the api gets it.
11
- #
12
- # For example, when searching in Splunk, the Firewall class (which includes
13
- # Searchable) must create the query string from the ip and port, plus any
14
- # other parameters like the Splunk index it wants to search.
10
+ # the adapter gets it.
15
11
  #
16
12
  # By default, this method just returns the arguments given, but note that
17
13
  # most classes _will have_ to modify the input to make it usable by the
18
- # API modification method.
14
+ # adapter.
19
15
  def format_input(input)
20
16
  input
21
17
  end
@@ -1,10 +1,10 @@
1
1
  module Whowas
2
2
  module Searchable
3
- @@api = nil
3
+ @@adapter = nil
4
4
 
5
- # The including class *must* set the api class in a class constant.
6
- def api
7
- @@api || (raise Errors::SubclassResponsibility)
5
+ # The including class *must* set the adapter class in a class constant.
6
+ def adapter
7
+ @@adapter || (raise Errors::SubclassResponsibility)
8
8
  end
9
9
 
10
10
  # extend the including class with the searchable sub-modules
@@ -19,7 +19,7 @@ module Whowas
19
19
  def search(input)
20
20
  validate(input)
21
21
  input = format(input)
22
- result = api.new.search(input)
22
+ result = adapter.new.search(input)
23
23
  parse(result)
24
24
  end
25
25
  end
@@ -1,7 +1,7 @@
1
1
  module Whowas
2
2
  module Validatable
3
3
  # Checks for required inputs and input formats
4
- # that the API will need to process the search.
4
+ # that the adapter will need to process the search.
5
5
  #
6
6
  # It does *not* matter if there are other, non-required parameters
7
7
  # in the input hash; they will be ignored later.
@@ -32,7 +32,8 @@ module Whowas
32
32
  end
33
33
  end
34
34
 
35
- # Format is a lambda defined in the api class which returns true or false.
35
+ # Format is a lambda defined in the search method class which returns
36
+ # true or false.
36
37
  # This allows for flexible format checking:
37
38
  # e.g. regex for ip addresses and DateTime.parse calls for timestamps
38
39
  def check_format(formats, input)
@@ -1,3 +1,3 @@
1
1
  module Whowas
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
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.1.4
4
+ version: 0.2.0
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-06-24 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleware
@@ -138,17 +138,17 @@ files:
138
138
  - Rakefile
139
139
  - bin/console
140
140
  - bin/setup
141
- - lib/apis/splunk.rb
142
- - lib/generators/whowas/api_generator.rb
141
+ - lib/adapters/splunk.rb
142
+ - lib/generators/whowas/adapter_generator.rb
143
143
  - lib/generators/whowas/install_generator.rb
144
144
  - lib/generators/whowas/recipe_generator.rb
145
145
  - lib/generators/whowas/search_method_generator.rb
146
- - lib/generators/whowas/templates/api.rb
146
+ - lib/generators/whowas/templates/adapter.rb
147
147
  - lib/generators/whowas/templates/initializer.rb
148
148
  - lib/generators/whowas/templates/recipe.rb
149
149
  - lib/generators/whowas/templates/search_method.rb
150
150
  - lib/whowas.rb
151
- - lib/whowas/api.rb
151
+ - lib/whowas/adapter.rb
152
152
  - lib/whowas/configuration.rb
153
153
  - lib/whowas/errors.rb
154
154
  - lib/whowas/formattable.rb
@@ -1,13 +0,0 @@
1
- module Whowas
2
- class ApiGenerator < Rails::Generators::NamedBase
3
- source_root File.expand_path("../templates", __FILE__)
4
-
5
- def create
6
- copy_file "api.rb", "app/apis/#{file_name}.rb"
7
- end
8
-
9
- def rename_class
10
- gsub_file "app/apis/#{file_name}.rb", /MyApi/, name.camelize
11
- end
12
- end
13
- end