immutable_struct_ex_redactable 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +4 -3
- data/README.md +36 -9
- data/lib/immutable_struct_ex_redactable/configuration.rb +13 -3
- data/lib/immutable_struct_ex_redactable/redacted_accessible.rb +24 -9
- data/lib/immutable_struct_ex_redactable/version.rb +1 -1
- data/lib/immutable_struct_ex_redactable.rb +13 -5
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d52c752fa013e9231b263b7f0395f2d6713ce627bd42c9c7bb664c47030d6a58
|
4
|
+
data.tar.gz: 17a8fe47bf9b7890d38075ac82d25fdd0aae91b2eb824a25636bbf9116f8900a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e89673ded8ec3cdd8517914aab113b61e65c5f2b4b8b3deaeb729cc61381c2b43e4e6502a81d90fc64427ddf4cda426b4252bbd1dc1dad5f584b2b169dd4010c
|
7
|
+
data.tar.gz: 70e2d85a032dae78691435c3a01b749d15fdaa4c28b944887eef8384813ffe509967032d2d4100e83870f5dcc31e149e201e65b9279e5ac40a59da1c3fd37262
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## [1.3.0] - 2023-09-03
|
2
|
+
|
3
|
+
Changes
|
4
|
+
|
5
|
+
- `ImmutableStructExRedactable::Configuration#whitelist` is now supported. Attributes added to #whitelist will not be redacted. All other attributes will be redacted.
|
6
|
+
- `ImmutableStructExRedactable::Configuration#redacted` will be deprecated in a future release. Please use `ImmutableStructExRedactable::Configuration#blacklist` instead.
|
7
|
+
|
8
|
+
## [1.2.2] - 2023-08-29
|
9
|
+
|
10
|
+
Changes
|
11
|
+
|
12
|
+
- Ruby gem updates.
|
13
|
+
|
1
14
|
## [1.2.1] - 2023-08-17
|
2
15
|
|
3
16
|
Changes
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
immutable_struct_ex_redactable (1.
|
4
|
+
immutable_struct_ex_redactable (1.3.0)
|
5
5
|
immutable_struct_ex (~> 1.0, >= 1.0.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
coderay (1.1.3)
|
14
14
|
diff-lcs (1.5.0)
|
15
15
|
docile (1.4.0)
|
16
|
-
immutable_struct_ex (1.0.
|
16
|
+
immutable_struct_ex (1.0.2)
|
17
17
|
json (2.6.3)
|
18
18
|
kwalify (0.7.2)
|
19
19
|
language_server-protocol (3.17.0.3)
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
51
|
rspec-support (~> 3.12.0)
|
52
52
|
rspec-support (3.12.1)
|
53
|
-
rubocop (1.56.
|
53
|
+
rubocop (1.56.2)
|
54
54
|
base64 (~> 0.1.1)
|
55
55
|
json (~> 2.3)
|
56
56
|
language_server-protocol (>= 3.17.0)
|
@@ -75,6 +75,7 @@ GEM
|
|
75
75
|
|
76
76
|
PLATFORMS
|
77
77
|
x86_64-darwin-19
|
78
|
+
x86_64-darwin-21
|
78
79
|
x86_64-linux
|
79
80
|
|
80
81
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -15,10 +15,9 @@
|
|
15
15
|
|
16
16
|
`immutable_struct_ex_redactable` is the *redactable version* of the world-famous *immutable_struct_ex* immutable struct :). To find out more about the *immutable_struct_ex* gem, visit the Rubygems.org entry for [immutable_struct_ex](https://rubygems.org/gems/immutable_struct_ex).
|
17
17
|
|
18
|
-
`immutable_struct_ex_redactable` maintains all the functionality of the *immutable_struct_ex* gem, but allows you to create immutable structs that can be configured to redact field values using standard gem configuration (`ImmutableStructExRedactable.configure { |config| ... }`) or by passing configuration options to the appropriate method (`ImmutableStructExRedactable.create_with(config, ...)`)
|
18
|
+
`immutable_struct_ex_redactable` maintains all the functionality of the *immutable_struct_ex* gem, but allows you to create immutable structs that can be configured to redact field values using standard gem configuration (`ImmutableStructExRedactable.configure { |config| ... }`) or by passing configuration options to the appropriate method (`ImmutableStructExRedactable.create_with(config, ...)`).
|
19
19
|
|
20
|
-
|
21
|
-
- Future functionality will probably accept regex pattern for redacting field values (e.g. 'gen***@***.com').
|
20
|
+
NOTE: both **whitelisting** and **blacklisting** are supported.
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
@@ -28,11 +27,12 @@ Follow the instructions for [Installation](#installation) first, to incorporate
|
|
28
27
|
|
29
28
|
#### Configure Gem Global Defaults
|
30
29
|
|
31
|
-
*immutable_struct_ex_redactable*, by default, will redact fields named `:password` using the redacted label `"******"`. This will not meet your needs in all circumstances most likely. If this is *not* the case, you may change the
|
30
|
+
*immutable_struct_ex_redactable*, by default, will redact fields named `:password` using the redacted label `"******"`. This will not meet your needs in all circumstances most likely. If this is *not* the case, you may change the fields that are redacted and the redactable label by changing the *immutable_struct_ex_redactable* configuration via the `#whitelist` or `#blacklist` configuration options:
|
32
31
|
|
32
|
+
##### Using a whitelist
|
33
33
|
```ruby
|
34
34
|
ImmutableStructExRedactable::configure do |config|
|
35
|
-
config.
|
35
|
+
config.whitelist = %i[first last]
|
36
36
|
config.redacted_label = '[REDACTED]'
|
37
37
|
end
|
38
38
|
|
@@ -55,7 +55,34 @@ fields = {
|
|
55
55
|
|
56
56
|
ImmutableStructExRedactable.create(**fields)
|
57
57
|
=> #<struct first="Jane", last="Smith", password="[REDACTED]", dob="[REDACTED]">
|
58
|
+
```
|
59
|
+
|
60
|
+
##### Using a blacklist
|
61
|
+
```ruby
|
62
|
+
ImmutableStructExRedactable::configure do |config|
|
63
|
+
config.blacklist = %i[password dob ssn phone]
|
64
|
+
config.redacted_label = '[REDACTED]'
|
65
|
+
end
|
66
|
+
|
67
|
+
fields = {
|
68
|
+
first: 'John',
|
69
|
+
last: 'Smith',
|
70
|
+
password: 'p@ssw0rd',
|
71
|
+
dob: '1986-05-12'
|
72
|
+
}
|
58
73
|
|
74
|
+
ImmutableStructExRedactable.create(**fields)
|
75
|
+
=> #<struct first="John", last="Smith", password="[REDACTED]", dob="[REDACTED]">
|
76
|
+
|
77
|
+
fields = {
|
78
|
+
first: 'Jane',
|
79
|
+
last: 'Smith',
|
80
|
+
password: 'h3l10W04lD',
|
81
|
+
dob: '1990-12-26'
|
82
|
+
}
|
83
|
+
|
84
|
+
ImmutableStructExRedactable.create(**fields)
|
85
|
+
=> #<struct first="Jane", last="Smith", password="[REDACTED]", dob="[REDACTED]">
|
59
86
|
```
|
60
87
|
|
61
88
|
NOTE: Setting the global defaults in the above manner will affect **every** *immutable_struct_ex_redactable* struct instance you create unless you override the global configuration options, by passing a custom configuration.
|
@@ -67,7 +94,7 @@ To override the global configuration options, you may do so by calling the `Immu
|
|
67
94
|
```ruby
|
68
95
|
# Create a custom configuration with the options you want to use.
|
69
96
|
custom_config = ImmutableStructExRedactable::Configuration.new.tap do |config|
|
70
|
-
config.
|
97
|
+
config.whitelist = %i[first last]
|
71
98
|
config.redacted_label = '[NO WAY JOSE]'
|
72
99
|
end
|
73
100
|
|
@@ -85,7 +112,7 @@ ImmutableStructExRedactable.create_with(custom_config, **fields)
|
|
85
112
|
|
86
113
|
### Access to the Original Redacted Field Values
|
87
114
|
|
88
|
-
By default, *immutable_struct_ex_redactable* **will not** allow access to redacted field values; that is, field values marked for redaction via the global configuration (`ImmutableStructExRedactable::Configuration#
|
115
|
+
By default, *immutable_struct_ex_redactable* **will not** allow access to redacted field values; that is, field values marked for redaction via the global configuration (`ImmutableStructExRedactable::Configuration#whitelist/#blacklist`) or by overriding the global configuration by passing a custom configuration (`ImmutableStructExRedactable.create_with(my_config, ...)`). However, if you really *need* access to redacted field values in their original, *un*redacted form, you can turn on the `ImmutableStructExRedactable::Configuration#redacted_unsafe` option in the global configuration or turn this same option on when passing a custom configuration. Turning the `redacted_unsafe` configuration option on in either scenario will instruct *immutable_struct_ex_redactable* to create *private methods* on structs created that will allow access to the original *un*redacted field values via `send:`. The *private methods* created that will allow access to the original *un*redacted field values, will have the following naming convention:
|
89
116
|
|
90
117
|
```ruby
|
91
118
|
unredacted_<redacted field>
|
@@ -97,6 +124,7 @@ For example:
|
|
97
124
|
|
98
125
|
```ruby
|
99
126
|
custom_config = ImmutableStructExRedactable::Configuration.new.tap do |config|
|
127
|
+
config.whitelist = %i[username]
|
100
128
|
config.redacted_unsafe = true
|
101
129
|
end
|
102
130
|
|
@@ -119,7 +147,6 @@ struct.send :unredacted_password
|
|
119
147
|
|
120
148
|
struct.to_h_unredacted
|
121
149
|
#=> {:username=>"jsmith", :password=>"p@ssw0rd"}
|
122
|
-
|
123
150
|
```
|
124
151
|
|
125
152
|
### &blocks are Permitted
|
@@ -165,7 +192,7 @@ class MyRedactableImmutableStruct
|
|
165
192
|
|
166
193
|
def config
|
167
194
|
@config ||= ImmutableStructExRedactable::Configuration.new.tap do |config|
|
168
|
-
config.
|
195
|
+
config.whitelist = %i[username]
|
169
196
|
config.redacted_label = 'xxxxxx'
|
170
197
|
end
|
171
198
|
end
|
@@ -24,12 +24,21 @@ module ImmutableStructExRedactable
|
|
24
24
|
# This class encapsulates the configuration properties for this gem and
|
25
25
|
# provides methods and attributes that allow for management of the same.
|
26
26
|
class Configuration
|
27
|
-
# Gets/sets the fields that should be redacted for this gem.
|
27
|
+
# Gets/sets the blacklisted fields that should be redacted for this gem.
|
28
28
|
#
|
29
29
|
# The default is %i[password].
|
30
30
|
#
|
31
31
|
# @return [Array<Symbol>] an Array of Symbols that should be redacted.
|
32
|
-
attr_accessor :
|
32
|
+
attr_accessor :blacklist
|
33
|
+
alias redacted blacklist
|
34
|
+
alias redacted= blacklist=
|
35
|
+
|
36
|
+
# Gets/sets the whitelisted fields that should not be redacted for this gem.
|
37
|
+
#
|
38
|
+
# The default is [].
|
39
|
+
#
|
40
|
+
# @return [Array<Symbol>] an Array of Symbols that should be whitelisted.
|
41
|
+
attr_accessor :whitelist
|
33
42
|
|
34
43
|
# Gets/sets the label that should replace redacted field values.
|
35
44
|
#
|
@@ -62,7 +71,8 @@ module ImmutableStructExRedactable
|
|
62
71
|
#
|
63
72
|
# @return [void]
|
64
73
|
def reset
|
65
|
-
@
|
74
|
+
@blacklist = %i[password]
|
75
|
+
@whitelist = []
|
66
76
|
@redacted_label = '******'
|
67
77
|
@redacted_unsafe = false
|
68
78
|
end
|
@@ -11,15 +11,30 @@ module ImmutableStructExRedactable
|
|
11
11
|
module ClassModules
|
12
12
|
def redacted_accessible_module_for(hash:, config:)
|
13
13
|
Module.new do
|
14
|
-
config.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
if config.whitelist.any?
|
15
|
+
hash.each do |attr, _|
|
16
|
+
next if config.whitelist.include? attr
|
17
|
+
|
18
|
+
unredacted_attr_method = "unredacted_#{attr}"
|
19
|
+
code = <<~CODE
|
20
|
+
def #{unredacted_attr_method}
|
21
|
+
"#{hash[attr]}"
|
22
|
+
end
|
23
|
+
private :#{unredacted_attr_method}
|
24
|
+
CODE
|
25
|
+
class_eval code
|
26
|
+
end
|
27
|
+
else
|
28
|
+
config.blacklist.each do |attr|
|
29
|
+
unredacted_attr_method = "unredacted_#{attr}"
|
30
|
+
code = <<~CODE
|
31
|
+
def #{unredacted_attr_method}
|
32
|
+
"#{hash[attr]}"
|
33
|
+
end
|
34
|
+
private :#{unredacted_attr_method}
|
35
|
+
CODE
|
36
|
+
class_eval code
|
37
|
+
end
|
23
38
|
end
|
24
39
|
end
|
25
40
|
end
|
@@ -10,9 +10,9 @@ module ImmutableStructExRedactable
|
|
10
10
|
|
11
11
|
module_function
|
12
12
|
|
13
|
-
def create(
|
13
|
+
def create(...)
|
14
14
|
config = ImmutableStructExRedactable.configure
|
15
|
-
create_with(config,
|
15
|
+
create_with(config, ...)
|
16
16
|
end
|
17
17
|
|
18
18
|
def create_with(config, **hash, &block)
|
@@ -21,10 +21,18 @@ module ImmutableStructExRedactable
|
|
21
21
|
redacted_accessible_module_for(hash: hash, config: config)
|
22
22
|
end
|
23
23
|
|
24
|
-
config.
|
25
|
-
|
24
|
+
if config.whitelist.any?
|
25
|
+
hash.each do |key, _|
|
26
|
+
next if config.whitelist.include? key
|
26
27
|
|
27
|
-
|
28
|
+
hash[key] = config.redacted_label
|
29
|
+
end
|
30
|
+
else
|
31
|
+
config.blacklist.each do |attr|
|
32
|
+
next unless hash.key? attr
|
33
|
+
|
34
|
+
hash[attr] = config.redacted_label
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
30
38
|
ImmutableStructEx.new(**hash, &block).tap do |struct|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immutable_struct_ex_redactable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene M. Angelo, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: immutable_struct_ex
|
@@ -63,7 +63,14 @@ metadata:
|
|
63
63
|
source_code_uri: https://github.com/gangelo/immutable_struct_ex_redactable
|
64
64
|
changelog_uri: https://github.com/gangelo/immutable_struct_ex_redactable/blob/main/CHANGELOG.md
|
65
65
|
rubygems_mfa_required: 'true'
|
66
|
-
post_install_message:
|
66
|
+
post_install_message: |
|
67
|
+
Thank you for installing immutable_struct_ex_redactable.
|
68
|
+
|
69
|
+
immutable_struct_ex_redactable now supports `ImmutableStructExRedactable::Configuration#whitelist`
|
70
|
+
See the README.md for more information.
|
71
|
+
|
72
|
+
Please note that `ImmutableStructExRedactable::Configuration#redacted` will be deprecated in a future release.
|
73
|
+
Please use `ImmutableStructExRedactable::Configuration#blacklist` instead.
|
67
74
|
rdoc_options: []
|
68
75
|
require_paths:
|
69
76
|
- lib
|
@@ -78,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
85
|
- !ruby/object:Gem::Version
|
79
86
|
version: '0'
|
80
87
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
88
|
+
rubygems_version: 3.2.15
|
82
89
|
signing_key:
|
83
90
|
specification_version: 4
|
84
91
|
summary: The redactable version of the immutable_stuct_ex gem.
|