-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEOS-1692:add in transform uuid transformer #3079
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3079 +/- ##
==========================================
+ Coverage 31.88% 31.90% +0.01%
==========================================
Files 358 360 +2
Lines 41672 41815 +143
==========================================
+ Hits 13288 13340 +52
- Misses 26839 26918 +79
- Partials 1545 1557 +12 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments regarding the algorithm for transforming the uuids
binary.LittleEndian.PutUint64(seedBytes[8:], uint64(randomInt)) | ||
|
||
// Create a new UUID using SHA1 namespace | ||
output := uuid.NewSHA1(uuid.Nil, seedBytes).String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually want to put all of the generated uuids in the same Nil namespace?
The original design we came up with puts the new uuids inside of the original uuid's namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
seedBytes := make([]byte, 16) | ||
|
||
// Use the first 8 bytes from the input UUID | ||
copy(seedBytes, inputUuid[:8]) | ||
|
||
randomInt := randomizer.Float64() | ||
binary.LittleEndian.PutUint64(seedBytes[8:], uint64(randomInt)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious as to why we are going through this whole song and dance to generate the input data when it accepts any arbitrary amount.
In other words, why not just uuid.NewSha1(inputUuid, []byte(randomizer.Float64()))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the newSha1()
takes in a byte array for the second argument and you can't transforma a float64 to a byte array by wrapping it in []byte()
. You have to encode it in order to convert it. With that being said, we can simplify it.
// Create a new UUID using SHA1 namespace | ||
output := uuid.NewSHA1(uuid.Nil, seedBytes).String() | ||
bytes := make([]byte, 16) | ||
binary.LittleEndian.PutUint64(bytes, uint64(randomInt)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you go into the randomizer you can expose the Int63
or Int()
function, then the Float64
can just go away entirely.
Then it can become uuid.NewSHA1(inputUuid, []byte(randomizer.Int63()))
cede392
to
f7694f7
Compare
This feature adds in a Transform UUID transformer. By default, it generates new UUID v4s. You can pass in a seed value to deterministically output UUIDs based on the input UUID. This is useful if you consider UUIDs to be sensitive data but want users to maintain their UUID consistency across tables/databases. So given a seed value, an input UUID will generate the same output UUID.
Demo:
https://www.loom.com/share/cc48d55850e246a488f90976b90e2b3f?sid=965d7b94-31fd-412b-93de-d90db181bde5