attacked 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b04ffb22bcc29d0d939bd2eb5e1c22c605386a9ffce1f2aa59bc919dc1850ae
4
- data.tar.gz: c6b5e545c137f187130a49edb59c0ab7a07c31402d025f3eba9667ef46b158f4
3
+ metadata.gz: aeb323131d526113f62aa3a7acfa4842a4fcd8d9c1ba79fddab258fc7521f3d3
4
+ data.tar.gz: f957cedf0d9501e5e0405ffd2412f90dae7d4a75969e5be185678f0fb3a775ab
5
5
  SHA512:
6
- metadata.gz: ae74f489a4fb6a25c7697330ae25f297987fd0824cef1064baf7c632dcf2b8222b6224dc86fc05467b0ca6330e626b065807899d606ce73776c13d6fd7960be0
7
- data.tar.gz: ab911ef29e7fce5539e3380d867fd77cad9b328dfb1a391b912f968af2357743e6579e91929eeb9cd1c1fa917cf5fe0a39fd2e05fd76172b24a73f96d71f7a91
6
+ metadata.gz: ae73b71d77ef6133c287581dbfabe9edf29fa89562c85a4d7f2fc3e9b9e4968819617d5b27fb39744e6046b26158a753e1aea958c635f779bc7228c383679289
7
+ data.tar.gz: 23523e71a0224c746be7416fad7ca46811635111b839228a573e6c37c0b7e246c103514d4aa1725516d72af9db80a67fd748a274711bfd5d993e9a5b584118bd
data/README.md CHANGED
@@ -39,13 +39,21 @@ Install [rack-attack](https://github.com/rack/rack-attack) as usual and setup a
39
39
  # Block attacks from IPs
40
40
  # To block an IP: Attacked::BlockedIpAddress.block("1.2.3.4")
41
41
  # To unblock an IP: Attacked::BlockedIpAddress.unblock("1.2.3.4")
42
- blocklist("block ips") do |req|
42
+ blocklist("block_ips") do |req|
43
43
  Attacked::BlockedIpAddress.blocked?(req.ip)
44
44
  end
45
45
  ```
46
46
 
47
47
  Please note that `Attacked` defaults to using the `Rails.cache` when caching blocked
48
- IP addresses. As such you must setup a cache store for your application.
48
+ IP addresses. As such you must setup a cache store for your application. If you'd like
49
+ to setup a custom cache store you can create a `config/initializers/attacked.rb` and configure
50
+ the cache store:
51
+
52
+ ```ruby
53
+ Attacked.config do |config|
54
+ config.cache = ActiveSupport::Cache::MemCacheStore.new("localhost", "server-downstairs.localnetwork:8229")
55
+ end
56
+ ```
49
57
 
50
58
  ### Usage
51
59
 
@@ -15,7 +15,7 @@ module Attacked
15
15
  }
16
16
 
17
17
  def self.blocked?(ip_address)
18
- Rails.cache.read(blocked_cache_key(ip_address)) ? true : false
18
+ Attacked.cache.read(blocked_cache_key(ip_address)) ? true : false
19
19
  end
20
20
 
21
21
  def self.block(ip_address)
@@ -34,19 +34,19 @@ module Attacked
34
34
  private
35
35
 
36
36
  def create_in_cache
37
- Rails.cache.write(blocked_cache_key(ip_address), true)
37
+ Attacked.cache.write(blocked_cache_key(ip_address), true)
38
38
  end
39
39
 
40
40
  def remove_from_cache
41
- Rails.cache.delete(blocked_cache_key(ip_address))
41
+ Attacked.cache.delete(blocked_cache_key(ip_address))
42
42
  end
43
43
 
44
44
  def self.blocked_cache_key(ip_address)
45
- "attacked_blocked_ip #{ip_address}"
45
+ "attacked_blocked_ip_#{ip_address}"
46
46
  end
47
47
 
48
48
  def blocked_cache_key(ip_address)
49
- "attacked_blocked_ip #{ip_address}"
49
+ "attacked_blocked_ip_#{ip_address}"
50
50
  end
51
51
  end
52
52
  end
@@ -1,7 +1,7 @@
1
1
  class CreateAttackedBlockedIpAddresses < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :attacked_blocked_ip_addresses do |t|
4
- t.string :ip_address, index: { unique: true }
4
+ t.string :ip_address, index: { unique: true, name: "idx_attacked_blocked_ip_on_ip" }
5
5
  t.text :description
6
6
  t.timestamps
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Attacked
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/attacked.rb CHANGED
@@ -3,4 +3,14 @@ require "attacked/engine"
3
3
 
4
4
  module Attacked
5
5
  # Your code goes here...
6
+
7
+ mattr_writer :cache
8
+
9
+ def self.config
10
+ yield self
11
+ end
12
+
13
+ def self.cache
14
+ @@cache || Rails.cache
15
+ end
6
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attacked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murray Summers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-06 00:00:00.000000000 Z
11
+ date: 2025-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -57,7 +57,7 @@ metadata:
57
57
  homepage_uri: https://github.com/murraysum/attacked
58
58
  source_code_uri: https://github.com/murraysum/attacked
59
59
  changelog_uri: https://github.com/murraysum/attacked
60
- post_install_message:
60
+ post_install_message:
61
61
  rdoc_options: []
62
62
  require_paths:
63
63
  - lib
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.0.3
76
- signing_key:
75
+ rubygems_version: 3.4.10
76
+ signing_key:
77
77
  specification_version: 4
78
78
  summary: Manage a persisted list of blocked IP addresses
79
79
  test_files: []