Decouple dryRun from SessionMetadata

dryRun is only available via the (sessionless!) tool, and is not
a property of the session.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125203026
This commit is contained in:
cgoldfeder 2016-06-17 14:31:22 -07:00 committed by Ben McIlwain
parent 3ae646d687
commit e359ab5f52
17 changed files with 31 additions and 54 deletions

View file

@ -43,6 +43,7 @@ public class EppConsoleAction implements Runnable {
eppRequestHandler.executeEpp(
new HttpSessionMetadata(session),
new GaeUserCredentials(getUserService().getCurrentUser()),
false, // This endpoint is never a dry run.
inputXmlBytes);
}
}

View file

@ -54,6 +54,7 @@ public final class EppController {
public byte[] handleEppCommand(
SessionMetadata sessionMetadata,
TransportCredentials credentials,
boolean isDryRun,
byte[] inputXmlBytes) {
Trid trid = null;
try {
@ -72,6 +73,7 @@ public final class EppController {
trid,
sessionMetadata,
credentials,
isDryRun,
inputXmlBytes,
metrics,
clock);

View file

@ -42,10 +42,12 @@ public class EppRequestHandler {
public void executeEpp(
SessionMetadata sessionMetadata,
TransportCredentials credentials,
boolean isDryRun,
byte[] inputXmlBytes) {
try {
response.setPayload(new String(
eppController.handleEppCommand(sessionMetadata, credentials, inputXmlBytes), UTF_8));
eppController.handleEppCommand(
sessionMetadata, credentials, isDryRun, inputXmlBytes), UTF_8));
response.setContentType(APPLICATION_EPP_XML);
// Note that we always return 200 (OK) even if the EppController returns an error response.
// This is because returning an non-OK HTTP status code will cause the proxy server to

View file

@ -46,7 +46,11 @@ public class EppTlsAction implements Runnable {
if (!tlsCredentials.hasSni()) {
logger.warning("Request did not include required SNI header.");
}
eppRequestHandler.executeEpp(new HttpSessionMetadata(session), tlsCredentials, inputXmlBytes);
eppRequestHandler.executeEpp(
new HttpSessionMetadata(session),
tlsCredentials,
false, // This endpoint is never a dry run.
inputXmlBytes);
}
}

View file

@ -51,10 +51,10 @@ public class EppToolAction implements Runnable {
new StatelessRequestSessionMetadata(
clientIdentifier,
superuser,
dryRun,
ProtocolDefinition.getVisibleServiceExtensionUris(),
SessionSource.TOOL),
new PasswordOnlyTransportCredentials(),
dryRun,
xml.getBytes(UTF_8));
}

View file

@ -36,7 +36,7 @@ import org.joda.time.DateTime;
/** Run a flow, either transactionally or not, with logging and retrying as needed. */
public class FlowRunner {
private static final String COMMAND_LOG_FORMAT = "EPP Command" + Strings.repeat("\n\t%s", 5);
private static final String COMMAND_LOG_FORMAT = "EPP Command" + Strings.repeat("\n\t%s", 6);
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
@ -44,6 +44,7 @@ public class FlowRunner {
private final EppInput eppInput;
private final Trid trid;
private final SessionMetadata sessionMetadata;
private final boolean isDryRun;
private final TransportCredentials credentials;
private final byte[] inputXmlBytes;
private final EppMetrics metrics;
@ -55,6 +56,7 @@ public class FlowRunner {
Trid trid,
SessionMetadata sessionMetadata,
TransportCredentials credentials,
boolean isDryRun,
byte[] inputXmlBytes,
final EppMetrics metrics,
Clock clock) {
@ -64,6 +66,7 @@ public class FlowRunner {
this.trid = trid;
this.sessionMetadata = sessionMetadata;
this.credentials = credentials;
this.isDryRun = isDryRun;
this.inputXmlBytes = inputXmlBytes;
this.metrics = metrics;
this.clock = clock;
@ -77,7 +80,8 @@ public class FlowRunner {
clientId,
sessionMetadata,
prettyPrint(inputXmlBytes).replaceAll("\n", "\n\t"),
credentials);
credentials,
isDryRun ? "DRY_RUN" : "LIVE");
if (!isTransactional()) {
if (metrics != null) {
metrics.incrementAttempts();
@ -100,7 +104,7 @@ public class FlowRunner {
}
try {
EppOutput output = createAndInitFlow(ofy().getTransactionTime()).run();
if (sessionMetadata.isDryRun()) {
if (isDryRun) {
throw new DryRunException(output);
}
return output;

View file

@ -137,12 +137,6 @@ public abstract class SessionMetadata {
setPropertyChecked(FAILED_LOGIN_ATTEMPTS_KEY, null);
}
// These three methods are here to allow special permissions if a derived class overrides them.
public boolean isDryRun() {
return false;
}
@Override
public String toString() {
return toStringHelper(getClass())

View file

@ -21,19 +21,16 @@ public class StatelessRequestSessionMetadata extends SessionMetadata {
private final String clientId;
private final boolean isSuperuser;
private final boolean isDryRun;
private final Set<String> serviceExtensionUris;
private final SessionSource sessionSource;
public StatelessRequestSessionMetadata(
String clientId,
boolean isSuperuser,
boolean isDryRun,
Set<String> serviceExtensionUris,
SessionSource source) {
this.clientId = clientId;
this.isSuperuser = isSuperuser;
this.isDryRun = isDryRun;
this.serviceExtensionUris = serviceExtensionUris;
this.sessionSource = source;
}
@ -48,11 +45,6 @@ public class StatelessRequestSessionMetadata extends SessionMetadata {
return isSuperuser;
}
@Override
public boolean isDryRun() {
return isDryRun;
}
@Override
public Set<String> getServiceExtensionUris() {
return serviceExtensionUris;

View file

@ -109,6 +109,7 @@ final class ValidateLoginCredentialsCommand implements RemoteApiCommand, GtechCo
clientCertificateHash,
Optional.of(clientIpAddress),
"placeholder"), // behave as if we have SNI on, since we're validating a cert
false,
inputXmlBytes,
null,
new SystemClock()).run()), UTF_8));

View file

@ -81,7 +81,6 @@ public class CheckApiAction implements Runnable {
new StatelessRequestSessionMetadata(
RegistryEnvironment.get().config().getCheckApiServletRegistrarClientId(),
false,
false,
ImmutableSet.of(FEE_0_6.getUri()),
SessionSource.HTTP);
@ -121,6 +120,7 @@ public class CheckApiAction implements Runnable {
Trid.create(getClass().getSimpleName()),
sessionMetadata,
new PasswordOnlyTransportCredentials(),
false,
inputXmlBytes,
null,
clock)