mirror of
https://github.com/google/nomulus.git
synced 2025-05-12 22:38:16 +02:00
Consolidate all Set parameter parsing
Currently, we have two different ways to parse a "set" parameter: key=value1&key=value2&key=value3... and keys=value1,value2,value3 This is error prone for several reasons: - different parts of the code must be "synchronized" to use the same style (the place that creates the request, and the place that parses the request) - for the key=value1&key=value2, we often use the same key name for the single value and the set value. This can result in subtle bugs where part of the code will successfully read the key assuming there's only one key (and will get the first key=value1, ignoring the rest) Here we transition everything to the keys=value1,value2,value3 method. This one was chosen because: - it's shorter - it's more intuitive for users - the key name is plural, differentiating it from the singular key=value that other requests might need ----------------------------------- To make sure there are not "transition issues", we will continue to support (with warnings) the key=value1&key=value2 parameter parsing until we're sure we haven't forgotten to update any part of the code. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=198810681
This commit is contained in:
parent
3960207502
commit
9d2b1e7572
20 changed files with 290 additions and 181 deletions
|
@ -30,45 +30,53 @@ import javax.servlet.http.HttpServletRequest;
|
|||
@Module
|
||||
public final class CronModule {
|
||||
|
||||
public static final String ENDPOINT_PARAM = "endpoint";
|
||||
public static final String QUEUE_PARAM = "queue";
|
||||
public static final String FOR_EACH_REAL_TLD_PARAM = "forEachRealTld";
|
||||
public static final String FOR_EACH_TEST_TLD_PARAM = "forEachTestTld";
|
||||
public static final String RUN_IN_EMPTY_PARAM = "runInEmpty";
|
||||
public static final String EXCLUDE_PARAM = "exclude";
|
||||
public static final String JITTER_SECONDS_PARAM = "jitterSeconds";
|
||||
|
||||
@Provides
|
||||
@Parameter("endpoint")
|
||||
@Parameter(ENDPOINT_PARAM)
|
||||
static String provideEndpoint(HttpServletRequest req) {
|
||||
return extractRequiredParameter(req, "endpoint");
|
||||
return extractRequiredParameter(req, ENDPOINT_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("exclude")
|
||||
@Parameter(EXCLUDE_PARAM)
|
||||
static ImmutableSet<String> provideExcludes(HttpServletRequest req) {
|
||||
return extractSetOfParameters(req, "exclude");
|
||||
return extractSetOfParameters(req, EXCLUDE_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("queue")
|
||||
@Parameter(QUEUE_PARAM)
|
||||
static String provideQueue(HttpServletRequest req) {
|
||||
return extractRequiredParameter(req, "queue");
|
||||
return extractRequiredParameter(req, QUEUE_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("runInEmpty")
|
||||
@Parameter(RUN_IN_EMPTY_PARAM)
|
||||
static boolean provideRunInEmpty(HttpServletRequest req) {
|
||||
return extractBooleanParameter(req, "runInEmpty");
|
||||
return extractBooleanParameter(req, RUN_IN_EMPTY_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("forEachRealTld")
|
||||
@Parameter(FOR_EACH_REAL_TLD_PARAM)
|
||||
static boolean provideForEachRealTld(HttpServletRequest req) {
|
||||
return extractBooleanParameter(req, "forEachRealTld");
|
||||
return extractBooleanParameter(req, FOR_EACH_REAL_TLD_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("forEachTestTld")
|
||||
@Parameter(FOR_EACH_TEST_TLD_PARAM)
|
||||
static boolean provideForEachTestTld(HttpServletRequest req) {
|
||||
return extractBooleanParameter(req, "forEachTestTld");
|
||||
return extractBooleanParameter(req, FOR_EACH_TEST_TLD_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("jitterSeconds")
|
||||
@Parameter(JITTER_SECONDS_PARAM)
|
||||
static Optional<Integer> provideJitterSeconds(HttpServletRequest req) {
|
||||
return extractOptionalIntParameter(req, "jitterSeconds");
|
||||
return extractOptionalIntParameter(req, JITTER_SECONDS_PARAM);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue