rack-rejector 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/.rubocop.yml +31 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.md +25 -0
- data/README.md +54 -0
- data/Rakefile +9 -0
- data/lib/rack/rejector/version.rb +5 -0
- data/lib/rack/rejector.rb +47 -0
- data/rack-rejector.gemspec +26 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 377f7d47b090d26482b148d09c841ffe89bbc1b7
|
4
|
+
data.tar.gz: fc95d7c85531c4cb5735ad805641eb54675ea7f1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 56a2b71ce669542e100d8ed35849c860b435eb09a242ba42e563907deed5fb3ee7d087d32b0bd9c0abf8cb1dfd933378a71134d77ad83968d3722c3c83f65abd
|
7
|
+
data.tar.gz: 47d112681eb33eb75f61b272e45a656f14c06fa96af860a3f197363c1bfe7da007e834bbb6a094f245dbfaad190d6b2f58c477cdf3ec3e0440112a4758d39295
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Common configuration.
|
2
|
+
AllCops:
|
3
|
+
TargetRubyVersion: 2.3
|
4
|
+
Exclude:
|
5
|
+
- db/**/*
|
6
|
+
- config/**/*
|
7
|
+
- tmp/**/*
|
8
|
+
- vendor/**/*
|
9
|
+
- apps/accounting_records_csv/application.rb
|
10
|
+
- apps/public_api/application.rb
|
11
|
+
|
12
|
+
Documentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
AbcSize:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
DoubleNegation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
NumericLiterals:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
SingleLineBlockParams:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
FrozenStringLiteralComment:
|
31
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Copyright © `2016` `InVision AG`
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person
|
7
|
+
obtaining a copy of this software and associated documentation
|
8
|
+
files (the “Software”), to deal in the Software without
|
9
|
+
restriction, including without limitation the rights to use,
|
10
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the
|
12
|
+
Software is furnished to do so, subject to the following
|
13
|
+
conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Rack::Rejector
|
2
|
+
|
3
|
+
This gem is a Rack Middleware to reject requests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rack-rejector'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```Shell
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```Shell
|
22
|
+
$ gem install rack-rejector
|
23
|
+
```
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
You still have to write the conditions for rejection on your own.
|
27
|
+
The rest is handled by this gem. It will reject the request if the
|
28
|
+
given block evaluates to true. This example would grant access only to
|
29
|
+
GET requests:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
use Rack::Rejector, body: 'No Teapot' do |request, options|
|
33
|
+
!request.get?
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Available options are:
|
38
|
+
```ruby
|
39
|
+
options.body = "I'm a teapot" # Default: '503 SERVICE UNAVAILABLE'
|
40
|
+
options.code = 418 # Default: 503
|
41
|
+
options.headers = { 'x-teapot' => 'teapot' } # Default: {}
|
42
|
+
```
|
43
|
+
|
44
|
+
You can set them either at initialization or override them in the block.
|
45
|
+
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bundle` to install dependencies. Then, run `bundle exec rake` to run the tests.
|
50
|
+
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ivx/rack-rejector.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rack/rejector/version'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Rejector
|
5
|
+
def initialize(app, options = {}, &block)
|
6
|
+
default_options = {
|
7
|
+
code: 503,
|
8
|
+
body: '503 SERVICE UNAVAILABLE',
|
9
|
+
headers: {}
|
10
|
+
}
|
11
|
+
|
12
|
+
@app = app
|
13
|
+
@options = default_options.merge(options)
|
14
|
+
@block = block
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
request = Rack::Request.new(env)
|
19
|
+
options = @options.clone
|
20
|
+
reject?(request, options) ? reject!(request, options) : @app.call(env)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def reject?(request, options)
|
26
|
+
@block.call(request, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def reject!(_request, options)
|
30
|
+
[status(options), headers(options), body(options)]
|
31
|
+
end
|
32
|
+
|
33
|
+
def headers(options)
|
34
|
+
headers = {}
|
35
|
+
headers['Content-Type'] = 'text/html; charset=utf-8'
|
36
|
+
headers.merge(options[:headers])
|
37
|
+
end
|
38
|
+
|
39
|
+
def status(options)
|
40
|
+
options[:code]
|
41
|
+
end
|
42
|
+
|
43
|
+
def body(options)
|
44
|
+
Array(options[:body])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/rejector/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rack-rejector'
|
8
|
+
spec.version = Rack::Rejector::VERSION
|
9
|
+
spec.authors = ['Tristan Druyen', 'Maik Röhrig']
|
10
|
+
spec.email = ['tristan.druyen@invision.de',
|
11
|
+
'maik.roehrig@invision.de']
|
12
|
+
|
13
|
+
spec.summary = 'This gem is a Rack Middleware to reject requests.'
|
14
|
+
spec.homepage = 'https://github.com/ivx/rack-rejector'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`
|
17
|
+
.split("\x0")
|
18
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'rack'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'rubocop'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-rejector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tristan Druyen
|
8
|
+
- Maik Röhrig
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.12'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.12'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rubocop
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description:
|
85
|
+
email:
|
86
|
+
- tristan.druyen@invision.de
|
87
|
+
- maik.roehrig@invision.de
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".rubocop.yml"
|
95
|
+
- ".ruby-version"
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.md
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- lib/rack/rejector.rb
|
101
|
+
- lib/rack/rejector/version.rb
|
102
|
+
- rack-rejector.gemspec
|
103
|
+
homepage: https://github.com/ivx/rack-rejector
|
104
|
+
licenses: []
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: This gem is a Rack Middleware to reject requests.
|
126
|
+
test_files: []
|