anonuuid

package module
Version: v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

README

anonuuid

🔧 anonymize UUIDs

anonuuid Logo

CircleCI GoDoc License GitHub release Go Report Card CodeFactor codecov Docker Metrics Sourcegraph Made by Manfred Touron

anonuuid anonymize an input string by replacing all UUIDs by an anonymized new one.

The fake UUIDs are cached, so if anonuuid encounter the same real UUIDs multiple times, the translation will be the same.

Usage

$ anonuuid --help
NAME:
   anonuuid - Anonymize UUIDs outputs

USAGE:
   anonuuid [global options] command [command options] [arguments...]

VERSION:
   1.0.0-dev

AUTHOR(S):
   Manfred Touron <https://moul.io/anonuuid>

COMMANDS:
   help, h	Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --hexspeak		Generate hexspeak style fake UUIDs
   --random, -r		Generate random fake UUIDs
   --keep-beginning	Keep first part of the UUID unchanged
   --keep-end		Keep last part of the UUID unchanged
   --prefix, -p 	Prefix generated UUIDs
   --suffix 		Suffix generated UUIDs
   --help, -h		show help
   --version, -v	print the version

Example

Replace all UUIDs and cache the correspondance.

$ anonuuid git:(master) ✗ cat <<EOF | anonuuid
VOLUMES_0_SERVER_ID=15573749-c89d-41dd-a655-16e79bed52e0
VOLUMES_0_SERVER_NAME=hello
VOLUMES_0_ID=c245c3cb-3336-4567-ada1-70cb1fe4eefe
VOLUMES_0_SIZE=50000000000
ORGANIZATION=fe1e54e8-d69d-4f7c-a9f1-42069e03da31
TEST=15573749-c89d-41dd-a655-16e79bed52e0
EOF
VOLUMES_0_SERVER_ID=00000000-0000-0000-0000-000000000000
VOLUMES_0_SERVER_NAME=hello
VOLUMES_0_ID=11111111-1111-1111-1111-111111111111
VOLUMES_0_SIZE=50000000000
ORGANIZATION=22222222-2222-2222-2222-222222222222
TEST=00000000-0000-0000-0000-000000000000

Inline

$ echo 'VOLUMES_0_SERVER_ID=15573749-c89d-41dd-a655-16e79bed52e0 VOLUMES_0_SERVER_NAME=bitrig1 VOLUMES_0_ID=c245c3cb-3336-4567-ada1-70cb1fe4eefe VOLUMES_0_SIZE=50000000000 ORGANIZATION=fe1e54e8-d69d-4f7c-a9f1-42069e03da31 TEST=15573749-c89d-41dd-a655-16e79bed52e0' | ./anonuuid
VOLUMES_0_SERVER_ID=00000000-0000-0000-0000-000000000000 VOLUMES_0_SERVER_NAME=bitrig1 VOLUMES_0_ID=11111111-1111-1111-1111-111111111111 VOLUMES_0_SIZE=50000000000 ORGANIZATION=22222222-2222-2222-2222-222222222222 TEST=00000000-0000-0000-0000-000000000000

$ curl -s https://api.pathwar.net/achievements\?max_results\=2 | anonuuid | jq .
{
  "_items": [
    {
      "_updated": "Thu, 30 Apr 2015 13:00:58 GMT",
      "description": "You",
      "_links": {
        "self": {
          "href": "achievements/00000000-0000-0000-0000-000000000000",
          "title": "achievement"
        }
      },
      "_created": "Thu, 30 Apr 2015 13:00:58 GMT",
      "_id": "00000000-0000-0000-0000-000000000000",
      "_etag": "b1e9f850accfcb952c58384db41d89728890a69f",
      "name": "finish-20-levels"
    },
    {
      "_updated": "Thu, 30 Apr 2015 13:01:07 GMT",
      "description": "You",
      "_links": {
        "self": {
          "href": "achievements/11111111-1111-1111-1111-111111111111",
          "title": "achievement"
        }
      },
      "_created": "Thu, 30 Apr 2015 13:01:07 GMT",
      "_id": "11111111-1111-1111-1111-111111111111",
      "_etag": "c346f5e1c4f7658f2dfc4124efa87aba909a9821",
      "name": "buy-30-levels"
    }
  ],
  "_links": {
    "self": {
      "href": "achievements?max_results=2",
      "title": "achievements"
    },
    "last": {
      "href": "achievements?max_results=2&page=23",
      "title": "last page"
    },
    "parent": {
      "href": "/",
      "title": "home"
    },
    "next": {
      "href": "achievements?max_results=2&page=2",
      "title": "next page"
    }
  },
  "_meta": {
    "max_results": 2,
    "total": 46,
    "page": 1
  }
}

