Drop

A Drop operation is the process of removing certain envelope fields depending on specified conditions. Conditions can be based on the field names, heuristics about the data values and attributes about the requesting client.

type Drop struct {
    Conditions []Condition `json:"conditions,omitempty"`
}

type Condition struct {
    // Example = /passport_id|ssn|cc/
    FieldRegexp string `json:"field_regexp"`
    // Example = /d{13,16}/
    ValueRegexp string `json:"value_regexp"`
    // Example = /Node v[0-7].*|Python v2.*/
    AgentRegexp string `json:"agent_regexp"`
    // Example  = ["ssn", "cc"] or ["*"]
    Fields []string `json:"fields"`
    // Example = medium
    SensivityLevel string `json:"sensitivity_level"`
}
import (
    "reflect"
    "github.com/ume/api/pkg/mirror"
)

func HandleFormSubmission(form *Form) {
    // form = {name: Ada, email: ada@lovelace.com}
    formData := form.ToMap()
    envelope := mirror.Envelope{
        Data: formData,
        Operations: []mirror.Operation{
            {
                DataLocation: mirror.DataLocation{Source: "email"},
                Drop: &mirror.Drop{},
            },
        },
    }

    envelope.Execute()

    formEmail := form.Get("email")

    if assertNotEqual(envelope.Data["email"], formEmail) {
        // Email was successfully dropped
    }
}

func assertNotEqual(expected, actual interface{}) bool {
    isEqual := reflect.DeepEqual(expected, actual)

    return !isEqual
}

Before

{
  "data": {
    "name": "Ada",
    "email": "ada@lovelace.com"
  },
  "ops": [{ "src": "email", "drop": {} }]
}

After

{
  "data": { "name": "Ada" },
  "ops": []
}