Search in sources :

Example 46 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerHostStep method doValidate.

public ValidationInfo doValidate(boolean shakeOnError) {
    if (dockerImageNameTextField.getText() == null || dockerImageNameTextField.getText().equals("")) {
        ValidationInfo info = new ValidationInfo("Missing Docker image name", dockerImageNameTextField);
        dockerImageNameLabel.setVisible(true);
        setDialogButtonsState(false);
        if (shakeOnError)
            model.getSelectDockerWizardDialog().DialogShaker(info);
        return info;
    }
    dockerImageDescription.dockerImageName = dockerImageNameTextField.getText();
    model.setDockerContainerName(AzureDockerUtils.getDefaultDockerContainerName(dockerImageDescription.dockerImageName));
    //    if (dockerArtifactPath.getText() == null || !AzureDockerValidationUtils.validateDockerArtifactPath(dockerArtifactPath.getText())) {
    //      ValidationInfo info = new ValidationInfo("Invalid artifact file name", dockerArtifactPath);
    //      dockerArtifactPathLabel.setVisible(true);
    //      setDialogButtonsState(false);
    //      if (shakeOnError)
    //        model.getSelectDockerWizardDialog().DialogShaker(info);
    //      return info;
    //    }
    //    String artifactFilePath = dockerArtifactPath.getText();
    String dockerArtifactPath = (String) dockerArtifactComboboxWithBrowse.getComboBox().getSelectedItem();
    if (dockerArtifactPath == null || !AzureDockerValidationUtils.validateDockerArtifactPath(dockerArtifactPath)) {
        ValidationInfo info = new ValidationInfo("Invalid artifact file name", dockerArtifactComboboxWithBrowse);
        dockerArtifactPathLabel.setVisible(true);
        setDialogButtonsState(false);
        if (shakeOnError)
            model.getSelectDockerWizardDialog().DialogShaker(info);
        return info;
    }
    String artifactFileName = new File(dockerArtifactPath).getName();
    dockerImageDescription.artifactName = artifactFileName.indexOf(".") > 0 ? artifactFileName.substring(0, artifactFileName.lastIndexOf(".")) : "";
    if (dockerImageDescription.artifactName.isEmpty()) {
        ValidationInfo info = new ValidationInfo("Invalid artifact file name (it is missing a file name)", dockerArtifactComboboxWithBrowse);
        //      ValidationInfo info = new ValidationInfo("Invalid artifact file name (it's missing a file name)", dockerArtifactPath);
        dockerArtifactPathLabel.setVisible(true);
        setDialogButtonsState(false);
        if (shakeOnError)
            model.getSelectDockerWizardDialog().DialogShaker(info);
        return info;
    }
    if (dockerImageDescription.artifactPath == null || !dockerImageDescription.artifactPath.equals(dockerArtifactPath)) {
        dockerImageDescription.artifactPath = dockerArtifactPath;
        dockerImageDescription.hasRootDeployment = artifactFileName.toLowerCase().matches(".*.jar");
        model.setPredefinedDockerfileOptions(artifactFileName);
    }
    if (dockerHostsTableSelection == null && !dockerImageDescription.hasNewDockerHost) {
        ValidationInfo info = new ValidationInfo("Please check a Docker host or create a new", dockerHostsTable);
        setDialogButtonsState(false);
        if (shakeOnError)
            model.getSelectDockerWizardDialog().DialogShaker(info);
        return info;
    }
    if (!dockerImageDescription.hasNewDockerHost) {
        dockerImageDescription.host = dockerHostsTableSelection.host;
        dockerImageDescription.sid = dockerImageDescription.host.sid;
    }
    setDialogButtonsState(true);
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 47 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project azure-tools-for-java by Microsoft.

the class AzureNewDockerLoginStep method doValidate.

private ValidationInfo doValidate(boolean shakeOnError) {
    if (dockerHostImportKeyvaultCredsRadioButton.isSelected()) {
        // read key vault secrets and set the credentials for the new host
        AzureDockerCertVault certVault = (AzureDockerCertVault) dockerHostImportKeyvaultComboBox.getSelectedItem();
        if (certVault == null) {
            ValidationInfo info = AzureDockerUIResources.validateComponent("Missing vault", rootConfigureContainerPanel, dockerHostImportKeyvaultComboBox, dockerHostImportKeyvaultComboLabel);
            setDialogButtonsState(false);
            if (shakeOnError) {
                model.DialogShaker(info);
            }
            return info;
        }
        dockerHostImportKeyvaultComboLabel.setVisible(false);
        newHost.certVault.name = certVault.name;
        newHost.certVault.resourceGroupName = certVault.resourceGroupName;
        newHost.certVault.region = certVault.region;
        newHost.certVault.uri = certVault.uri;
        AzureDockerCertVaultOps.copyVaultLoginCreds(newHost.certVault, certVault);
        AzureDockerCertVaultOps.copyVaultSshKeys(newHost.certVault, certVault);
        AzureDockerCertVaultOps.copyVaultTlsCerts(newHost.certVault, certVault);
        // create a weak link (resource tag) between the virtual machine and the key vault
        //  we will not create/update the key vault unless the user checks the specific option
        newHost.certVault.hostName = null;
        newHost.hasKeyVault = true;
    } else {
        // reset key vault info
        newHost.hasKeyVault = false;
        newHost.certVault.name = null;
        newHost.certVault.uri = null;
        dockerHostImportKeyvaultComboLabel.setVisible(false);
        // User name
        String vmUsername = dockerHostUsernameTextField.getText();
        if (vmUsername == null || vmUsername.isEmpty() || !AzureDockerValidationUtils.validateDockerHostUserName(vmUsername)) {
            ValidationInfo info = AzureDockerUIResources.validateComponent("Missing username", vmCredsPanel, dockerHostUsernameTextField, dockerHostUsernameLabel);
            credsTabbedPane.setSelectedComponent(vmCredsPanel);
            setDialogButtonsState(false);
            if (shakeOnError) {
                model.DialogShaker(info);
            }
            return info;
        }
        newHost.certVault.vmUsername = vmUsername;
        // Password login
        String vmPwd1 = new String(dockerHostFirstPwdField.getPassword());
        String vmPwd2 = new String(dockerHostSecondPwdField.getPassword());
        if ((dockerHostNoSshRadioButton.isSelected() || dockerHostFirstPwdField.getPassword().length > 0 || dockerHostSecondPwdField.getPassword().length > 0) && (vmPwd1.isEmpty() || vmPwd2.isEmpty() || !vmPwd1.equals(vmPwd2) || !AzureDockerValidationUtils.validateDockerHostPassword(vmPwd1))) {
            ValidationInfo info = AzureDockerUIResources.validateComponent("Incorrect password", vmCredsPanel, dockerHostFirstPwdField, dockerHostFirstPwdLabel);
            credsTabbedPane.setSelectedComponent(vmCredsPanel);
            setDialogButtonsState(false);
            if (shakeOnError) {
                model.DialogShaker(info);
            }
            return info;
        }
        dockerHostFirstPwdLabel.setVisible(false);
        if (dockerHostFirstPwdField.getPassword().length > 0) {
            newHost.certVault.vmPwd = new String(dockerHostFirstPwdField.getPassword());
            newHost.hasPwdLogIn = true;
        } else {
            newHost.certVault.vmPwd = null;
            newHost.hasPwdLogIn = false;
        }
        // SSH key auto generated
        if (dockerHostAutoSshRadioButton.isSelected()) {
            AzureDockerCertVault certVault = AzureDockerCertVaultOps.generateSSHKeys(null, "SSH keys for " + newHost.name);
            AzureDockerCertVaultOps.copyVaultSshKeys(newHost.certVault, certVault);
            newHost.hasSSHLogIn = true;
        }
        if (dockerHostNoSshRadioButton.isSelected()) {
            newHost.hasSSHLogIn = false;
            newHost.certVault.sshKey = null;
            newHost.certVault.sshPubKey = null;
        }
        // SSH key imported from local file directory
        if (dockerHostImportSshRadioButton.isSelected()) {
            if (dockerHostImportSSHBrowseTextField.getText() == null || dockerHostImportSSHBrowseTextField.getText().isEmpty() || !AzureDockerValidationUtils.validateDockerHostSshDirectory(dockerHostImportSSHBrowseTextField.getText())) {
                ValidationInfo info = AzureDockerUIResources.validateComponent("SSH key files were not found in the selected directory", vmCredsPanel, dockerHostImportSSHBrowseTextField, dockerHostImportSSHBrowseLabel);
                credsTabbedPane.setSelectedComponent(vmCredsPanel);
                setDialogButtonsState(false);
                if (shakeOnError) {
                    model.DialogShaker(info);
                }
                return info;
            } else {
                AzureDockerCertVault certVault = AzureDockerCertVaultOps.getSSHKeysFromLocalFile(dockerHostImportSSHBrowseTextField.getText());
                AzureDockerCertVaultOps.copyVaultSshKeys(newHost.certVault, certVault);
                newHost.hasSSHLogIn = true;
            }
        }
        // No Docker daemon security
        if (dockerHostNoTlsRadioButton.isSelected()) {
            newHost.isTLSSecured = false;
        }
        // TLS certs auto generated
        if (dockerHostAutoTlsRadioButton.isSelected()) {
            AzureDockerCertVault certVault = AzureDockerCertVaultOps.generateTLSCerts("TLS certs for " + newHost.name);
            AzureDockerCertVaultOps.copyVaultTlsCerts(newHost.certVault, certVault);
            newHost.isTLSSecured = true;
        }
        // TLS certs imported from local file directory
        if (dockerHostImportTlsRadioButton.isSelected()) {
            if (dockerHostImportTLSBrowseTextField.getText() == null || dockerHostImportTLSBrowseTextField.getText().isEmpty() || !AzureDockerValidationUtils.validateDockerHostTlsDirectory(dockerHostImportTLSBrowseTextField.getText())) {
                ValidationInfo info = AzureDockerUIResources.validateComponent("TLS certificates files were not found in the selected directory", vmCredsPanel, dockerHostImportTLSBrowseTextField, dockerHostImportTLSBrowseLabel);
                credsTabbedPane.setSelectedComponent(vmCredsPanel);
                setDialogButtonsState(false);
                if (shakeOnError) {
                    model.DialogShaker(info);
                }
                return info;
            } else {
                AzureDockerCertVault certVault = AzureDockerCertVaultOps.getTLSCertsFromLocalFile(dockerHostImportTLSBrowseTextField.getText());
                AzureDockerCertVaultOps.copyVaultTlsCerts(newHost.certVault, certVault);
                newHost.isTLSSecured = true;
            }
        }
    }
    // Docker daemon port settings
    if (dockerDaemonPortTextField.getText() == null || dockerDaemonPortTextField.getText().isEmpty() || !AzureDockerValidationUtils.validateDockerHostPort(dockerDaemonPortTextField.getText())) {
        ValidationInfo info = AzureDockerUIResources.validateComponent("Invalid Docker daemon port settings", daemonCredsPanel, dockerDaemonPortTextField, dockerDaemonPortLabel);
        credsTabbedPane.setSelectedComponent(daemonCredsPanel);
        setDialogButtonsState(false);
        if (shakeOnError) {
            model.DialogShaker(info);
        }
        return info;
    }
    newHost.port = dockerDaemonPortTextField.getText();
    // create new key vault for storing the credentials
    if (dockerHostSaveCredsCheckBox.isSelected()) {
        if (dockerHostNewKeyvaultTextField.getText() == null || dockerHostNewKeyvaultTextField.getText().isEmpty() || !AzureDockerValidationUtils.validateDockerHostKeyvaultName(dockerHostNewKeyvaultTextField.getText(), dockerManager, true)) {
            ValidationInfo info = AzureDockerUIResources.validateComponent("Incorrect Azure Key Vault", rootConfigureContainerPanel, dockerHostNewKeyvaultTextField, dockerHostNewKeyvaultLabel);
            setDialogButtonsState(false);
            return info;
        } else {
            newHost.hasKeyVault = true;
            newHost.certVault.name = dockerHostNewKeyvaultTextField.getText();
            newHost.certVault.hostName = (newHost.name != null) ? newHost.name : null;
            newHost.certVault.region = (newHost.hostVM.region != null) ? newHost.hostVM.region : null;
            newHost.certVault.resourceGroupName = (newHost.hostVM.resourceGroupName != null) ? newHost.hostVM.resourceGroupName : null;
            newHost.certVault.uri = (newHost.hostVM.region != null && newHost.hostVM.resourceGroupName != null) ? "https://" + newHost.certVault.name + ".vault.azure.net" : null;
        }
    } else {
        newHost.certVault.hostName = null;
    }
    setDialogButtonsState(true);
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) AzureDockerCertVault(com.microsoft.azure.docker.model.AzureDockerCertVault)

Example 48 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project azure-tools-for-java by Microsoft.

the class CreateRedisCacheForm method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    redisCacheNameValue = txtRedisName.getText();
    selectedResGrpValue = newResGrp ? txtNewResGrp.getText() : cbUseExist.getSelectedItem().toString();
    selectedLocationValue = ((Location) cbLocations.getSelectedItem()).inner().name();
    selectedPriceTierValue = cbPricing.getSelectedItem().toString();
    if (redisCacheNameValue.length() > REDIS_CACHE_MAX_NAME_LENGTH || !redisCacheNameValue.matches(DNS_NAME_REGEX)) {
        return new ValidationInfo(INVALID_REDIS_CACHE_NAME, txtRedisName);
    }
    try {
        for (RedisCache existingRedisCache : azureManager.getAzure(currentSub.getSubscriptionId()).redisCaches().list()) {
            if (existingRedisCache.name().equals(redisCacheNameValue)) {
                return new ValidationInfo(String.format(VALIDATION_FORMAT, redisCacheNameValue), txtRedisName);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) RedisCache(com.microsoft.azure.management.redis.RedisCache) IOException(java.io.IOException) Location(com.microsoft.azure.management.resources.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 49 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project azure-tools-for-java by Microsoft.

the class TableEntityForm method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    final TableModel model = propertiesTable.getModel();
    final String partitionKey = model.getValueAt(0, 3).toString();
    final String rowKey = model.getValueAt(1, 3).toString();
    for (int row = 2; row != model.getRowCount(); row++) {
        TableEntity.PropertyType propertyType = (TableEntity.PropertyType) model.getValueAt(row, 2);
        String name = model.getValueAt(row, 1).toString();
        String value = model.getValueAt(row, 3).toString();
        if (!isValidPropertyName(name)) {
            return new ValidationInfo(String.format("The property name \"%s\" is invalid", name), propertiesTable);
        }
        TableEntity.Property property = getProperty(value, propertyType);
        if (property == null) {
            return new ValidationInfo(String.format("The field %s has an invalid value for its type", name), propertiesTable);
        }
    }
    if (tableEntity == null) {
        for (TableEntity te : tableEntityList) {
            if (te.getPartitionKey().equals(partitionKey) && te.getRowKey().equals(rowKey)) {
                return new ValidationInfo("An entity already exists with this partition key and row key pair", propertiesTable);
            }
        }
    }
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) Nullable(org.jetbrains.annotations.Nullable)

Example 50 with ValidationInfo

use of com.intellij.openapi.ui.ValidationInfo in project azure-tools-for-java by Microsoft.

the class AzureNewDockerHostStep method validateDockerOSType.

private ValidationInfo validateDockerOSType(boolean shakeOnError) {
    // OS type
    KnownDockerVirtualMachineImage osType = (KnownDockerVirtualMachineImage) dockerHostOSTypeComboBox.getSelectedItem();
    if (osType == null) {
        ValidationInfo info = AzureDockerUIResources.validateComponent("OS type not found", vmKindPanel, dockerHostOSTypeComboBox, null);
        hostDetailsTabbedPane.setSelectedComponent(vmKindPanel);
        setDialogButtonsState(false);
        if (shakeOnError) {
            model.DialogShaker(info);
        }
        return info;
    }
    newHost.hostOSType = DockerHost.DockerHostOSType.valueOf(osType.toString());
    newHost.hostVM.osHost = osType.getAzureOSHost();
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo)

Aggregations

ValidationInfo (com.intellij.openapi.ui.ValidationInfo)53 Nullable (org.jetbrains.annotations.Nullable)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 File (java.io.File)7 Module (com.intellij.openapi.module.Module)3 Pattern (java.util.regex.Pattern)3 DocumentEvent (javax.swing.event.DocumentEvent)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)2 Project (com.intellij.openapi.project.Project)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 Configuration (com.android.tools.idea.gradle.structure.dependencies.android.Configuration)1 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)1 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)1 PsAndroidModule (com.android.tools.idea.gradle.structure.model.android.PsAndroidModule)1 PsBuildType (com.android.tools.idea.gradle.structure.model.android.PsBuildType)1 PsLibraryAndroidDependency (com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency)1 FilterData (com.android.tools.idea.logcat.PersistentAndroidLogFilters.FilterData)1