access_watch_rails 0.0.4
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 +7 -0
- data/.gitignore +11 -0
- data/access_watch_rails.gemspec +35 -0
- data/lib/access_watch/logger.rb +55 -0
- data/lib/access_watch/rails_version.rb +3 -0
- data/lib/access_watch_rails.rb +6 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b0a9aa00f27ae2ded551891dca8590df4576c95
|
4
|
+
data.tar.gz: 12b33b039dce73dfab374fe64471e12e32688060
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5680ce067d772bee45baf7fbc619ce13d0980f74901eb621ed1d9a72dcc187c37871d83940cb6b252acadb68bd279e3eb3adfff4680afcbd771741aa21b9568
|
7
|
+
data.tar.gz: 95fd44851a43501ed9d5256f311f260e7bf0061868d737cd08863c66f8bab5f527343b55ad2acf2dc1d4b6b58a84e94d9f18fb22d2b7a85da21bfc4b1f3877b1
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "access_watch/rails_version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "access_watch_rails"
|
8
|
+
spec.version = AccessWatch::RAILS_VERSION
|
9
|
+
spec.authors = ["Alexis Bernard"]
|
10
|
+
spec.email = ["alexis@bernard.io"]
|
11
|
+
|
12
|
+
spec.summary = "A Rails library to log and analyse Rails HTTP requests using the Access Watch cloud service."
|
13
|
+
spec.description = "A Rails library to log and analyse Rails HTTP requests using the Access Watch cloud service."
|
14
|
+
spec.homepage = "https://access.watch/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_dependency "access_watch", ">= 0.0.2"
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module AccessWatch
|
2
|
+
class Logger
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@client = AccessWatch::Client.new(config)
|
7
|
+
end
|
8
|
+
|
9
|
+
def record(request, response)
|
10
|
+
post_request(
|
11
|
+
time: Time.now.utc,
|
12
|
+
address: request.remote_ip,
|
13
|
+
host: request.host,
|
14
|
+
request: {
|
15
|
+
# TODO: Check if is SERVER_PROTOCOL comes from client browser
|
16
|
+
# "protocol": "HTTP/1.1",
|
17
|
+
method: request.method,
|
18
|
+
scheme: URI(request.original_url).scheme,
|
19
|
+
host: request.host,
|
20
|
+
port: request.port,
|
21
|
+
url: request.path,
|
22
|
+
headers: extract_http_headers(request.headers)
|
23
|
+
},
|
24
|
+
response: {status: response.status},
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract_http_headers(headers)
|
29
|
+
headers.reduce({}) do |hash, (name, value)|
|
30
|
+
if name.index("HTTP_") == 0 && name != "HTTP_COOKIE"
|
31
|
+
hash[format_header_name(name)] = value
|
32
|
+
end
|
33
|
+
hash
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def format_header_name(name)
|
38
|
+
name.sub(/^HTTP_/, '').sub("_", " ").titleize.sub(" ", "-")
|
39
|
+
end
|
40
|
+
|
41
|
+
#######################
|
42
|
+
### Private methods ###
|
43
|
+
#######################
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def post_request(data)
|
48
|
+
post_async("log".freeze, data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def post_async(path, data)
|
52
|
+
Thread.new { client.post(path, data) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: access_watch_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexis Bernard
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: access_watch
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.2
|
55
|
+
description: A Rails library to log and analyse Rails HTTP requests using the Access
|
56
|
+
Watch cloud service.
|
57
|
+
email:
|
58
|
+
- alexis@bernard.io
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- access_watch_rails.gemspec
|
65
|
+
- lib/access_watch/logger.rb
|
66
|
+
- lib/access_watch/rails_version.rb
|
67
|
+
- lib/access_watch_rails.rb
|
68
|
+
homepage: https://access.watch/
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata:
|
72
|
+
allowed_push_host: https://rubygems.org
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.5.1
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: A Rails library to log and analyse Rails HTTP requests using the Access Watch
|
93
|
+
cloud service.
|
94
|
+
test_files: []
|
95
|
+
has_rdoc:
|