cors-config 0.2.3

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: 9a0ed7e1e8a06f36e4eedc04b2a24fc6cd02d4c0
4
+ data.tar.gz: d7ea5eb2a80bda41520a4964c79ff6881e66592c
5
+ SHA512:
6
+ metadata.gz: bef49b57271cd9cf5421cbd27b751a9afc35d69d2a904eae2206330f6ce557b3e676e5e258d3a250c7037f74636ac9d11a14197353f7b86cb6ac85fddacef0f6
7
+ data.tar.gz: ab0eba6b04e56cd03413c825382f446838c2165c16ad6a73668e35340d3a8228184942b294cd29595ebafa27742103f3a2ca020ffd3a09f8d380917e6b79b6f0
data/.byebug_history ADDED
@@ -0,0 +1,256 @@
1
+ c
2
+ s
3
+ c
4
+ s
5
+ quit
6
+ cors.to_yaml
7
+ cors_result_object
8
+ c
9
+ quit
10
+ self.use
11
+ self.inspect
12
+ self
13
+ quit
14
+ stack.use
15
+ stack
16
+ quit
17
+ cors.call(env)
18
+ cors.call(env(
19
+ env
20
+ cors
21
+ n
22
+ cors
23
+ n
24
+ @user_config
25
+ s
26
+ quit
27
+ cors_config
28
+ quit
29
+ @user_config
30
+ s
31
+ quit
32
+ error
33
+ n
34
+ s
35
+ quit
36
+ n
37
+ @user_config
38
+ s
39
+ quit
40
+ config
41
+ n
42
+ s
43
+ c
44
+ e
45
+ n
46
+ @app
47
+ n
48
+ s
49
+ rack_app
50
+ quit
51
+ @app
52
+ s
53
+ @rack_app
54
+ quit
55
+ @rack_app
56
+ quit
57
+ quity
58
+ app
59
+ error
60
+ n
61
+ env
62
+ s
63
+ quit
64
+ error.message
65
+ error
66
+ n
67
+ env
68
+ s
69
+ quit
70
+ env
71
+ s
72
+ quit
73
+ cors_config.call({})
74
+ c
75
+ env
76
+ cors.call(env)
77
+ cors.call
78
+ env
79
+ n
80
+ cors
81
+ n
82
+ s
83
+ c
84
+ quit
85
+ cors.empty?
86
+ cors.nil?
87
+ cors
88
+ n
89
+ s
90
+ c
91
+ n
92
+ env
93
+ cors
94
+ n
95
+ config
96
+ @app
97
+ env
98
+ n
99
+ s
100
+ quit
101
+ cors_config.call({)
102
+ c
103
+ cors_result_object
104
+ c
105
+ n
106
+ quit
107
+ cors === cors_result_object
108
+ quit
109
+ cors.to_yaml
110
+ cors.to_s
111
+ cors.tos
112
+ cors
113
+ JSON.load(JSON.dump(cors))
114
+ JSON.dump(cors)
115
+ require 'json'
116
+ JSON.dump(cors)
117
+ c
118
+ cors_result_object
119
+ c
120
+ quit
121
+ Marshal.load(cors_result_object)
122
+ quit
123
+ Marshal.load(cors_result_object)
124
+ Marshall.load(cors_result_object)
125
+ cors_result_object
126
+ cors
127
+ quit
128
+ Marshal.dump(cors)
129
+ Marshal
130
+ Marshall
131
+ require 'marshal'
132
+ Marshall.dump(cors)
133
+ Marshall.dump cors
134
+ cors
135
+ quit
136
+ YAML.load_file('spec/support/success.yml')
137
+ quit
138
+ cors.to_yaml
139
+ cors.to_yaml.split
140
+ cors.to_yaml
141
+ cors.to_yaml.to_s.strip!
142
+ cors.to_yaml.to_s.strip
143
+ cors.to_s
144
+ cors.to_yaml.s
145
+ cors.to_yaml
146
+ YAML::parse(cors.to_yaml).children
147
+ YAML::parse(cors.to_yaml.strip).children
148
+ hash = YAML.load(cors.to_yaml.strip)
149
+ hash = YAML.load(cors.to_yaml.strip.split)
150
+ hash = YAML.load(cors.to_yaml.strip)
151
+ cors.to_yaml
152
+ hash = YAML.load(cors.to_yaml)
153
+ hash = YAML.load(cors)
154
+ hash.inspect
155
+ hash.app
156
+ hash[app]
157
+ hash = YAML.load(cors.to_yaml)
158
+ YAML.load(cors.to_yaml)
159
+ YAML::parse(cors.to_yaml)
160
+ YAML::parse(cors.to_yaml).children
161
+ YAML::parse(cors.to_yaml).methods
162
+ YAML::parse(cors.to_yaml)
163
+ YAML::parse(cors.to_yaml)[0]
164
+ YAML::parse(cors.to_yaml)
165
+ cors.to_yaml
166
+ cors.yaml
167
+ test[0]
168
+ test = Array[cors]
169
+ Array[cors]
170
+ cors.to_yaml
171
+ cors.yaml
172
+ JSON.dump cors
173
+ JSON.dump_object
174
+ cors.dump_oject
175
+ cors.to_json
176
+ require 'json'
177
+ cors.attributes
178
+ cors.instance_variable_get(:all_resources)
179
+ cors.instance_variable_get(@all_resources)
180
+ cors.instance_variable_get(all_resources)
181
+ cors.in
182
+ cors.instance_variable_get(:headers)
183
+ cors.instance_variable_get('headers')
184
+ cors.instance_variables_get('headers')
185
+ cors.instance_variables_get(:headers)
186
+ cors.instace_variables_get(:headers)
187
+ cors.instace_variables_get(:headers0
188
+ cors.instace_variables_get
189
+ cors.instace_variables
190
+ cors.to_yaml.include?('path:')
191
+ cors.psych_to_yaml
192
+ cors.to_yaml
193
+ cors.to_yaml_properties
194
+ cors.methods
195
+ cors.attributes_name
196
+ cors.attributes_names
197
+ cors.to_hash
198
+ cors.to_h
199
+ cors.inspect.class
200
+ cors.inspect
201
+ cors.to_yaml
202
+ cors.debug
203
+ cors.resource_for_path
204
+ cors.
205
+ cors.all_resources
206
+ cors..all_resources
207
+ cors.instance_variables.all_resources
208
+ cors.instance_variables.all_resource
209
+ cors.instance_variables
210
+ cors.methods
211
+ cors.class
212
+ c
213
+ Rack::Cors.name
214
+ Rack::Cor.name
215
+ Rack::Cor.nam
216
+ Rack::Cors.methods
217
+ Rack::Cors
218
+ cors.class
219
+ cors.display
220
+ cors.methods
221
+ cors.hash
222
+ cors.public_methods
223
+ cors.public_instance_methods
224
+ cors.inspect
225
+ cors.resources
226
+ cors.inspect
227
+ cors[0]
228
+ cors
229
+ cors.resource_for_path('/status')
230
+ cors.to_yaml
231
+ cors.all_resources
232
+ cors.allow
233
+ cors.methods
234
+ cors[:app]
235
+ cors['app']
236
+ cors.app
237
+ cors.headers
238
+ cors[headers]
239
+ cors
240
+ c
241
+ quit
242
+ config
243
+ c
244
+ quit
245
+ config
246
+ c
247
+ s
248
+ @config
249
+ quit
250
+ @config
251
+ c
252
+ n
253
+ app
254
+ s
255
+ n
256
+ quit
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ .byebug_history
2
+ *tgz
3
+ test_tfa.sh
4
+ test_production.sh
5
+ iut-list
6
+ juddi-distro-*
7
+ *.swo
8
+ *.zip
9
+ *.tar.gz
10
+ *.swp
11
+ *.gem
12
+ *.rbc
13
+ *.log
14
+ /Gemfile.lock
15
+ /.config
16
+ /coverage/
17
+ /InstalledFiles
18
+ /pkg/
19
+ /spec/reports/
20
+ /spec/examples.txt
21
+ /test/tmp/
22
+ /test/version_tmp/
23
+ /tmp/
24
+ .DS_Store
25
+
26
+ ## Specific to RubyMotion:
27
+ .dat*
28
+ .repl_history
29
+ build/
30
+
31
+ ## Documentation cache and generated files:
32
+ /.yardoc/
33
+ /_yardoc/
34
+ /doc/
35
+ /rdoc/
36
+
37
+ ## Environment normalisation:
38
+ /.bundle/
39
+ /vendor/bundle
40
+ /lib/bundler/man/
41
+
42
+ # for a library or gem, you might want to ignore these files since the code is
43
+ # intended to run in multiple environments; otherwise, check them in:
44
+ # Gemfile.lock
45
+ # .ruby-version
46
+ # .ruby-gemset
47
+
48
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
49
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ cors-config
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at dane.balia@hetzner.co.za. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cors-config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 daneb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Cors Config
2
+
3
+ Middleware that allows you to configure CORS via a YAML file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cors-config'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cors-config
20
+
21
+ ## Usage
22
+
23
+ Default configuration location and name is $ROOT/config/cors.yml.
24
+
25
+ In config.ru
26
+
27
+ ```
28
+ use Cors::Config
29
+ use Cors::Config, 'config/my_config.yml'
30
+ ```
31
+
32
+ Also the configuration is expected in config/cors.yml (for now).
33
+
34
+ ```
35
+ cors:
36
+ products:
37
+ origins: '*'
38
+ resource: '/products'
39
+ headers: 'any'
40
+ methods: 'any'
41
+ status:
42
+ origins: '*'
43
+ resource: '/status'
44
+ headers: 'any'
45
+ methods: 'any'
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ Please send feedback and comments to the author at:
51
+
52
+ Dane-Garrin Balia <dane.balia@hetzner.co.za>
53
+
54
+ This gem is sponsored by Hetzner (Pty) Ltd - http://hetzner.co.za
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cors/config"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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 'cors/config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cors-config"
8
+ spec.version = Cors::Config::VERSION
9
+ spec.authors = ["daneb"]
10
+ spec.email = ["dane.balia@hetzner.co.za"]
11
+
12
+ spec.summary = %q{CORS Configuration Gem.}
13
+ spec.homepage = "http://github.com/hetznerZA/cors-config"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rack-cors", "~> 0.4.0"
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.5"
25
+ spec.add_development_dependency "rack", "~> 2.0"
26
+ end
@@ -0,0 +1,5 @@
1
+ module Cors
2
+ class Config
3
+ VERSION = "0.2.3"
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ require "cors/config/version"
2
+ require 'rack/cors'
3
+ require 'yaml'
4
+ require 'byebug'
5
+
6
+ module Cors
7
+ class Config
8
+ class Error < StandardError; end
9
+ attr_accessor :app, :user_config
10
+
11
+ def initialize(app, user_config = 'config/cors.yml')
12
+ @app = app
13
+ @user_config = user_config
14
+ end
15
+
16
+ def call(env)
17
+ config = configure_cors
18
+ return @app.call(env) if config.empty?
19
+ cors = generate_cors_rules_from_config(config)
20
+ return @app.call(env) if cors.nil?
21
+ cors.call(env)
22
+ rescue => error
23
+ Error.new("Unexpected error #{error.message}")
24
+ end
25
+
26
+ private
27
+ def generate_cors_rules_from_config(config)
28
+ cors = Rack::Cors.new(@app, {}) do
29
+ config['cors'].each { |rule|
30
+ allow do
31
+ origins rule[1]['origins']
32
+ resource rule[1]['resource'], :headers => rule[1]['headers'].to_sym, :methods => rule[1]['headers'].to_sym
33
+ end
34
+ }
35
+ end
36
+ end
37
+
38
+ def configure_cors
39
+ return [] unless File.exist?(@user_config)
40
+ YAML.load_file(@user_config)
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cors-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - daneb
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-cors
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.0
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.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description:
84
+ email:
85
+ - dane.balia@hetzner.co.za
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".byebug_history"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - cors-config.gemspec
104
+ - lib/cors/config.rb
105
+ - lib/cors/config/version.rb
106
+ homepage: http://github.com/hetznerZA/cors-config
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: CORS Configuration Gem.
130
+ test_files: []