-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add random setting #10
Labels
Comments
How about using |
This is more like an extension of a string setting but without a configurable default value. Instead the default value is generated every time the definition is created. You could test something like this: public class RandomSettingDefinition
extends StringSettingDefinition implements Constructable {
private static final String DEFAULT_ALLOWED_CHARACTERS =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFHIJKLMNOPQRSTUVWXYZ"
private boolean secure = true;
private int length = 20;
private int[] allowedCharacters = DEFAULT_ALLOWED_CHARACTERS.codePoints().toArray();
public void setSecure(boolean secure) {
this.secure = secure;
}
public boolean isSecure() {
return this.secure;
}
public void setAllowedCharacters(String allowedCharacters) {
Preconditions.checkArgument(allowedCharacters.length() > 0);
this.allowedCharacters = allowedCharacters.codePoints().distinct().toArray();
}
public String getAllowedCharacters() {
return Arrays.stream(this.allowedCharacters)
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
}
public void setLength(int length) {
Preconditions.checkArgument(length > 0);
this.length = length;
}
public int getLength() {
return this.length;
}
@Override
public void init() {
String value = (this.secure ? new SecureRandom() : new Random())
.ints(this.length, 0, this.allowedCharacters.length)
.map(idx -> this.allowedCharacters[idx])
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
setDefaultValue(value);
}
} |
Is this issue still open? |
Yes, the issue is still open. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add a new setting type that generates a random string (or number?) at every time the service starts. Can be used for security tokens etc.
See 52North/iceland#32
The text was updated successfully, but these errors were encountered: