@@ -23,14 +23,32 @@ def initialize(all_attributes_private, private_attributes)
23
23
# @return [Hash]
24
24
#
25
25
def filter ( context )
26
- return filter_single_context ( context , true ) unless context . multi_kind?
26
+ internal_filter ( context , false )
27
+ end
28
+
29
+ #
30
+ # Return a hash representation of the provided context with attribute
31
+ # redaction applied.
32
+ #
33
+ # If a context is anonyomous, all attributes will be redacted except
34
+ # for key, kind, and anonymous.
35
+ #
36
+ # @param context [LaunchDarkly::LDContext]
37
+ # @return [Hash]
38
+ #
39
+ def filter_redact_anonymous ( context )
40
+ internal_filter ( context , true )
41
+ end
42
+
43
+ private def internal_filter ( context , redact_anonymous )
44
+ return filter_single_context ( context , true , redact_anonymous ) unless context . multi_kind?
27
45
28
46
filtered = { kind : 'multi' }
29
47
( 0 ...context . individual_context_count ) . each do |i |
30
48
c = context . individual_context ( i )
31
49
next if c . nil?
32
50
33
- filtered [ c . kind ] = filter_single_context ( c , false )
51
+ filtered [ c . kind ] = filter_single_context ( c , false , redact_anonymous )
34
52
end
35
53
36
54
filtered
@@ -43,22 +61,24 @@ def filter(context)
43
61
# @param include_kind [Boolean]
44
62
# @return [Hash]
45
63
#
46
- private def filter_single_context ( context , include_kind )
64
+ private def filter_single_context ( context , include_kind , redact_anonymous )
47
65
filtered = { key : context . key }
48
66
49
67
filtered [ :kind ] = context . kind if include_kind
50
- filtered [ :anonymous ] = true if context . get_value ( :anonymous )
68
+
69
+ anonymous = context . get_value ( :anonymous )
70
+ filtered [ :anonymous ] = true if anonymous
51
71
52
72
redacted = [ ]
53
73
private_attributes = @private_attributes . concat ( context . private_attributes )
54
74
55
75
name = context . get_value ( :name )
56
- if !name . nil? && !check_whole_attribute_private ( :name , private_attributes , redacted )
76
+ if !name . nil? && !check_whole_attribute_private ( :name , private_attributes , redacted , anonymous && redact_anonymous )
57
77
filtered [ :name ] = name
58
78
end
59
79
60
80
context . get_custom_attribute_names . each do |attribute |
61
- unless check_whole_attribute_private ( attribute , private_attributes , redacted )
81
+ unless check_whole_attribute_private ( attribute , private_attributes , redacted , anonymous && redact_anonymous )
62
82
value = context . get_value ( attribute )
63
83
filtered [ attribute ] = redact_json_value ( nil , attribute , value , private_attributes , redacted )
64
84
end
@@ -75,10 +95,11 @@ def filter(context)
75
95
# @param attribute [Symbol]
76
96
# @param private_attributes [Array<Reference>]
77
97
# @param redacted [Array<Symbol>]
98
+ # @param redact_all [Boolean]
78
99
# @return [Boolean]
79
100
#
80
- private def check_whole_attribute_private ( attribute , private_attributes , redacted )
81
- if @all_attributes_private
101
+ private def check_whole_attribute_private ( attribute , private_attributes , redacted , redact_all )
102
+ if @all_attributes_private || redact_all
82
103
redacted << attribute
83
104
return true
84
105
end
0 commit comments