mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 17:59:41 +02:00
Add command for creating LRP tokens
Command allows for both one-off creation and bulk import of assignees via file (the latter will be used for the initial import from Play Store). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133048360
This commit is contained in:
parent
1a050554fe
commit
75203918a9
7 changed files with 404 additions and 5 deletions
|
@ -33,6 +33,24 @@ import javax.inject.Named;
|
|||
class DeterministicStringGenerator extends StringGenerator {
|
||||
|
||||
private Iterator<Character> iterator;
|
||||
private final Rule rule;
|
||||
private int counter = 0;
|
||||
|
||||
/** String generation rules. */
|
||||
enum Rule {
|
||||
|
||||
/**
|
||||
* Simple string generation, cycling through sequential letters in the alphabet. May produce
|
||||
* duplicates.
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* Same cyclical pattern as {@link Rule#DEFAULT}, prepending the iteration number and an
|
||||
* underscore. Intended to avoid duplicates.
|
||||
*/
|
||||
PREPEND_COUNTER
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a string using sequential characters in the generator's alphabet, cycling back to the
|
||||
|
@ -45,11 +63,22 @@ class DeterministicStringGenerator extends StringGenerator {
|
|||
for (int i = 0; i < length; i++) {
|
||||
password += iterator.next();
|
||||
}
|
||||
return password;
|
||||
switch (rule) {
|
||||
case PREPEND_COUNTER:
|
||||
return String.format("%04d_%s", counter++, password);
|
||||
case DEFAULT:
|
||||
default:
|
||||
return password;
|
||||
}
|
||||
}
|
||||
|
||||
public DeterministicStringGenerator(@Named("alphabet") String alphabet, Rule rule) {
|
||||
super(alphabet);
|
||||
iterator = Iterators.cycle(charactersOf(alphabet));
|
||||
this.rule = rule;
|
||||
}
|
||||
|
||||
public DeterministicStringGenerator(@Named("alphabet") String alphabet) {
|
||||
super(alphabet);
|
||||
iterator = Iterators.cycle(charactersOf(alphabet));
|
||||
this(alphabet, Rule.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue