cache_bro 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.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +114 -0
  4. data/Rakefile +3 -0
  5. data/app/controllers/cache_bro/application_controller.rb +91 -0
  6. data/app/controllers/cache_bro/audit_events_controller.rb +38 -0
  7. data/app/controllers/cache_bro/flushes_controller.rb +32 -0
  8. data/app/controllers/cache_bro/keys_controller.rb +39 -0
  9. data/app/controllers/cache_bro/purges_controller.rb +38 -0
  10. data/app/helpers/cache_bro/application_helper.rb +63 -0
  11. data/app/models/cache_bro/application_record.rb +6 -0
  12. data/app/models/cache_bro/audit_event.rb +25 -0
  13. data/app/views/cache_bro/audit_events/index.html.erb +39 -0
  14. data/app/views/cache_bro/audit_events/show.html.erb +48 -0
  15. data/app/views/cache_bro/flushes/new.html.erb +19 -0
  16. data/app/views/cache_bro/keys/index.html.erb +36 -0
  17. data/app/views/cache_bro/keys/show.html.erb +57 -0
  18. data/app/views/cache_bro/purges/new.html.erb +17 -0
  19. data/app/views/cache_bro/purges/preview.html.erb +37 -0
  20. data/app/views/cache_bro/shared/_store_tabs.html.erb +9 -0
  21. data/app/views/cache_bro/shared/forbidden.html.erb +3 -0
  22. data/app/views/cache_bro/shared/unsupported.html.erb +3 -0
  23. data/config/routes.rb +18 -0
  24. data/db/migrate/20261115130000_create_cache_bro_audit_events.rb +25 -0
  25. data/lib/cache_bro/audit.rb +25 -0
  26. data/lib/cache_bro/configuration.rb +113 -0
  27. data/lib/cache_bro/engine.rb +25 -0
  28. data/lib/cache_bro/errors.rb +29 -0
  29. data/lib/cache_bro/redis_store.rb +220 -0
  30. data/lib/cache_bro/version.rb +3 -0
  31. data/lib/cache_bro.rb +43 -0
  32. data/lib/generators/cache_bro/install/install_generator.rb +35 -0
  33. data/lib/generators/cache_bro/install/templates/cache_bro.rb +32 -0
  34. metadata +109 -0
