Giter VIP home page Giter VIP logo

ecto_anon's Issues

Option to use different values per type

Currently it is only possible to anonymise a field with a value different from the default value providing a custom function for each field.

For example:

defmodule User do
  use Ecto.Schema
  use EctoAnon.Schema

  anon_schema [
    name: &__MODULE__.custom_string/3
    email: &__MODULE__.custom_string/3
  ]

  schema "users" do
    field :name, :string
    field :age, :integer
    field :email, :string

    anonymized()
  end

  def custom_string(:string, %__MODULE__{} = _user, _opts \\ []), do: "[REDACTED]"
end

user = Repo.get(User, id)
%User{name: "jane", age: 24, email: "[email protected]"}

EctoAnon.run(user, Repo)
{:ok, %User{name: "[REDACTED]", age: 24, email: "[REDACTED]"}}

My suggestion is to have an alternative to provider a different value per type.

For example:

defmodule User do
  use Ecto.Schema
  use EctoAnon.Schema

   anon_schema(
     [:name, :email],
     anonymized_values: [string: "[REDACTED]"]
   )

  schema "users" do
    field :name, :string
    field :age, :integer
    field :email, :string

    anonymized()
  end
end

user = Repo.get(User, id)
%User{name: "jane", age: 24, email: "[email protected]"}

EctoAnon.run(user, Repo)
{:ok, %User{name: "[REDACTED]", age: 24, email: "[REDACTED]"}}

I am not thinking about the implementation details now, only the public interface and its usage for the sake of the discussion of the new feature. ๐Ÿ™‚

What do you think?

Run anonymizer through associations

Being able to specify an option for the runner like cascade: true and let it anonymize associations of our object could be awesome ! ๐Ÿš€

Implement anonymizing functions for some fields

As for now, we only have default anonymizing functions. It would be great to provide functions that are more business aware to keep anonymous data more readable.

Examples:

  • Anonymous phone (ie XX-XX-XX-XX-02 where locale is configurable)
  • Anonymous email (ie [email protected], where domain and tld are configurable)

[WIP] Keep a generic log of anonymized data

TODO

  • Provide basic migrations see Oban
  • Make logging optional
  • Provide (hooks | behaviour) to decorate the log changeset with specific needs (anonymizing done in an async queue? add a status, requested_at and finished_at fields to the table structure and fill them with your own data)
    • may we return the log id in order to find it later from the async queue processing?
    • the {source_id, source_type} identifier tuple may serve as well to find it later

Table structure

id source_id source_type serialized_changeset inserted_at
1 2345 User '{email,<<"redacted">>}' 2021-12-12-00:00:00

serialized_changeset can be created with:

:io_lib.format("~p", [email: "redacted"]) |> :lists.flatten()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.