redaction 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8111bc43a6fc2d4dbd6224b80664d7410bf62780c6d609b5532c9043ee3032fa
4
- data.tar.gz: 8ab8dcfa4d70432f19c179eb77e4f9093a12b1f8261c7aad1fe0800e372bda30
3
+ metadata.gz: 8c7c1ab9e4c83779e70bd6cc332671fd69a007281c34b4c64ea4ce309ca1eb49
4
+ data.tar.gz: b2c8ef0998df228f1062b91e6a3d4cff740071c3d41cb5082d34431254e2b446
5
5
  SHA512:
6
- metadata.gz: d2479196f571dfc27a21f48147d488b08140eaa4afa0821467d0d5d04b4b3f9ae3295c8db4b316d70fe7be39848de8925a6ebb84cc5533deed1c6171ddf79e14
7
- data.tar.gz: 135321f897acb08d60cac36b3c8413ea9bd2c42280cee09bc30ac9ee999099009c7c4f8d735c128f8b1326e64d9beac1107e8d959748ea36eaba956373a9abb2
6
+ metadata.gz: 1ec8127de732264971eef233c3ee8366db0eb660e84b427901180729c0f5d7c253d227c3591c6a3ab403b1e930dbcf709935d224382dd4cdc79b2736fee9056e
7
+ data.tar.gz: 0fb500148ce2f328f96d59bf0ff497bc908a6d2641e363d9fa5e7f9d6301cc0c2a1ba429025c6986c91103d0ae70036b11198c20225921cb9b5628389ab1c853
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Redaction
2
+ [![Gem Version](https://badge.fury.io/rb/redaction.svg)](https://badge.fury.io/rb/redaction)
2
3
  [![Tests](https://github.com/DRBragg/redaction/actions/workflows/ci.yml/badge.svg)](https://github.com/DRBragg/redaction/actions/workflows/ci.yml)
3
4
 
4
5
  Easily redact your ActiveRecord Models. Great for use when you use production data in staging or dev. Simply set the redaction type of the attributes you want to redact and run via the [console](#via-the-rails-console) or the included [rake task](#via-rake-task).
@@ -6,17 +7,17 @@ Easily redact your ActiveRecord Models. Great for use when you use production da
6
7
  `redaction` uses [Faker](https://github.com/faker-ruby/faker) under the hood to generate redacted data.
7
8
 
8
9
  ## Installation
9
- **NOTE:** This is currently an unreleased library very much in beta. Use at your own risk.
10
+ **NOTE:** This is currently very much in beta. Use at your own risk.
10
11
 
11
12
  Add this line to your application's Gemfile:
12
13
 
13
14
  ```ruby
14
- gem "redaction", git: "https://github.com/drbragg/redaction.git"
15
+ gem "redaction"
15
16
  ```
16
17
 
17
18
  And then execute:
18
19
  ```bash
19
- $ bundle
20
+ $ bundle install
20
21
  ```
21
22
 
22
23
  ## Usage
@@ -1,6 +1,18 @@
1
1
  module Redaction
2
+ class << self
3
+ def config
4
+ @config ||= Railtie.config.redaction
5
+ end
6
+ end
7
+
2
8
  class Railtie < ::Rails::Railtie
9
+ config.redaction = ActiveSupport::OrderedOptions.new
10
+
3
11
  initializer "redaction.initialize" do
12
+ options = config.redaction
13
+
14
+ options.email_domain = options.email_domain
15
+
4
16
  ActiveSupport.on_load(:active_record) do
5
17
  include Redaction::Redactable
6
18
  end
@@ -10,6 +10,8 @@ module Redaction
10
10
  end
11
11
 
12
12
  def redact!
13
+ raise ProductionEnvironmentError if Rails.env.production?
14
+
13
15
  @_redacting = true
14
16
  redacted_attributes.each_pair do |redactor_type, attributes|
15
17
  redactor = Redaction.find(redactor_type)
@@ -9,6 +9,8 @@ module Redaction
9
9
  end
10
10
 
11
11
  def redact!
12
+ raise ProductionEnvironmentError if Rails.env.production?
13
+
12
14
  models_to_redact.each do |model|
13
15
  next if model.redacted_attributes.empty?
14
16
 
@@ -4,7 +4,11 @@ module Redaction
4
4
  module Types
5
5
  class Email < Base
6
6
  def content
7
- Faker::Internet.safe_email
7
+ if Redaction.config.email_domain.present?
8
+ Faker::Internet.email(domain: Redaction.config.email_domain)
9
+ else
10
+ Faker::Internet.safe_email
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -1,3 +1,3 @@
1
1
  module Redaction
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/redaction.rb CHANGED
@@ -16,6 +16,14 @@ module Redaction
16
16
  autoload :Redactable, "redaction/redactable"
17
17
  autoload :Redactor, "redaction/redactor"
18
18
 
19
+ class ProductionEnvironmentError < StandardError
20
+ DEFAULT_MESSAGE = "Data cannot be redacted in production!"
21
+
22
+ def initialize(message = DEFAULT_MESSAGE)
23
+ super
24
+ end
25
+ end
26
+
19
27
  def self.find(redactor_type)
20
28
  if redactor_type.respond_to?(:call)
21
29
  redactor_type
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Bragg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -111,7 +111,7 @@ metadata:
111
111
  homepage_uri: https://github.com/drbragg/redaction
112
112
  source_code_uri: https://github.com/drbragg/redaction
113
113
  changelog_uri: https://github.com/drbragg/redaction/blob/main/CHANGELOG.md
114
- post_install_message:
114
+ post_install_message:
115
115
  rdoc_options: []
116
116
  require_paths:
117
117
  - lib
@@ -119,15 +119,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '0'
122
+ version: 2.5.0
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.2.3
130
- signing_key:
129
+ rubygems_version: 3.3.3
130
+ signing_key:
131
131
  specification_version: 4
132
132
  summary: Easily redact your ActiveRecord Models.
133
133
  test_files: []