Add IdentifiedUser#getLoggableName()
Callers that want to include a unique identifier of an IdentifiedUser into a log currently use getUserName() but this method may return null which makes the log useless. Instead of letting every caller handle the null case add a new getLoggableName() method to IdentifiedUser that is guaranteed to return a unique name for the user. We can't offer this method on CurrentUser level since CurrentUser has no access to the account and a user name may not be set. Change-Id: I79433c5e37f8d5186e281c2590578e0aecf85e71 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -301,6 +301,11 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
return state().getUserName().orElse(null);
|
return state().getUserName().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return unique name of the user for logging, never {@code null} */
|
||||||
|
public String getLoggableName() {
|
||||||
|
return getUserName() != null ? getUserName() : "a/" + getAccountId().get();
|
||||||
|
}
|
||||||
|
|
||||||
public Account getAccount() {
|
public Account getAccount() {
|
||||||
return state().getAccount();
|
return state().getAccount();
|
||||||
}
|
}
|
||||||
|
@@ -918,7 +918,7 @@ class ReceiveCommits {
|
|||||||
reject(cmd, "invalid project configuration");
|
reject(cmd, "invalid project configuration");
|
||||||
logError(
|
logError(
|
||||||
"User "
|
"User "
|
||||||
+ user.getUserName()
|
+ user.getLoggableName()
|
||||||
+ " tried to push invalid project configuration "
|
+ " tried to push invalid project configuration "
|
||||||
+ cmd.getNewId().name()
|
+ cmd.getNewId().name()
|
||||||
+ " for "
|
+ " for "
|
||||||
@@ -994,7 +994,7 @@ class ReceiveCommits {
|
|||||||
reject(cmd, "invalid project configuration");
|
reject(cmd, "invalid project configuration");
|
||||||
logError(
|
logError(
|
||||||
"User "
|
"User "
|
||||||
+ user.getUserName()
|
+ user.getLoggableName()
|
||||||
+ " tried to push invalid project configuration "
|
+ " tried to push invalid project configuration "
|
||||||
+ cmd.getNewId().name()
|
+ cmd.getNewId().name()
|
||||||
+ " for "
|
+ " for "
|
||||||
|
@@ -447,7 +447,7 @@ public class CommitValidators {
|
|||||||
} catch (ConfigInvalidException | IOException e) {
|
} catch (ConfigInvalidException | IOException e) {
|
||||||
log.error(
|
log.error(
|
||||||
"User "
|
"User "
|
||||||
+ user.getUserName()
|
+ user.getLoggableName()
|
||||||
+ " tried to push an invalid project configuration "
|
+ " tried to push an invalid project configuration "
|
||||||
+ receiveEvent.command.getNewId().name()
|
+ receiveEvent.command.getNewId().name()
|
||||||
+ " for project "
|
+ " for project "
|
||||||
|
Reference in New Issue
Block a user