splunker 0.0.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.
@@ -0,0 +1,15 @@
1
+ module Splunker
2
+ module RspecLetDefinitions
3
+ def self.included(base)
4
+ base.let(:client) {
5
+ Splunker.client(
6
+ :auth_mode => :http_auth,
7
+ :endpoint => "https://127.0.0.1",
8
+ :username => "tido",
9
+ :password => "12345",
10
+ :app => "search"
11
+ )
12
+ }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'splunker'
3
+ require 'rspec_let_definitions'
4
+
5
+ RSpec.configure do |config|
6
+ config.color_enabled = true
7
+ config.formatter = 'documentation'
8
+ config.include Splunker::RspecLetDefinitions
9
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Splunker::Auth::HttpAuth do
4
+ let(:request_handler) do
5
+ Splunker::Auth::HttpAuth.new(client)
6
+ end
7
+
8
+ context "configuration" do
9
+ it "should have a valid configuratoin if username and password are present" do
10
+ request_handler.configuration_valid?.should be_true
11
+ end
12
+
13
+ it "should have an invalid configuration if either username or password are missing" do
14
+ request_handler.stub(:configuration).and_return({})
15
+ request_handler.configuration_valid?.should be_false
16
+
17
+ request_handler.stub(:configuration).and_return({:username => "tido"})
18
+ request_handler.configuration_valid?.should be_false
19
+
20
+ request_handler.stub(:configuration).and_return({:password => "12345"})
21
+ request_handler.configuration_valid?.should be_false
22
+ end
23
+
24
+ it "should raise an error when verifying configuration if invalid" do
25
+ request_handler.verify_configuration!
26
+ request_handler.stub(:configuration_valid?).and_return(false)
27
+ expect {
28
+ request_handler.verify_configuration!
29
+ }.to raise_error(Splunker::Errors::ConfigurationError)
30
+ end
31
+ end
32
+
33
+ context "connection handling" do
34
+ before(:all) do
35
+ @fake_connection = HttpAuthSpecConnection.new
36
+ end
37
+
38
+ it "should decorate a connection object with basic auth credentials" do
39
+ request_handler.authenticate_connection(@fake_connection)
40
+ @fake_connection.username.should eq("tido")
41
+ end
42
+
43
+ it "should not reconfigure a configured connection" do
44
+ request_handler.authenticate_connection(@fake_connection) # Configure with "tido"
45
+
46
+ request_handler.stub(:configuration).and_return({:username => "Ned", :password => "abcdefg"})
47
+ request_handler.authenticate_connection(@fake_connection)
48
+ @fake_connection.username.should eq("tido")
49
+ end
50
+
51
+ it "should reconfigure a configured connection after resetting" do
52
+ request_handler.authenticate_connection(@fake_connection) # configure with "tido"
53
+
54
+ request_handler.stub(:configuration).and_return({:username => "Ned", :password => "abcdefg"})
55
+ request_handler.reset
56
+ request_handler.authenticate_connection(@fake_connection)
57
+ @fake_connection.username.should eq("Ned")
58
+ end
59
+ end
60
+ end
61
+
62
+ class HttpAuthSpecConnection
63
+ attr_accessor :username, :password
64
+ def basic_auth(username, password)
65
+ self.username = username
66
+ self.password = password
67
+ end
68
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Splunker::Auth::SplunkAuth do
4
+ let(:request_handler) do
5
+ Splunker::Auth::SplunkAuth.new(client)
6
+ end
7
+
8
+ context "configuration" do
9
+ it "should not be configured by default" do
10
+ request_handler.configured?.should be_false
11
+ end
12
+
13
+ it "should have access to client configuration" do
14
+ request_handler.configuration.should be_a(Hash)
15
+ end
16
+
17
+ it "should raise exception when verifying configuration if invalid" do
18
+ request_handler.verify_configuration!
19
+ request_handler.stub(:configuration_valid?).and_return(false)
20
+ expect {
21
+ request_handler.verify_configuration!
22
+ }.to raise_error(Splunker::Errors::ConfigurationError)
23
+ end
24
+
25
+ it "should have a valid configuration by default" do
26
+ request_handler.configuration_valid?.should be_true
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Splunker::Client do
4
+ context "initialization" do
5
+ it "should be configurable" do
6
+ client.endpoint.should eq("https://127.0.0.1")
7
+ end
8
+ end
9
+
10
+ context "requests" do
11
+ it "should pass methods to request handler" do
12
+ expect {
13
+ client.get
14
+ }.to raise_error ArgumentError
15
+ end
16
+
17
+ it "should respond to methods handled by request handler" do
18
+ client.respond_to?(:get).should be_true
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ describe Splunker::Configuration do
2
+ class MyConfigurableClass
3
+ include Splunker::Configuration
4
+ end
5
+
6
+ let(:configurable) { MyConfigurableClass.new }
7
+
8
+ it "should set accessors" do
9
+ configurable.respond_to?(:endpoint=).should be_true
10
+ end
11
+
12
+ it "should set return a default configuration" do
13
+ configurable.reset
14
+ configurable.configuration[:app].should eq("search")
15
+ end
16
+
17
+ it "should be configurable" do
18
+ configurable.configure do |c|
19
+ c.username = "fred"
20
+ end
21
+ configurable.username.should eq("fred")
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ describe Splunker::Errors do
2
+ context ".raise_error_for_status" do
3
+ it "should raise no error for a 200..299 status" do
4
+ Splunker::Errors.raise_error_for_status!(200, "")
5
+ Splunker::Errors.raise_error_for_status!(201, "")
6
+ Splunker::Errors.raise_error_for_status!(299, "")
7
+ end
8
+
9
+ it "should raise a status from the map when there is a match" do
10
+ expect {
11
+ Splunker::Errors.raise_error_for_status!(401, "")
12
+ }.to raise_error(Splunker::Errors::AuthenticationFailureError)
13
+ end
14
+
15
+ it "should raise a generic error when status in 200..299 range" do
16
+ expect {
17
+ Splunker::Errors.raise_error_for_status!(504, "")
18
+ }.to raise_error(Splunker::Errors::ClientError)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Splunker" do
4
+ it "should create a new class if options are specified" do
5
+ Splunker.client(:endpoint => "https://127.0.0.2").should_not be(client)
6
+ end
7
+
8
+ it "should reuse the existing class if no options are specified" do
9
+ Splunker.client(:endpoint => "https://127.0.0.3").should be(Splunker.client)
10
+ end
11
+
12
+ it "should call methods on the client object" do
13
+ client.configuration[:endpoint].should eq("https://127.0.0.1")
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/splunker/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Joshua Murray"]
6
+ gem.email = ["joshua.murray@gmail.com"]
7
+ gem.description = %q{A Ruby client for the Splunk API}
8
+ gem.summary = %q{A Ruby client for the Splunk API}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "splunker"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Splunker::VERSION
17
+
18
+ gem.add_dependency "nokogiri"
19
+ gem.add_dependency "faraday"
20
+ gem.add_development_dependency "rspec", "~> 2.11"
21
+ gem.add_development_dependency "rake", "~> 0.9.2"
22
+ gem.add_development_dependency "webmock"
23
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: splunker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joshua Murray
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.9.2
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.2
78
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A Ruby client for the Splunk API
95
+ email:
96
+ - joshua.murray@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE
104
+ - README.md
105
+ - Rakefile
106
+ - VERSION
107
+ - lib/splunker.rb
108
+ - lib/splunker/auth.rb
109
+ - lib/splunker/auth/http_auth.rb
110
+ - lib/splunker/auth/splunk_auth.rb
111
+ - lib/splunker/auth/token_auth.rb
112
+ - lib/splunker/cli.rb
113
+ - lib/splunker/cli/setup.rb
114
+ - lib/splunker/client.rb
115
+ - lib/splunker/configuration.rb
116
+ - lib/splunker/connection.rb
117
+ - lib/splunker/errors.rb
118
+ - lib/splunker/faraday_middleware.rb
119
+ - lib/splunker/models/finders.rb
120
+ - lib/splunker/models/resource.rb
121
+ - lib/splunker/models/search/jobs.rb
122
+ - lib/splunker/models/search/results.rb
123
+ - lib/splunker/models/search/saved.rb
124
+ - lib/splunker/request.rb
125
+ - lib/splunker/version.rb
126
+ - script/console
127
+ - spec/fixtures/search_results_from_job.xml
128
+ - spec/rspec_let_definitions.rb
129
+ - spec/spec_helper.rb
130
+ - spec/unit/auth/http_auth_spec.rb
131
+ - spec/unit/auth/splunk_auth_spec.rb
132
+ - spec/unit/client_spec.rb
133
+ - spec/unit/configuration_spec.rb
134
+ - spec/unit/errors_spec.rb
135
+ - spec/unit/splunker_spec.rb
136
+ - splunker.gemspec
137
+ homepage: ''
138
+ licenses: []
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.24
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: A Ruby client for the Splunk API
161
+ test_files:
162
+ - spec/fixtures/search_results_from_job.xml
163
+ - spec/rspec_let_definitions.rb
164
+ - spec/spec_helper.rb
165
+ - spec/unit/auth/http_auth_spec.rb
166
+ - spec/unit/auth/splunk_auth_spec.rb
167
+ - spec/unit/client_spec.rb
168
+ - spec/unit/configuration_spec.rb
169
+ - spec/unit/errors_spec.rb
170
+ - spec/unit/splunker_spec.rb