use of org.knime.core.node.workflow.Credentials in project knime-core by knime.
the class OpenCredentialVariablesDialogAction method run.
/**
* {@inheritDoc}
*/
@Override
public void run() {
super.run();
// get workflow
final WorkflowManager wf = getWorkflow();
// open the dialog
final Display d = Display.getDefault();
// run in UI thread
d.asyncExec(new Runnable() {
@Override
public void run() {
CredentialsStore store = wf.getCredentialsStore();
CredentialVariablesDialog dialog = new CredentialVariablesDialog(d.getActiveShell(), store, wf.getName());
if (dialog.open() == Window.OK) {
for (String name : store.listNames()) {
store.remove(name);
}
List<Credentials> credentials = dialog.getCredentials();
for (Credentials cred : credentials) {
store.add(cred);
}
}
}
});
}
use of org.knime.core.node.workflow.Credentials in project knime-core by knime.
the class WorkflowConfigArtifactsGenerator method extractWorkflowCredentials.
private static void extractWorkflowCredentials(final WorkflowManager wfm, final JsonObjectBuilder builder) {
Iterable<Credentials> credentials = wfm.getCredentialsStore().getCredentials();
for (Credentials c : credentials) {
JsonObjectBuilder val = Json.createObjectBuilder();
val.add("type", "object");
JsonObjectBuilder login = Json.createObjectBuilder();
login.add("type", "string");
login.add("default", c.getLogin());
val.add("login", login);
JsonObjectBuilder pwd = Json.createObjectBuilder();
pwd.add("type", "string");
pwd.addNull("default");
val.add("password", pwd);
builder.add(CoreConstants.WORKFLOW_CREDENTIALS + c.getName(), val);
}
}
use of org.knime.core.node.workflow.Credentials in project knime-core by knime.
the class GUIWorkflowLoadHelper method loadCredentials.
/**
* {@inheritDoc}
*/
@Override
public List<Credentials> loadCredentials(final List<Credentials> credentialsList) {
// set the ones that were already prompted for into the result list ... don't prompt them again
final List<Credentials> newCredentialsList = new ArrayList<Credentials>();
final List<Credentials> credentialsToBePromptedList = new ArrayList<Credentials>();
for (Credentials c : credentialsList) {
Credentials updatedCredentials = m_promptedCredentials.get(c.getName());
if (updatedCredentials != null) {
newCredentialsList.add(updatedCredentials);
} else {
credentialsToBePromptedList.add(c);
}
}
// prompt for details for the credentials that haven't been prompted for
if (!credentialsToBePromptedList.isEmpty()) {
// run sync'ly in UI thread
m_display.syncExec(new Runnable() {
@Override
public void run() {
CredentialVariablesDialog dialog = new CredentialVariablesDialog(m_display.getActiveShell(), credentialsToBePromptedList, m_workflowName);
if (dialog.open() == Window.OK) {
List<Credentials> updateCredentialsList = dialog.getCredentials();
newCredentialsList.addAll(updateCredentialsList);
updateCredentialsList.stream().filter(c -> StringUtils.isNotEmpty(c.getPassword())).forEach(c -> m_promptedCredentials.put(c.getName(), c));
} else {
newCredentialsList.addAll(credentialsToBePromptedList);
}
}
});
}
return newCredentialsList;
}
use of org.knime.core.node.workflow.Credentials in project knime-core by knime.
the class CredentialVariablesDialog method editCredentials.
private void editCredentials(final Credentials cred, final int selectionIdx) {
CredentialVariablesEditDialog dlg = new CredentialVariablesEditDialog();
dlg.create();
dlg.loadFrom(cred);
if (dlg.open() == Dialog.OK) {
Credentials var = dlg.getCredential();
if (var != null) {
m_table.replace(selectionIdx, var);
m_table.getViewer().refresh();
}
}
}
use of org.knime.core.node.workflow.Credentials in project knime-core by knime.
the class CredentialVariablesDialog method addCredential.
private void addCredential() {
CredentialVariablesEditDialog dialog = new CredentialVariablesEditDialog();
if (dialog.open() == Dialog.CANCEL) {
// if the user has canceled the dialog there is nothing left to do
return;
}
Credentials var = dialog.getCredential();
if (var == null) {
// variables was not created
return;
}
// do not add it do WFM directly -> this is done when closing the dialog
if (!m_table.add(var)) {
MessageDialog.openWarning(getShell(), "Credential already exists", " A credential with the same name and type already exists. " + "Edit this one if you want to change the value.");
} else {
m_table.getViewer().refresh();
}
getShell().forceFocus();
}
Aggregations