IP Shield
A simple Roda plugin that helps you secure your Roda application by only allowing authoriased IP addresses an access to your app/page/resources
Thank you for using ip_shield gem. This gem helps defending your Roda application agenst unwanted requests by only granding authorased IP addresses and access to the app, page or any resources.
| 🏁 Installation & Getting statrted |
|---|
Install the gem and add to the application's Gemfile by executing:
$ bundle add ip_shield
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install ip_shield
| 👔 Usage and examples |
|---|
Add the plugin to your Roda Application
plugin :ip_shield, '0.0.0.0', ['128.0.0.0', '128.0.0.5']
Check if the request IP is authorised by calling authorised_ip? or must_be_authorised_ip. Please bear in mind that authorised_ip? will return a boolean value. must_be_authorised_ip in on the other hand will raise UnauthorisedIP error.
route do |r|
r. ? 'IP is authorised' : 'IP is not authorised'
end
route do |r|
begin
r.
'IP is authorised'
rescue UnauthorisedIP
'IP is not authorised'
end
end
You can add an IP from the request by simply using authorise_ip
route do |r|
r. unless r.
end
Use deauthorise_ip to remove the de-authorise the request IP
route do |r|
r. if r.
end
Note that calling authorised_ip? is not a must. However checking if the IP is authorised will help in preventing you from having a duplicate IPs, or de-authorise an IP that does not exist in the authorised IP list.
| 🛠 Development |
|---|
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.
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.
| 📃 License |
|---|
The gem is available as open source under the terms of the MIT License.