CGI-FR / CGI-FR/PIMO

Feature Request: Adding 'median' Parameter to RandomInt Mask

Open
#300 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
43
Forks
16
PR merge metrics
No merged PRs in 30d

Description

### Problem:
Currently, the PIMO tool provides a RandomInt mask for masking data in a JSONline stream. However, it lacks the ability to specify a median parameter for generating random numbers within a range, which can be useful in certain scenarios.

### Proposed Solution:
Integrate a 'median' parameter into the RandomInt mask to allow users to control the distribution of random numbers within the specified range.

### Example:
```yaml
version: "1"
masking:
- selector:
jsonpath: "age"
mask:
randomInt:
min: 25
median: 28
max: 32
```

### Workaround:
While waiting for the integration of the 'median' parameter into the RandomInt mask, users can achieve similar behavior by combining masks. Below is a workaround using existing PIMO masks:

```yaml
version: "1"
masking:
- selector:
jsonpath: "segment"
masks:
- add-transient : ""
- randomChoice:
- "upper"
- "lower"

- selector:
jsonpath: "value"
masks:
- template : |-
{{ if eq .segment "lower" -}}
{{- MaskRandomInt (int .min) (int .median) -}}
{{- else -}}
{{- MaskRandomInt (int .median) (int .max) -}}
{{- end }}
- fromjson: "value"

```
This workaround calculates a random number within the range defined by 'min' and 'max', centered around the 'median' value. It utilizes the existing MaskRandomInt function and template capabilities to achieve the desired behavior.

[try it on pimo play ! ](https://cgi-fr.github.io/pimo-play/#c=G4UwTgzglg9gdgLgAQCICMKBQBbAhhAayjgHMFMkkBaJCEAGxAGMAXGMcyrpAKwngAOuFgAtkKOiWwg4LLNzyEInbtSS4AJhqoswuONBksk4+app64GmNgDCImFCYgVqrjRQBXAQPBm3lB70MADufpgUanSMrOyuXHyCwmKowLj0niD+SIoEypHcNCwg2AL0wiAmSAA+VAUBlADejUhQAGZIIACOSAB0ktKyqMFhYCjUAL4T9Q1NjTQAsvgEAEr61tgAkkMAFMTGvdjEAJRIe0OHIBpQ+qdUUzMBzTQMdJPTs6rPSEuEa1Y2bbGc4HaTXW5nfZ9PAADzuD0+cxeViQCPMSDaYBsiUQqXSmSwQA&i=N4KABGBEBuCGA2BXAppAXFSAacUC2AlgHaRgYAMOEkesAHqRgIzmW43IAmBsJZYATnIgAvkA)

Contributor guide

Open the contributing guide

Research direction

Start by locating the RandomInt mask implementation and the existing MaskRandomInt function, then inspect related mask and configuration tests. Done means the YAML example accepts a median value and generated integers follow the requested min-to-median or median-to-max distribution, with tests covering the range and configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.