-
Notifications
You must be signed in to change notification settings - Fork 17
Rename class/method/variable names to improve token generation code readability #1080
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
base: main
Are you sure you want to change the base?
Conversation
…f variables which don't just include tokens
…LevelHashIdentity and RawUidIdentity as UserIdentity is a very vague term and one needs to read function calls to really understand whether the UserIdentity class has hashed DII, first level hash or raw Uid.
2. Rename RefreshToken class to RefreshTokenInput 3. Rename createAdvertisingToken/createRefreshToken methods to createAdvertisingTokenInput/createRefreshTokenInput
…ii/FirstLevelHash/RawUidIdentity sub-classes
…ertisingId to generateRawUid
2. Renamed AdvertisingId to RawUid in most operator codes (except optout store related)
public IdentityScope identityScope; | ||
public IdentityType identityType; | ||
public int privacyBits; | ||
public Instant establishedAt; | ||
public Instant refreshedAt; |
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.
Can we make these final and set them in a protected ctor.
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.
fixed
public IdentityScope GetIdentityScope() { return identityScope; } | ||
public IdentityType GetIdentityType() { return identityType; } | ||
public Instant GetEstablishedAt() { return establishedAt; }; | ||
public Instant GetIRefreshedAt() { return refreshedAt; } |
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.
- Should start with
get
- Why no getter for
privacyBits
? - Do we need getters if the fields are public? Or should we keep the getters and make the fields private?
- Typo in
GetIRefreshedAt
this.identityV3Enabled | ||
? TokenUtils.getAdvertisingIdV3(firstLevelHashIdentity.identityScope, firstLevelHashIdentity.identityType, firstLevelHashIdentity.id, rotatingSalt.getSalt()) | ||
: TokenUtils.getAdvertisingIdV2(firstLevelHashIdentity.id, rotatingSalt.getSalt()), | ||
? TokenUtils.getRawUidV3(firstLevelHashIdentity.identityScope, | ||
firstLevelHashIdentity.identityType, firstLevelHashIdentity.firstLevelHash, rotatingSalt.getSalt()) | ||
: TokenUtils.getRawUidV2(firstLevelHashIdentity.firstLevelHash, rotatingSalt.getSalt()), |
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.
Can we introduce a variable here? This is hard to read.
public static final String ValidateIdentityForEmail = "[email protected]"; | ||
public static final String ValidateIdentityForPhone = "+12345678901"; | ||
public static final byte[] ValidateIdentityForEmailHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForEmail); | ||
public static final byte[] ValidateIdentityForPhoneHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForPhone); | ||
|
||
// DIIs to use when you want to generate a optout response in token generation or identity map |
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.
Maybe we can add some similar comments for the above/below groups of variables too?
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.
Done
|
||
public IdentityScope GetIdentityScope() { return identityScope; } | ||
public IdentityType GetIdentityType() { return identityType; } | ||
public Instant GetEstablishedAt() { return establishedAt; }; |
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.
Extra ;
at the end
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.
removed the get methods for now
public IdentityScope GetIdentityScope() { return identityScope; } | ||
public IdentityType GetIdentityType() { return identityType; } | ||
public Instant GetEstablishedAt() { return establishedAt; }; | ||
public Instant GetIRefreshedAt() { return refreshedAt; } |
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.
Extra I
after Get
i.e. this should be GetRefreshedAfterAt()
|
||
import java.time.Instant; | ||
|
||
// Contains a hash computed from a raw email/phone number DII input or the hash is provided by the UID Participant |
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.
I think better to split this into two lines as such:
// Contains a hashed DII
// The hash can either be computed from a raw email/phone number DII input or provided by the UID Participant directly
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.
Fixed
import java.time.Instant; | ||
|
||
//base class for all other HshedDii/FirstLevelHash/RawUIDIdentity class and define the basic common fields | ||
public class UserIdentity { |
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.
I don't think we're instantiating UserIdentity
anymore, so I suggest making this an abstract class, i.e. public abstract class UserIdentity
As for the matches()
method, you can also move matches()
here as an abstract method and make other classes implement it, i.e. public abstract boolean matches(UserIdentity that);
, or use generics on the class type so you can do public abstract boolean matches (T that);
if you want to force the input parameter type to be the same as the derived class, but your call on this
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.
i have made UserIdentity abstract - regarding matches , let me see if i can refactor the codes of the various subclasses first
|
||
// Contains the computed raw UID and its bucket ID from identity/map request | ||
public class RawUidResult { | ||
public static RawUidResult OptoutIdentity = new RawUidResult(new byte[33], ""); |
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.
For public static, the naming convention is capitalized snake case, i.e. public static RawUidResult OPT_OUT_IDENTITY
On a separate note, not a really big deal because I think both make sense, but I noticed we sometimes refer to "optout" as "OptOut" and sometimes as "Optout" - do we want this standardized too?
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.
i'll keep the convention for now due to reason given above.
I'll note down the Optout/OptOut point - seems they are split 50/50 ish. Not too important in context of this ticket work tho
public static RefreshResponse Expired = new RefreshResponse(Status.Expired, IdentityTokens.LogoutToken); | ||
public static RefreshResponse Deprecated = new RefreshResponse(Status.Deprecated, IdentityTokens.LogoutToken); | ||
public static RefreshResponse NoActiveKey = new RefreshResponse(Status.NoActiveKey, IdentityTokens.LogoutToken); | ||
public static RefreshResponse Invalid = new RefreshResponse(Status.Invalid, IdentityResponse.OptOutIdentityResponse); |
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.
Similar comment to the other public static
comments, but it should be capitalized snake case here too
if (remoteApiHost == null) { | ||
handler.handle(Future.failedFuture("remote api not set")); | ||
return; | ||
} | ||
|
||
this.webClient.get(remoteApiPort, remoteApiHost, remoteApiPath). | ||
addQueryParam("identity_hash", EncodingUtils.toBase64String(firstLevelHashIdentity.id)) | ||
addQueryParam("identity_hash", EncodingUtils.toBase64String(firstLevelHashIdentity.firstLevelHash)) | ||
.addQueryParam("advertising_id", EncodingUtils.toBase64String(advertisingId)) |
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 want to add a comment here that advertising id
is equivalent to raw UID
?
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.
added
@@ -214,18 +217,19 @@ public AdvertisingToken decodeAdvertisingTokenV2(Buffer b) { | |||
final int siteId = b3.getInt(0); | |||
final int length = b3.getInt(4); | |||
|
|||
final byte[] advertisingId = EncodingUtils.fromBase64(b3.slice(8, 8 + length).getBytes()); | |||
final byte[] getRawUid = EncodingUtils.fromBase64(b3.slice(8, 8 + length).getBytes()); |
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.
I think just rawUid
is fine here
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.
fixed also renamed ``idto
rawUid``` in decodeAdvertisingTokenV3orV4 method below
private byte[] encryptIdentityV2(SourcePublisher sourcePublisher, FirstLevelHashIdentity firstLevelHashIdentity, KeysetKey key) { | ||
return encryptIdentityV2(sourcePublisher, firstLevelHashIdentity.firstLevelHash, firstLevelHashIdentity.privacyBits, | ||
firstLevelHashIdentity.establishedAt, key); | ||
|
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.
Extra newline
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.
fixed
2. Renamed RawUidResult to RawUidResponse 3. rename some id variable to rawUid to make it clearer 4. more comments
…xed the UserIdentity/FirstLevelHashIdentity class uses to HashedDiiIdentity instead in IdentityMapBenchmark and TokenEndecBenchmark
methods to encodeIntoAdvertisingToken or encodeIntoRefreshToken to make it clear what we are encoding into
Refer to ticket description on https://atlassian.thetradedesk.com/jira/browse/UID2-4159