@@ -0,0 +1,35 @@
1
+ require "rails/generators"
2
+ require "generators/bro_hub/installable"
3
+
4
+ module CacheBro
5
+ module Generators
6
+ # bin/rails generate cache_bro:install
7
+ class InstallGenerator < Rails::Generators::Base
8
+ # BroHub first (one mount for all the Bro gems), then CacheBro itself.
9
+ include BroHub::Generators::Installable
10
+
11
+ source_root File.expand_path("templates", __dir__)
12
+
13
+ desc "Sets up the BroHub dashboard (CacheBro lives in it), adds the CacheBro initializer and copies the migration."
14
+
15
+ def copy_initializer
16
+ copy_config_once "cache_bro.rb", "config/initializers/cache_bro.rb"
17
+ end
18
+
19
+ def copy_migrations
20
+ rails_command "cache_bro:install:migrations", inline: true
21
+ end
22
+
23
+ def next_steps
24
+ say <<~TEXT
25
+
26
+ CacheBro is installed. Next:
27
+ 1. bin/rails db:migrate
28
+ 2. Say who may do what in config/initializers/cache_bro.rb
29
+ 3. Give your Redis cache store a namespace (config.cache_store = :redis_cache_store, { namespace: "myapp" })
30
+ 4. Visit #{bro_hub_path}/cache_bro (BroHub mounts CacheBro under its own path)
31
+ TEXT
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ # CacheBro lets people browse, inspect and purge the Redis cache from the BroHub dashboard.
2
+ CacheBro.configure do |config|
3
+ # Who may do what. Each lambda gets the signed in user (nil when signed out).
4
+ # Everything is denied until you change these.
5
+ config.can_view_keys = ->(user) { false } # open CacheBro, search keys, see TTL and size, e.g. user&.developer?
6
+ config.can_view_values = ->(user) { false } # reveal what a key holds (audited). Values can hold personal data
7
+ config.can_delete = ->(user) { false } # delete one key
8
+ config.can_purge = ->(user) { false } # delete every key matching a pattern, e.g. user&.lead?
9
+ config.can_flush = ->(user) { false } # delete everything in the store's namespace, e.g. user&.admin?
10
+ config.can_audit = ->(user) { false } # read the audit log
11
+ # Higher includes lower: flush includes purge and delete, purge includes delete, and all of them include
12
+ # view_keys. view_values and audit stand alone.
13
+
14
+ # Which cache stores to manage. The name shows in the UI and the audit log. Only Rails' :redis_cache_store
15
+ # is supported, and it should have a `namespace:` so CacheBro stays out of keys that aren't the cache's.
16
+ # config.stores = { "Rails.cache" => -> { Rails.cache } }
17
+ # config.stores = { "App cache" => -> { Rails.cache }, "Sessions" => -> { MySessionCache } }
18
+
19
+ # Destructive actions that need a typed reason (kept in the audit log): any of :reveal, :delete, :purge, :flush.
20
+ # config.reason_required_for = %i[ purge flush ]
21
+
22
+ # A single purge deletes at most this many keys, then stops (run it again for more).
23
+ # config.max_purge_keys = 100_000
24
+
25
+ # Engine controllers inherit from parent_controller, so its authentication applies.
26
+ # config.parent_controller = "::ApplicationController"
27
+ # config.current_user = ->(controller) { controller.send(:current_user) }
28
+ # config.user_label = ->(user) { user.email }
29
+
30
+ # Reject plain HTTP.
31
+ # config.require_ssl = Rails.env.production?
32
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cache_bro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ruby Dev SRL
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: bro_hub
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.1.2
40
+ description: 'A mountable Rails engine for the BroHub dashboard: search cache keys,
41
+ see TTL and size, reveal a value, delete a key or purge a pattern. Permissions are
42
+ plain lambdas, destructive actions can require a reason, and everything lands in
43
+ an append-only audit log.'
44
+ email:
45
+ - office@rubydev.ro
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - MIT-LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - app/controllers/cache_bro/application_controller.rb
54
+ - app/controllers/cache_bro/audit_events_controller.rb
55
+ - app/controllers/cache_bro/flushes_controller.rb
56
+ - app/controllers/cache_bro/keys_controller.rb
57
+ - app/controllers/cache_bro/purges_controller.rb
58
+ - app/helpers/cache_bro/application_helper.rb
59
+ - app/models/cache_bro/application_record.rb
60
+ - app/models/cache_bro/audit_event.rb
61
+ - app/views/cache_bro/audit_events/index.html.erb
62
+ - app/views/cache_bro/audit_events/show.html.erb
63
+ - app/views/cache_bro/flushes/new.html.erb
64
+ - app/views/cache_bro/keys/index.html.erb
65
+ - app/views/cache_bro/keys/show.html.erb
66
+ - app/views/cache_bro/purges/new.html.erb
67
+ - app/views/cache_bro/purges/preview.html.erb
68
+ - app/views/cache_bro/shared/_store_tabs.html.erb
69
+ - app/views/cache_bro/shared/forbidden.html.erb
70
+ - app/views/cache_bro/shared/unsupported.html.erb
71
+ - config/routes.rb
72
+ - db/migrate/20261115130000_create_cache_bro_audit_events.rb
73
+ - lib/cache_bro.rb
74
+ - lib/cache_bro/audit.rb
75
+ - lib/cache_bro/configuration.rb
76
+ - lib/cache_bro/engine.rb
77
+ - lib/cache_bro/errors.rb
78
+ - lib/cache_bro/redis_store.rb
79
+ - lib/cache_bro/version.rb
80
+ - lib/generators/cache_bro/install/install_generator.rb
81
+ - lib/generators/cache_bro/install/templates/cache_bro.rb
82
+ homepage: https://www.rubydev.ro
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ allowed_push_host: https://rubygems.org
87
+ rubygems_mfa_required: 'true'
88
+ homepage_uri: https://www.rubydev.ro
89
+ source_code_uri: https://github.com/rubydevro/cache_bro
90
+ bug_tracker_uri: https://github.com/rubydevro/cache_bro/issues
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '3.2'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 4.0.10
106
+ specification_version: 4
107
+ summary: Browse, inspect and purge your Rails Redis cache from the browser, with every
108
+ action audited.
109
+ test_files: []