almaz 0.0.2
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.
- data/MIT-LICENSE +22 -0
- data/README.textile +54 -0
- data/Rakefile +55 -0
- data/lib/almaz.rb +71 -0
- metadata +80 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2009 James Pozdena
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
h1. Almaz
|
2
|
+
|
3
|
+
<img src='http://jpoz.net/almaz-medium-transparent.png'/>
|
4
|
+
|
5
|
+
Almaz is always watcing.
|
6
|
+
|
7
|
+
h2. Explanation
|
8
|
+
|
9
|
+
Almaz is rack middlware which logs request information to a redis server, under a preset user session variable.
|
10
|
+
|
11
|
+
h2. Example
|
12
|
+
|
13
|
+
h3. Almaz::Capture
|
14
|
+
|
15
|
+
<pre>
|
16
|
+
<code>
|
17
|
+
require 'almaz'
|
18
|
+
|
19
|
+
use Almaz::Capture
|
20
|
+
|
21
|
+
Almaz.redis_db = 7 # default is 0
|
22
|
+
Almaz.session_variable = :user
|
23
|
+
</code>
|
24
|
+
</pre>
|
25
|
+
|
26
|
+
By using Almaz::Capture and setting the session_variable to :user, all request are now logged under 'almaz::user::(session[:user])' in redis. Each user gets a separate list in the redis DB. All request that don't have the session variable :user are logged under 'almaz::user::'.
|
27
|
+
|
28
|
+
h3. Almaz::View
|
29
|
+
|
30
|
+
<pre>
|
31
|
+
<code>
|
32
|
+
require 'almaz'
|
33
|
+
|
34
|
+
use Almaz::View
|
35
|
+
Almaz::View.user('jpoz','password')
|
36
|
+
|
37
|
+
use Almaz::Capture
|
38
|
+
Almaz.session_variable = :user
|
39
|
+
</code>
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
Almaz::View is a separate middleware allows the information saved by Almaz::Capture into redis to be consumed via json. It has two routes:
|
43
|
+
|
44
|
+
# '/almaz' a index of all the keys in the Redis DB
|
45
|
+
# '/almaz/:val' the list of request information for the user who has the session variable value :val
|
46
|
+
|
47
|
+
Both are protected behind basic HTTP authentication. Which is setup by calling Almaz::View.user('username','password').
|
48
|
+
|
49
|
+
h2. Coming soon
|
50
|
+
|
51
|
+
h3. Almaz::Client
|
52
|
+
|
53
|
+
Yet another rack middleware to consume the json given out by Almaz::View.
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
require 'date'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
GEM = 'almaz'
|
8
|
+
GEM_NAME = 'almaz'
|
9
|
+
GEM_VERSION = '0.0.2'
|
10
|
+
AUTHORS = ['James Pozdena', 'Max Ogden', 'Andrew Kurtz', 'Dan Herrera']
|
11
|
+
EMAIL = "jpoz@jpoz.net"
|
12
|
+
HOMEPAGE = "http://github.com/jpoz/almaz"
|
13
|
+
SUMMARY = "Almaz is watching!"
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.name = GEM
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["MIT-LICENSE"]
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.authors = AUTHORS
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
s.require_path = 'lib'
|
27
|
+
s.autorequire = GEM
|
28
|
+
s.add_dependency('sinatra', '>= 0.9.4')
|
29
|
+
s.add_dependency('redis', '>= 0.1.1')
|
30
|
+
s.files = %w(MIT-LICENSE README.textile Rakefile) + Dir.glob("{lib}/**/*")
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
desc "Run specs"
|
36
|
+
Spec::Rake::SpecTask.new do |t|
|
37
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
38
|
+
t.spec_opts = %w(-fs --color)
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
42
|
+
pkg.gem_spec = spec
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "install the gem locally"
|
46
|
+
task :install => [:package] do
|
47
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "create a gemspec file"
|
51
|
+
task :make_spec do
|
52
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
53
|
+
file.puts spec.to_ruby
|
54
|
+
end
|
55
|
+
end
|
data/lib/almaz.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'redis'
|
4
|
+
require 'json'
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
class Almaz
|
8
|
+
@@session_variable = 'session_id'
|
9
|
+
@@redis_db = 0
|
10
|
+
|
11
|
+
def self.session_variable=(val)
|
12
|
+
@@session_variable = val
|
13
|
+
end
|
14
|
+
def self.session_variable; @@session_variable; end
|
15
|
+
|
16
|
+
def self.redis_db=(val)
|
17
|
+
@@redis_db = val
|
18
|
+
end
|
19
|
+
def self.redis_db; @@redis_db; end
|
20
|
+
|
21
|
+
class Capture
|
22
|
+
def initialize(app)
|
23
|
+
@app = app
|
24
|
+
@r = Redis.new(:db => Almaz.redis_db)
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(env)
|
28
|
+
@r.push_tail("almaz::#{Almaz.session_variable}::#{env['rack.session'][Almaz.session_variable]}", "#{Time.now.to_s} #{env['REQUEST_METHOD']} #{env['PATH_INFO']} #{env['QUERY_STRING']}#{env['rack.request.form_hash'].inspect}") rescue nil
|
29
|
+
@app.call(env)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class View < Sinatra::Base
|
34
|
+
|
35
|
+
class << self
|
36
|
+
def user(username, password)
|
37
|
+
@@username = username
|
38
|
+
@@password = password
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
helpers do
|
43
|
+
def protected!
|
44
|
+
response['WWW-Authenticate'] = %(Basic realm="Stats") and \
|
45
|
+
throw(:halt, [401, "Not authorized\n"]) and \
|
46
|
+
return unless authorized?
|
47
|
+
end
|
48
|
+
|
49
|
+
def authorized?
|
50
|
+
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
51
|
+
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [@@username, @@password]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
get '/almaz' do
|
56
|
+
protected!
|
57
|
+
content_type :json
|
58
|
+
@r = Redis.new(:db => Almaz.redis_db)
|
59
|
+
@r.keys('*').to_json
|
60
|
+
end
|
61
|
+
|
62
|
+
get '/almaz/:id' do |id|
|
63
|
+
protected!
|
64
|
+
content_type :json
|
65
|
+
@r = Redis.new(:db => Almaz.redis_db)
|
66
|
+
id = '' if id == 'noid'
|
67
|
+
@r.list_range("almaz::#{Almaz.session_variable}::#{id}", 0, -1).to_json
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: almaz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Pozdena
|
8
|
+
- Max Ogden
|
9
|
+
- Andrew Kurtz
|
10
|
+
- Dan Herrera
|
11
|
+
autorequire: almaz
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2009-12-10 00:00:00 -08:00
|
16
|
+
default_executable:
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: sinatra
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.4
|
27
|
+
version:
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: redis
|
30
|
+
type: :runtime
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.1.1
|
37
|
+
version:
|
38
|
+
description: Almaz is watching!
|
39
|
+
email: jpoz@jpoz.net
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- MIT-LICENSE
|
46
|
+
files:
|
47
|
+
- MIT-LICENSE
|
48
|
+
- README.textile
|
49
|
+
- Rakefile
|
50
|
+
- lib/almaz.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/jpoz/almaz
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Almaz is watching!
|
79
|
+
test_files: []
|
80
|
+
|