rails-access-control 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d843b1d80d9710cd44bb54b245d99fb696a22b8e1b8d42258645e1dc56219379
4
+ data.tar.gz: e3af643cf5a3b398afa934c5c85cb279a25a7a2c9359ebefaaf328205f7c22d2
5
+ SHA512:
6
+ metadata.gz: 2da932f1429977f1082d8e56a788c01b34111b5009367bfa6aa7f32a5badb0d673be14838ed6b2f33766907e68dfe2a6c4d66d03dc226cf154d377ee8cc0c8f4
7
+ data.tar.gz: dbbfb8acdd8555fd93e21ba8d361ab9ae87a46b6203c4435bf15683d255dd2e1dc1458da9bd4fea055caf9cc64859e01fac030c9e2ace56bda11505dbb6cfe8c
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-04-21
4
+
5
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Brian Haberer
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # RailsAccessControl
2
+
3
+ Basic gem to just unify a small chunk of code I drop in my personal projects to put very basic access control on my locally hosted rails apps.
4
+
5
+ This is by no means a substitution for real access control or security, and should not be used for anything serious.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```bash
12
+ bundle add rails-access-control
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```bash
18
+ gem install rails-access-control
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bhaberer/rails-access-control.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAccessControl
4
+ VERSION = "0.0.3"
5
+ end
@@ -0,0 +1,43 @@
1
+ module RailsAccessControl
2
+ module_function
3
+
4
+ def allowed_hosts_only!
5
+ return unless allowed_hosts.present?
6
+
7
+ Rails.logger.info(
8
+ msg: 'RailsAccessControl IP Enforcement Check',
9
+ requesting_ip: request.remote_ip,
10
+ allowed_request: allowed_request?
11
+ )
12
+
13
+ head(:forbidden) unless allowed_request?
14
+ end
15
+
16
+ def reject_blocked_hosts!
17
+ return unless blocked_hosts.present?
18
+
19
+ Rails.logger.info(
20
+ msg: 'RailsAccessControl IP Enforcement Check',
21
+ requesting_ip: request.remote_ip,
22
+ blocked_request: blocked_request?
23
+ )
24
+
25
+ head(:forbidden) if blocked_request?
26
+ end
27
+
28
+ def blocked_hosts
29
+ ENV.fetch('BLOCKED_HOSTS', '').split(',')
30
+ end
31
+
32
+ def allowed_hosts
33
+ ENV.fetch('ALLOWED_HOSTS', '').split(',')
34
+ end
35
+
36
+ def allowed_request?
37
+ allowed_hosts.include?(request.remote_ip)
38
+ end
39
+
40
+ def blocked_request?
41
+ blocked_hosts.include?(request.remote_ip)
42
+ end
43
+ end
@@ -0,0 +1,8 @@
1
+ module Rails
2
+ module Access
3
+ module Control
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-access-control
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Brian Haberer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-04-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Basic ip access restriction for rails webapps do not use for anything
14
+ important
15
+ email:
16
+ - bhaberer@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - lib/rails-access-control.rb
26
+ - lib/rails-access-control/version.rb
27
+ - sig/rails/access/control.rbs
28
+ homepage: https://github.com/bhaberer/rails-access-control
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ allowed_push_host: https://rubygems.org
33
+ source_code_uri: https://github.com/bhaberer/rails-access-control
34
+ changelog_uri: http://github.com/bhaberer/rails-access-control/blob/main/CHANGELOG.md
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.5.23
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Basic ip access restriction for rails webapps
54
+ test_files: []