From 5f29459e3a8ab53bb6898307468edf39185d0df8 Mon Sep 17 00:00:00 2001 From: Jan Horvath Date: Wed, 20 Dec 2023 14:30:15 +0100 Subject: [PATCH] Don't create OCI Vault secrets with empty datasource name --- .../actions/AddDbConnectionToVault.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/AddDbConnectionToVault.java b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/AddDbConnectionToVault.java index a5fac3c9887a..1c324b94ac10 100644 --- a/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/AddDbConnectionToVault.java +++ b/enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/AddDbConnectionToVault.java @@ -139,7 +139,8 @@ "CreatingSecret=Creating secret {0}", "UpdatingSecret=Updating secret {0}", "UpdatingVault=Updating {0} Vault", - "ReadingSecrets=Reading existing Secrets" + "ReadingSecrets=Reading existing Secrets", + "DatasourceEmpty=Datasource name cannot be empty" }) public class AddDbConnectionToVault implements ActionListener { @@ -437,6 +438,9 @@ class OverwriteStep implements Step { @Override public Step prepare(Result result) { this.result = result; + if (result.datasourceName == null || result.datasourceName.isEmpty()) { + return this; + } List secrets = SecretNode.getSecrets().apply(result.vault); this.dsNames = secrets.stream() .map(s -> extractDatasourceName(s.getName())) @@ -447,6 +451,9 @@ public Step prepare(Result result) { @Override public NotifyDescriptor createInput() { + if (result.datasourceName == null || result.datasourceName.isEmpty()) { + return new NotifyDescriptor.QuickPick("", Bundle.DatasourceEmpty(), Collections.emptyList(), false); + } List yesNo = new ArrayList(); yesNo.add(new Item(Bundle.AddVersion(), "")); yesNo.add(new Item(Bundle.Cancel(), "")); @@ -474,7 +481,7 @@ public Result getValue() { @Override public boolean onlyOneChoice() { - return !dsNames.contains(result.datasourceName); + return dsNames != null && !dsNames.contains(result.datasourceName); } } @@ -664,10 +671,16 @@ Object getResult() { public void actionPerformed(ActionEvent e) { Multistep multistep = new Multistep(new TenancyStep()); - NotifyDescriptor.ComposedInput ci = new NotifyDescriptor.ComposedInput(Bundle.AddADB(), 3, multistep.createInput()); + NotifyDescriptor.ComposedInput ci = new NotifyDescriptor.ComposedInput(Bundle.AddADBToVault(), 3, multistep.createInput()); if (DialogDescriptor.OK_OPTION == DialogDisplayer.getDefault().notify(ci)) { if (multistep.getResult() != null) { - addDbConnectionToVault((Result) multistep.getResult()); + Result result = (Result) multistep.getResult(); + if (result.datasourceName == null || result.datasourceName.isEmpty()) { + NotifyDescriptor.Message msg = new NotifyDescriptor.Message(Bundle.DatasourceEmpty()); + DialogDisplayer.getDefault().notify(msg); + return; + } + addDbConnectionToVault(result); } }