use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class ResourceGroupNameTextField method doValidateValue.
@Override
public AzureValidationInfo doValidateValue() {
final AzureValidationInfo info = super.doValidateValue();
if (!AzureValidationInfo.OK.equals(info)) {
return info;
}
final String value = this.getValue();
// validate length
int minLength = 1;
int maxLength = 90;
if (StringUtils.length(value) < minLength) {
return AzureValidationInfo.builder().input(this).message("The value must not be empty.").type(AzureValidationInfo.Type.ERROR).build();
} else if (StringUtils.length(value) > maxLength) {
return AzureValidationInfo.builder().input(this).message(String.format("Resource group names only allow up to %s characters.", maxLength)).type(AzureValidationInfo.Type.ERROR).build();
}
// validate special character
if (!PATTERN.matcher(value).matches()) {
return AzureValidationInfo.builder().input(this).message("Resource group names only allow alphanumeric characters, periods, underscores, hyphens and parenthesis and cannot end in a period.").type(AzureValidationInfo.Type.ERROR).build();
}
// validate availability
try {
if (!Azure.az(AzureGroup.class).checkNameAvailability(subscription.getId(), value)) {
return AzureValidationInfo.builder().input(this).message(value + " already existed.").type(AzureValidationInfo.Type.ERROR).build();
}
} catch (CloudException e) {
return AzureValidationInfo.builder().input(this).message(e.getMessage()).type(AzureValidationInfo.Type.ERROR).build();
}
return AzureValidationInfo.OK;
}
use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class SqlServerRegionValidator method apply.
@Override
public AzureValidationInfo apply(RegionComboBox comboBox) {
AzureSqlServer service = Azure.az(AzureSqlServer.class);
try {
if (service.checkRegionCapability(comboBox.getSubscription().getId(), comboBox.getValue().getName())) {
return AzureValidationInfo.OK;
}
} catch (ManagementException e) {
return AzureValidationInfo.builder().input(comboBox).message(e.getMessage()).type(AzureValidationInfo.Type.ERROR).build();
}
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
return builder.input(comboBox).message(REGION_UNAVAILABLE_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
}
use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class AdminUsernameTextField method doValidateValue.
/**
* Admin username must be at least 1 characters and at most 16 characters.
* Admin username must only contain characters and numbers.
* Admin login name cannot be 'azure_superuser', 'admin', 'administrator', 'root', 'guest' or 'public'
*/
@NotNull
public AzureValidationInfo doValidateValue() {
if (!isValueInitialized()) {
return AzureValidationInfo.UNINITIALIZED;
}
final AzureValidationInfo info = super.doValidateValue();
if (!AzureValidationInfo.OK.equals(info)) {
return info;
}
final String value = this.getValue();
// validate length
if (StringUtils.length(value) < MIN_LENGTH || StringUtils.length(value) > MAX_LENGTH) {
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
return builder.input(this).message(INVALID_LENGTH_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
}
// validate special character
if (!StringUtils.isAlphanumeric(value)) {
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
return builder.input(this).message(INVALID_ALPHANUMERIC_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
}
// validate special character
if (!PATTERN.matcher(value).matches()) {
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
return builder.input(this).message(INVALID_LANGUAGE_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
}
// validate special admin username
if (StringUtils.equalsAnyIgnoreCase(value, INVALID_USERNAMES)) {
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
return builder.input(this).message(INVALID_USERNAMES_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
}
return AzureValidationInfo.OK;
}
use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class PasswordUtils method generatePasswordFieldInput.
public static AzurePasswordFieldInput generatePasswordFieldInput(JPasswordField passwordField, JTextField adminUsernameTextField) {
return new AzurePasswordFieldInput(passwordField) {
@Override
public AzureValidationInfo doValidate() {
final AzureValidationInfo info = super.doValidate();
if (!AzureValidationInfo.OK.equals(info)) {
return info;
}
final String adminUsername = adminUsernameTextField.getText();
final String value = this.getValue();
return PasswordUtils.validatePassword(value, adminUsername, this);
}
};
}
use of com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo in project azure-tools-for-java by Microsoft.
the class PasswordUtils method generateConfirmPasswordFieldInput.
public static AzurePasswordFieldInput generateConfirmPasswordFieldInput(JPasswordField confirmPasswordField, JPasswordField passwordField) {
return new AzurePasswordFieldInput(confirmPasswordField) {
@Override
public AzureValidationInfo doValidate() {
final AzureValidationInfo info = super.doValidate();
if (!AzureValidationInfo.OK.equals(info)) {
return info;
}
final String value = this.getValue();
final char[] password = passwordField.getPassword();
final String passwordAsString = password != null ? String.valueOf(password) : StringUtils.EMPTY;
return PasswordUtils.validateConfirmPassword(value, passwordAsString, this);
}
};
}
Aggregations