Install

Using go
  • go get moul.io/anonuuid/cmd/anonuuid
Using brew
  • brew install moul/moul/anonuuid
Download release

https://github.com/moul/anonuuid/releases

License

© 2015-2021 Manfred Touron - Apache-2.0 License

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// UUIDRegex is the regex used to find UUIDs in texts
	UUIDRegex = "[a-z0-9]{8}-[a-z0-9]{4}-[1-5][a-z0-9]{3}-[a-z0-9]{4}-[a-z0-9]{12}"
)

Functions

func FormatUUID

func FormatUUID(part string) (string, error)

FormatUUID takes a string in input and return an UUID formatted string by repeating the string and placing dashes if necessary

func GenerateHexspeakUUID

func GenerateHexspeakUUID(i int) (string, error)

GenerateHexspeakUUID returns an UUID formatted string containing hexspeak words

func GenerateLenUUID

func GenerateLenUUID(i int) (string, error)

GenerateLenUUID returns an UUID formatted string based on an index number

func GenerateRandomUUID

func GenerateRandomUUID(length int) (string, error)

GenerateRandomUUID returns an UUID based on random strings

func IsUUID

func IsUUID(input string) error

IsUUID returns nil if the input is an UUID, else it returns an error

func PrefixUUID

func PrefixUUID(prefix string, uuid string) (string, error)

PrefixUUID returns a prefixed UUID

func SuffixUUID added in v1.1.0

func SuffixUUID(suffix string, uuid string) (string, error)

SuffixUUID returns a suffixed UUID

Types

type AnonUUID

type AnonUUID struct {

	// Hexspeak flag will generate hexspeak style fake UUIDs
	Hexspeak bool

	// Random flag will generate random fake UUIDs
	Random bool

	// Prefix will be the beginning of all the generated UUIDs
	Prefix string

	// Suffix will be the end of all the generated UUIDs
	Suffix string

	// AllowNonUUIDInput tells FakeUUID to accept non UUID input string
	AllowNonUUIDInput bool

	// KeepBeginning tells FakeUUID to let the beginning of the UUID as it is
	KeepBeginning bool

	// KeepEnd tells FakeUUID to let the last part of the UUID as it is
	KeepEnd bool
	// contains filtered or unexported fields
}

AnonUUID is the main structure, it contains the cache map and helpers

func New

func New() *AnonUUID

New returns a prepared AnonUUID structure

func (*AnonUUID) FakeUUID

func (a *AnonUUID) FakeUUID(input string) string

FakeUUID takes a word (real UUID or standard string) and returns its corresponding (mapped) fakeUUID

Example
anonuuid := New()
fmt.Println(anonuuid.FakeUUID("15573749-c89d-41dd-a655-16e79bed52e0"))
fmt.Println(anonuuid.FakeUUID("15573749-c89d-41dd-a655-16e79bed52e0"))
fmt.Println(anonuuid.FakeUUID("c245c3cb-3336-4567-ada1-70cb1fe4eefe"))
fmt.Println(anonuuid.FakeUUID("c245c3cb-3336-4567-ada1-70cb1fe4eefe"))
fmt.Println(anonuuid.FakeUUID("15573749-c89d-41dd-a655-16e79bed52e0"))
fmt.Println(anonuuid.FakeUUID("fe1e54e8-d69d-4f7c-a9f1-42069e03da31"))
Output:

00000000-0000-1000-0000-000000000000
00000000-0000-1000-0000-000000000000
11111111-1111-1111-1111-111111111111
11111111-1111-1111-1111-111111111111
00000000-0000-1000-0000-000000000000
22222222-2222-1222-2222-222222222222

func (*AnonUUID) Sanitize

func (a *AnonUUID) Sanitize(input string) string

Sanitize takes a string as input and return sanitized string

Example
anonuuid := New()
fmt.Println(anonuuid.Sanitize(exampleInput))
Output:

VOLUMES_0_SERVER_ID=00000000-0000-1000-0000-000000000000
VOLUMES_0_SERVER_NAME=hello
VOLUMES_0_ID=11111111-1111-1111-1111-111111111111
VOLUMES_0_SIZE=50000000000
ORGANIZATION=22222222-2222-1222-2222-222222222222
TEST=00000000-0000-1000-0000-000000000000

Source Files

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL