f4w-rack 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +20 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/f4w-rack.gemspec +29 -0
- data/lib/f4w/logging/app_data.rb +15 -0
- data/lib/f4w/logging/entry.rb +69 -0
- data/lib/f4w/logging/error_data.rb +6 -0
- data/lib/f4w/rack/logger.rb +37 -0
- data/lib/f4w/rack/oauth2.rb +37 -0
- data/lib/f4w/rack/version.rb +5 -0
- data/lib/f4w/rack.rb +7 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ad35b1fc323072c8c9bf4c6d239ede885a90d59
|
4
|
+
data.tar.gz: 177811be343d378b03bf1922e61f69888127143a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 768f3cea3eff162ca162295e2e52d799c1e7d87789b84cef0fd4297f50ce8d973db3ed4ea744522fb3a65f300679fff3bc151fd3be3e0c1607e6d5a016a85b52
|
7
|
+
data.tar.gz: e83f6f3501d3ee52cbcab1b92c2125c89ed36a792a1f45e0835e1155132161dd667edf6c5710a0cd00c38e2879b3cfa631234325cac577530b64c50173b2ae49
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# F4w::Rack
|
2
|
+
|
3
|
+
This gems offers some rack middlewares specifically developed for FACTS4WORKERS.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'f4w-rack'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install f4w-rack
|
20
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "f4w/rack"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/f4w-rack.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'f4w/rack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "f4w-rack"
|
8
|
+
spec.version = F4w::Rack::VERSION
|
9
|
+
spec.authors = ["Alessio Caiazza"]
|
10
|
+
spec.email = ["nolith@abisso.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{A collection of rack middleware}
|
13
|
+
spec.description = %q{A collection of rack middleware related to FACTS4WORKERS EU project}
|
14
|
+
spec.homepage = "https://gitlab.com/unifi-f4w/f4w-rack"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "rack", ">= 1.6.4"
|
24
|
+
spec.add_dependency "oauth2-checker", "~> 0.2.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'f4w/logging/app_data'
|
3
|
+
require 'f4w/logging/error_data'
|
4
|
+
|
5
|
+
module F4w
|
6
|
+
module Logging
|
7
|
+
class Entry
|
8
|
+
VERSION = 1
|
9
|
+
|
10
|
+
attr_accessor :app_data_log_record
|
11
|
+
attr_accessor :error_log_record
|
12
|
+
attr_accessor :invocation_zoned_date_time
|
13
|
+
attr_accessor :service_uri
|
14
|
+
attr_accessor :type_of_call
|
15
|
+
attr_accessor :user_id
|
16
|
+
|
17
|
+
def initialize(uri, type_of_call, user_id, app_data, error_data)
|
18
|
+
@service_uri = uri
|
19
|
+
@type_of_call = type_of_call
|
20
|
+
@app_data_log_record = app_data
|
21
|
+
@error_log_record = error_data
|
22
|
+
@user_id = user_id
|
23
|
+
|
24
|
+
@invocation_zoned_date_time = DateTime.now.iso8601(3)
|
25
|
+
end
|
26
|
+
|
27
|
+
def as_json(options=nil)
|
28
|
+
json = {
|
29
|
+
'invocationZonedDateTime' => @invocation_zoned_date_time,
|
30
|
+
'serviceURI' => @service_uri,
|
31
|
+
'tyepeOfCall' => @type_of_call
|
32
|
+
}
|
33
|
+
|
34
|
+
json['appDataLogRecord'] = @app_data_log_record.as_json(options) unless @app_data_log_record.nil?
|
35
|
+
json['errorLogRecord'] = @error_log_record.as_json(options) unless @error_log_record.nil?
|
36
|
+
json['userID'] = @user_id unless @user_id.nil?
|
37
|
+
|
38
|
+
json
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.request_start(uri, user_id, data = nil)
|
42
|
+
log_request(uri, '1', user_id, data)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.request_end(uri, user_id, data = nil)
|
46
|
+
log_request(uri, '2', user_id, data)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.error(uri, user_id, error_context, error_message, data = nil)
|
50
|
+
log_request(uri, '-1', user_id, data, error_context, error_message)
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
"ver=#{VERSION} log=#{to_json}"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def self.log_request(uri, type, user_id, data = nil, error_context=nil, error_message=nil)
|
60
|
+
error = if !error_context.nil? && !error_message.nil?
|
61
|
+
ErrorData.new(error_context, error_message)
|
62
|
+
else
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
new(uri, type, user_id, data.nil? ? nil : AppData.new(data), error)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'f4w/logging/entry'
|
3
|
+
|
4
|
+
module F4w
|
5
|
+
module Rack
|
6
|
+
class Logger
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
req = ::Rack::Request.new(env)
|
13
|
+
requested_uri = req.url()
|
14
|
+
user_id = env['rack.oauth2.resource_owner']
|
15
|
+
data = app_data(env)
|
16
|
+
puts F4w::Logging::Entry.request_start(requested_uri, user_id, data)
|
17
|
+
begin
|
18
|
+
status, headers, body = @app.call(env)
|
19
|
+
|
20
|
+
[status, headers, body]
|
21
|
+
rescue Exception => e
|
22
|
+
puts F4w::Logging::Entry.error(requested_uri, user_id, 'uncatched_exception', e.message, data.merge(error_class: e.class))
|
23
|
+
throw e
|
24
|
+
ensure
|
25
|
+
puts F4w::Logging::Entry.request_end(requested_uri, user_id, data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def app_data(env)
|
32
|
+
env.dup.delete_if { |key,_| !(key =~/^HTTP_/) || key == 'HTTP_COOKIE' }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'oauth2/checker'
|
3
|
+
|
4
|
+
module F4w
|
5
|
+
module Rack
|
6
|
+
class Oauth2
|
7
|
+
def initialize(app, client_id, client_secret, options={})
|
8
|
+
@app = app
|
9
|
+
@client_id = client_id
|
10
|
+
@client_secret = client_secret
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
req = ::Rack::Request.new(env)
|
16
|
+
if req.params['access_token']
|
17
|
+
req.logger.debug('getting Oauth2 resource_owner') unless req.logger.nil?
|
18
|
+
valid, resource_owner = oauth2_checker.validate(req.params['access_token'])
|
19
|
+
env['rack.oauth2.valid_token'] = valid
|
20
|
+
env['rack.oauth2.resource_owner'] = resource_owner
|
21
|
+
req.logger.debug("resource_owner: #{resource_owner}") unless req.logger.nil?
|
22
|
+
else
|
23
|
+
env['rack.oauth2.valid_token'] = false
|
24
|
+
end
|
25
|
+
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def oauth2_checker
|
32
|
+
::OAuth2::Checker.new(@client_id,@client_secret,@options)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/f4w/rack.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: f4w-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessio Caiazza
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-15 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.6.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oauth2-checker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: A collection of rack middleware related to FACTS4WORKERS EU project
|
84
|
+
email:
|
85
|
+
- nolith@abisso.org
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- f4w-rack.gemspec
|
99
|
+
- lib/f4w/logging/app_data.rb
|
100
|
+
- lib/f4w/logging/entry.rb
|
101
|
+
- lib/f4w/logging/error_data.rb
|
102
|
+
- lib/f4w/rack.rb
|
103
|
+
- lib/f4w/rack/logger.rb
|
104
|
+
- lib/f4w/rack/oauth2.rb
|
105
|
+
- lib/f4w/rack/version.rb
|
106
|
+
homepage: https://gitlab.com/unifi-f4w/f4w-rack
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.5.1
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A collection of rack middleware
|
129
|
+
test_files: []
|