rack-logs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e41cba44bb13dd1cb47253fe02c2e098a53df2de
4
+ data.tar.gz: 498c846612eb65afc5bc9c8bbe27d24c66804434
5
+ SHA512:
6
+ metadata.gz: 9f2adf14ab42fb7e2b08a7cdb6adb6be8cb881f084abd81c547393e69be5c6c4a9af731fcfe667dfbb61d678ba25dbb759559814bab8fc7901fd3cb25acc3efb
7
+ data.tar.gz: eb243ac4724ba8ec15b4fe622f2bb4e218646ed11cc8ab8996b4abdc21e93798717e89ea96150fc54526f56d71bae988a2fe48d66f0a5f60e6a59c4d24c965eb
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ pkg
3
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --order random
3
+ -I ./lib
4
+ -r spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ bundler_args: "--standalone --binstubs"
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-19mode
7
+ - rbx-2.2.1
8
+ - 2.0.0
9
+ - 2.1.0
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx-2.2.1
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-logs.gemspec
4
+ gemspec
5
+
6
+ platforms :rbx do
7
+ gem 'rubysl'
8
+ gem 'rubysl-logger' # for rake
9
+ gem 'racc'
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jon Rowe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Rack::Logs
2
+
3
+ Simple rack mountable log viewer.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rack-logs'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rack-logs
18
+
19
+ ## Usage
20
+
21
+ Mount as `rack` middleware to expose your logs.
22
+
23
+ ** `rack-logs` exposes potentially sensitive information that may be contained
24
+ in your logs, please secure your stack against unauthorised access**
25
+
26
+ ```Ruby
27
+ use Rack::Logs do |config|
28
+ # controls the pattern used to find logs, defaults to *.log
29
+ config.pattern = '*.log'
30
+
31
+ # controls the directory searched for logs, defaults to `./log`
32
+ config.log_dir = File.expand_path('../log',__FILE__)
33
+ end
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc "Run unit tests"
7
+ RSpec::Core::RakeTask.new(:unit) do |t|
8
+ t.ruby_opts = %w[-w]
9
+ t.pattern = 'spec/unit/**/*_spec.rb'
10
+ end
11
+
12
+ desc "Run integration tests"
13
+ RSpec::Core::RakeTask.new(:integration) do |t|
14
+ t.ruby_opts = %w[-w]
15
+ t.pattern = 'spec/integration/**/*_spec.rb'
16
+ end
17
+
18
+ desc "Run both spec suites in order by default"
19
+ task default: %w[unit integration]
20
+
21
+ rescue LoadError
22
+ puts "RSpec Unavailable"
23
+ end
@@ -0,0 +1,14 @@
1
+ module Rack
2
+ module Logs
3
+ class Config
4
+
5
+ def initialize
6
+ @pattern = '*.log'
7
+ @log_dir = './log'
8
+ end
9
+
10
+ attr_accessor :pattern, :log_dir
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Logs
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ module Rack
2
+ module Logs
3
+ class Viewer
4
+
5
+ def initialize config
6
+ @config = config
7
+ end
8
+ attr_reader :config
9
+
10
+ def call env
11
+ [200, headers, [joined_logs]]
12
+ end
13
+
14
+ private
15
+
16
+ def headers
17
+ {
18
+ 'Content-Type' => 'text/plain'
19
+ }
20
+ end
21
+
22
+ def joined_logs
23
+ logs.inject("") do |string, (filename, contents)|
24
+ string + "## " + filename + "\n\n" + contents
25
+ end
26
+ end
27
+
28
+ def logs
29
+ files.inject({}) do |hash, filename|
30
+ hash[filename] = ::File.read(filename)
31
+ hash
32
+ end
33
+ end
34
+
35
+ def files
36
+ Dir[@config.log_dir+'/'+@config.pattern]
37
+ end
38
+
39
+ end
40
+ end
41
+ end
data/lib/rack/logs.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "rack/logs/version"
2
+
3
+ module Rack
4
+ module Logs
5
+ module_function
6
+
7
+ autoload 'Viewer', 'rack/logs/viewer'
8
+ autoload 'Config', 'rack/logs/config'
9
+
10
+ def configure
11
+ Rack::Logs::Viewer.new Config.new.tap { |c| yield c }
12
+ end
13
+
14
+ def call env
15
+ configure {}.call env
16
+ end
17
+
18
+ end
19
+ end
data/lib/rack-logs.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rack/logs'
data/rack-logs.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # enccoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/logs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-logs"
8
+ spec.version = Rack::Logs::VERSION
9
+ spec.authors = ["Jon Rowe"]
10
+ spec.email = ["hello@jonrowe.co.uk"]
11
+ spec.description = %q{Simple rack based log viewer}
12
+ spec.summary = %q{Simple rack based log viewer}
13
+ spec.homepage = "https://github.com/JonRowe/rack-logs"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^(spec)/})
18
+ spec.require_paths = ["lib"]
19
+ spec.required_ruby_version = '> 1.9'
20
+
21
+ spec.add_runtime_dependency "rack", "~> 1.5.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "fakefs"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rack-test"
27
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta1"
28
+ end
@@ -0,0 +1,45 @@
1
+ require 'rack/test'
2
+ require 'rack/logs'
3
+
4
+ describe 'running `Rack::Logs` via `Rack::Builder`', type: :integration do
5
+ include Rack::Test::Methods
6
+
7
+ context 'running with defaults' do
8
+ let(:app) { Rack::Builder.app { run Rack::Logs } }
9
+
10
+ before { get '/' }
11
+
12
+ example 'returns a 200 response code' do
13
+ expect(last_response).to be_ok
14
+ end
15
+ example 'returns no logs because there are no files' do
16
+ expect(last_response.body).to eq ''
17
+ end
18
+ end
19
+
20
+ context 'given a log in a configured directory' do
21
+ let(:app) do
22
+ Rack::Builder.app do
23
+ logs = Rack::Logs.configure do |config|
24
+ config.log_dir = './tmp'
25
+ end
26
+ run logs
27
+ end
28
+ end
29
+
30
+ before do
31
+ File.open('./tmp/my_log_file.log','w') do |f|
32
+ f.write "LOG ENTRY 1234"
33
+ end
34
+ get '/'
35
+ end
36
+
37
+ example 'returns a 200 response code' do
38
+ expect(last_response).to be_ok
39
+ end
40
+
41
+ example 'accessing the log returns log contents' do
42
+ expect(last_response.body).to match 'LOG ENTRY 1234'
43
+ end
44
+ end
45
+ end
@@ -0,0 +1 @@
1
+ # required by .rspec
@@ -0,0 +1,25 @@
1
+ require 'rack/logs/config'
2
+
3
+ describe 'Rack::Logs::Config' do
4
+ let(:config) { Rack::Logs::Config.new }
5
+
6
+ describe '#log_dir' do
7
+ it 'defaults to *.log' do
8
+ expect(config.log_dir).to eq './log'
9
+ end
10
+ it 'is configurable' do
11
+ config.log_dir = './tmp'
12
+ expect(config.log_dir).to eq './tmp'
13
+ end
14
+ end
15
+
16
+ describe '#pattern' do
17
+ it 'defaults to *.log' do
18
+ expect(config.pattern).to eq '*.log'
19
+ end
20
+ it 'is configurable' do
21
+ config.pattern = '*.doge'
22
+ expect(config.pattern).to eq '*.doge'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ require 'fakefs/safe'
2
+ require 'rack/logs/viewer'
3
+
4
+ describe 'Rack::Logs::Viewer' do
5
+ let(:config) { instance_double "Rack::Logs::Config", pattern: '*.doge', log_dir: './tmp' }
6
+
7
+ describe '#initialize' do
8
+ it 'takes a configuration' do
9
+ Rack::Logs::Viewer.new config
10
+ end
11
+ end
12
+
13
+ describe '#call env' do
14
+ let(:viewer) { Rack::Logs::Viewer.new config }
15
+ let(:response) { viewer.call({}) }
16
+
17
+ before do
18
+ FakeFS.activate!
19
+ FileUtils.mkdir_p('./tmp')
20
+ File.open('./tmp/not_log.txt','w') { |file| file.write 'Nothing to see here' }
21
+ File.open('./tmp/my_log.doge','w') { |file| file.write 'Much log, such information' }
22
+ end
23
+ after do
24
+ FakeFS.deactivate!
25
+ end
26
+
27
+ it 'returns a rack response' do
28
+ expect(response[0]).to be_a Fixnum
29
+ expect(response[1]).to be_a Hash
30
+ expect(response[1].keys).to include 'Content-Type'
31
+ expect(response[2].respond_to? :each).to be true
32
+ end
33
+ it 'returns the contents of the logs' do
34
+ expect(response[2]).to eq ["## tmp/my_log.doge\n\nMuch log, such information"]
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,53 @@
1
+ require 'rack/logs'
2
+
3
+ describe 'Rack::Logs' do
4
+ before do
5
+ stub_const "Rack::Logs::Config", Class.new
6
+ stub_const "Rack::Logs::Viewer", (Class.new do
7
+ def initialize config
8
+ @config = config
9
+ end
10
+ attr_reader :config
11
+ end)
12
+ end
13
+
14
+ describe '.configure' do
15
+ let(:viewer) { Rack::Logs.configure { } }
16
+
17
+ it 'takes a block that yields configuration' do
18
+ config = nil
19
+ Rack::Logs.configure { |object| config = object }
20
+ expect(config).to be_a Rack::Logs::Config
21
+ end
22
+ it 'creates a Rack::Logs::Viewer with the config' do
23
+ expect(viewer.config).to be_an_instance_of Rack::Logs::Config
24
+ end
25
+ it 'returns a Rack::Logs::Viewer' do
26
+ expect(viewer).to be_a Rack::Logs::Viewer
27
+ end
28
+ end
29
+
30
+ describe '.call' do
31
+ let(:viewer_response) { double }
32
+ let(:viewer) { instance_double "Rack::Logs::Viewer" }
33
+ let(:env) { double }
34
+
35
+ before do
36
+ allow(Rack::Logs::Viewer).to receive(:new).and_return(viewer)
37
+ allow(viewer).to receive(:call).and_return(viewer_response)
38
+ end
39
+
40
+ it 'creates a default Rack::Logs::Config' do
41
+ expect(Rack::Logs::Config).to receive(:new).once
42
+ Rack::Logs.call env
43
+ end
44
+ it 'creates a Rack::Logs::Viewer' do
45
+ expect(Rack::Logs::Viewer).to receive(:new).once
46
+ Rack::Logs.call env
47
+ end
48
+ it 'delegates to Rack::Logs::Viewer' do
49
+ expect(viewer).to receive(:call).with env
50
+ expect(Rack::Logs.call env).to eq viewer_response
51
+ end
52
+ end
53
+ end
data/tmp/.gitkeep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Rowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fakefs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0.beta1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0.beta1
97
+ description: Simple rack based log viewer
98
+ email:
99
+ - hello@jonrowe.co.uk
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/rack-logs.rb
112
+ - lib/rack/logs.rb
113
+ - lib/rack/logs/config.rb
114
+ - lib/rack/logs/version.rb
115
+ - lib/rack/logs/viewer.rb
116
+ - rack-logs.gemspec
117
+ - spec/integration/running_rack_logs_via_rack_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/unit/rack/logs/config_spec.rb
120
+ - spec/unit/rack/logs/viewer_spec.rb
121
+ - spec/unit/rack/logs_spec.rb
122
+ - tmp/.gitkeep
123
+ homepage: https://github.com/JonRowe/rack-logs
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">"
134
+ - !ruby/object:Gem::Version
135
+ version: '1.9'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.2.0
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Simple rack based log viewer
147
+ test_files:
148
+ - spec/integration/running_rack_logs_via_rack_spec.rb
149
+ - spec/spec_helper.rb
150
+ - spec/unit/rack/logs/config_spec.rb
151
+ - spec/unit/rack/logs/viewer_spec.rb
152
+ - spec/unit/rack/logs_spec.rb