sunitparekh / data-anonymization

Want to use production data for testing, data-anonymization can help you.
MIT License
459 stars 92 forks source link

How do I anonymize jsonb fields? #84

Open josh-levinson opened 1 year ago

josh-levinson commented 1 year ago

I am just looking for a little guidance here on how to anonymize jsonb fields. The docs are a little unclear to me how I would go about using a Custom Strategy.

What I'm looking to do is basically go into some of our jsonb fields and maintain the keys but replace the values. I don't have a problem writing a custom method to do this, but I don't really know where to put it or how to connect it the data anon DSL.

Does anybody have any examples? Or at least maybe can show me how CustomStrategy examples work so I can add one that could read the data fields and output something?

Thanks so much.

sunitparekh commented 1 year ago

Follow documentation here to write your own analymosation strategy at field level... https://github.com/sunitparekh/data-anonymization#write-you-own-field-strategies

On Sat, Nov 4, 2023 at 1:47 AM Josh Levinson @.***> wrote:

I am just looking for a little guidance here on how to anonymize jsonb fields. The docs are a little unclear to me how I would go about using a Custom Strategy.

What I'm looking to do is basically go into some of our jsonb fields and maintain the keys but replace the values. I don't have a problem writing a custom method to do this, but I don't really know where to put it or how to connect it the data anon DSL.

Does anybody have any examples? Or at least maybe can show me how CustomStrategy examples work so I can add one that could read the data fields and output something?

Thanks so much.

— Reply to this email directly, view it on GitHub https://github.com/sunitparekh/data-anonymization/issues/84, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABLNOSPPRFOL5XMHFLZ5J3YCVGL7AVCNFSM6AAAAAA6453MP6VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE3TMOBXGM4TGOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- thanks & regards, Sunit Parekh +91 99237 00662 @.***

josh-levinson commented 12 months ago

@sunitparekh I have looked at those docs but I don't really understand how to use the custom strategies.

In your example you show

class MyFieldStrategy

    # method anonymize is what required
    def anonymize field
      # write your code here
    end

end

But its not clear a) where this should be, or b) how to call it

Does this go to the end of the anonymization file? In a separate class? I would love to see a real example of how to use this and I imagine so would others

sunitparekh commented 11 months ago
# to keep it simple create your own strategy class in same file
class AbcFieldStrategy

    # method anonymize is what required
    def anonymize field
      # write your code here
    end

end

# use it like just another anonymization strategies for required field
...
 collection 'users' do
        anonymize('your_field').using FieldStrategy::AbcFieldStrategy.new
 end
...