Search in sources :

Example 1 with AzureValidationInfo

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;
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) CloudException(com.microsoft.azure.CloudException)

Example 2 with AzureValidationInfo

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();
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) AzureSqlServer(com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer) ManagementException(com.azure.core.management.exception.ManagementException)

Example 3 with AzureValidationInfo

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;
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 4 with AzureValidationInfo

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);
        }
    };
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) AzurePasswordFieldInput(com.microsoft.azure.toolkit.intellij.common.component.AzurePasswordFieldInput)

Example 5 with AzureValidationInfo

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);
        }
    };
}
Also used : AzureValidationInfo(com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo) AzurePasswordFieldInput(com.microsoft.azure.toolkit.intellij.common.component.AzurePasswordFieldInput)

Aggregations

AzureValidationInfo (com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo)8 ManagementException (com.azure.core.management.exception.ManagementException)2 AzurePasswordFieldInput (com.microsoft.azure.toolkit.intellij.common.component.AzurePasswordFieldInput)2 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)2 Nonnull (javax.annotation.Nonnull)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 CloudException (com.microsoft.azure.CloudException)1 CheckNameAvailabilityResultEntity (com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity)1 AzureSqlServer (com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer)1