Merge "Log agent version over SSH"
This commit is contained in:
@@ -217,7 +217,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>,
|
||||
|
||||
private void log(final int rc) {
|
||||
if (logged.compareAndSet(false, true)) {
|
||||
log.onExecute(cmd, rc);
|
||||
log.onExecute(cmd, rc, ctx.getSession());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -47,6 +47,7 @@ class SshLog implements LifecycleListener {
|
||||
private static final String P_WAIT = "queueWaitTime";
|
||||
private static final String P_EXEC = "executionTime";
|
||||
private static final String P_STATUS = "status";
|
||||
private static final String P_AGENT = "agent";
|
||||
|
||||
private final Provider<SshSession> session;
|
||||
private final Provider<Context> context;
|
||||
@@ -115,7 +116,7 @@ class SshLog implements LifecycleListener {
|
||||
audit(null, "FAIL", "AUTH");
|
||||
}
|
||||
|
||||
void onExecute(DispatchCommand dcmd, int exitValue) {
|
||||
void onExecute(DispatchCommand dcmd, int exitValue, SshSession sshSession) {
|
||||
final Context ctx = context.get();
|
||||
ctx.finished = TimeUtil.nowMs();
|
||||
|
||||
@@ -144,6 +145,10 @@ class SshLog implements LifecycleListener {
|
||||
break;
|
||||
}
|
||||
event.setProperty(P_STATUS, status);
|
||||
String peerAgent = sshSession.getPeerAgent();
|
||||
if (peerAgent != null) {
|
||||
event.setProperty(P_AGENT, peerAgent);
|
||||
}
|
||||
|
||||
if (async != null) {
|
||||
async.append(event);
|
||||
|
@@ -31,6 +31,7 @@ public final class SshLogLayout extends Layout {
|
||||
private static final String P_WAIT = "queueWaitTime";
|
||||
private static final String P_EXEC = "executionTime";
|
||||
private static final String P_STATUS = "status";
|
||||
private static final String P_AGENT = "agent";
|
||||
|
||||
private final Calendar calendar;
|
||||
private long lastTimeMillis;
|
||||
@@ -66,6 +67,7 @@ public final class SshLogLayout extends Layout {
|
||||
opt(P_WAIT, buf, event);
|
||||
opt(P_EXEC, buf, event);
|
||||
opt(P_STATUS, buf, event);
|
||||
opt(P_AGENT, buf, event);
|
||||
|
||||
buf.append('\n');
|
||||
return buf.toString();
|
||||
|
@@ -35,6 +35,7 @@ public class SshSession {
|
||||
private volatile CurrentUser identity;
|
||||
private volatile String username;
|
||||
private volatile String authError;
|
||||
private volatile String peerAgent;
|
||||
|
||||
SshSession(final int sessionId, SocketAddress peer) {
|
||||
this.sessionId = sessionId;
|
||||
@@ -72,6 +73,14 @@ public class SshSession {
|
||||
return remoteAsString;
|
||||
}
|
||||
|
||||
public String getPeerAgent() {
|
||||
return peerAgent;
|
||||
}
|
||||
|
||||
public void setPeerAgent(String agent) {
|
||||
peerAgent = agent;
|
||||
}
|
||||
|
||||
String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import com.google.gerrit.server.git.ReceiveCommits;
|
||||
import com.google.gerrit.server.git.VisibleRefFilter;
|
||||
import com.google.gerrit.sshd.AbstractGitCommand;
|
||||
import com.google.gerrit.sshd.CommandMetaData;
|
||||
import com.google.gerrit.sshd.SshSession;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.errors.TooLargeObjectInPackException;
|
||||
@@ -55,6 +56,9 @@ final class Receive extends AbstractGitCommand {
|
||||
@Inject
|
||||
private IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||
|
||||
@Inject
|
||||
private SshSession session;
|
||||
|
||||
private final Set<Account.Id> reviewerId = new HashSet<>();
|
||||
private final Set<Account.Id> ccId = new HashSet<>();
|
||||
|
||||
@@ -91,6 +95,7 @@ final class Receive extends AbstractGitCommand {
|
||||
ReceivePack rp = receive.getReceivePack();
|
||||
try {
|
||||
rp.receive(in, out, err);
|
||||
session.setPeerAgent(rp.getPeerUserAgent());
|
||||
} catch (UnpackException badStream) {
|
||||
// In case this was caused by the user pushing an object whose size
|
||||
// is larger than the receive.maxObjectSizeLimit gerrit.config parameter
|
||||
|
@@ -78,6 +78,7 @@ final class Upload extends AbstractGitCommand {
|
||||
up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks));
|
||||
try {
|
||||
up.upload(in, out, err);
|
||||
session.setPeerAgent(up.getPeerUserAgent());
|
||||
} catch (UploadValidationException e) {
|
||||
// UploadValidationException is used by the UploadValidators to
|
||||
// stop the uploadPack. We do not want this exception to go beyond this
|
||||
|
Reference in New Issue
Block a user