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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations