use of org.eclipse.linuxtools.docker.core.IRegistryAccount in project linuxtools by eclipse.
the class DockerRegistryAccountPreferencePage method handleEvent.
/**
* @see org.eclipse.swt.widgets.Listener#handleEvent(Event)
*/
@Override
public void handleEvent(Event event) {
if (event.type == SWT.Selection) {
if (event.widget == addButton) {
RegistryAccountDialog dialog = new RegistryAccountDialog(getShell(), "New Registry Account");
if (dialog.open() == Window.OK) {
IRegistryAccount info = dialog.getSignonInformation();
passwords.add(info);
modifications.add(new PasswordModification(PasswordModification.ADD, info));
pwdTableViewer.refresh();
// select the new
pwdTable.select(passwords.size() - 1);
// entry
}
} else if (event.widget == changeButton) {
RegistryAccountDialog dialog = new RegistryAccountDialog(getShell(), "Edit Registry Account");
int index = pwdTable.getSelectionIndex();
IRegistryAccount info = passwords.get(index);
dialog.setInputData(info);
if (dialog.open() == Window.OK) {
// Remove old and add new
info = dialog.getSignonInformation();
IRegistryAccount oldInfo = passwords.remove(index);
passwords.add(index, info);
modifications.add(new PasswordModification(PasswordModification.DELETE, oldInfo));
modifications.add(new PasswordModification(PasswordModification.ADD, info));
pwdTableViewer.refresh();
pwdTable.select(index);
}
} else if (event.widget == removeButton) {
int[] indicies = pwdTable.getSelectionIndices();
for (int idx = indicies.length - 1; idx >= 0; idx--) {
RegistryAccountManager.getInstance().remove(passwords.get(indicies[idx]));
modifications.add(new PasswordModification(PasswordModification.DELETE, passwords.remove(indicies[idx])));
}
pwdTableViewer.refresh();
}
// Update table buttons based on changes
switch(pwdTable.getSelectionCount()) {
case 0:
changeButton.setEnabled(false);
removeButton.setEnabled(false);
break;
case 1:
changeButton.setEnabled(true);
removeButton.setEnabled(true);
break;
default:
changeButton.setEnabled(false);
removeButton.setEnabled(true);
break;
}
}
}
use of org.eclipse.linuxtools.docker.core.IRegistryAccount in project linuxtools by eclipse.
the class RegistryAccountStorageManager method getAccounts.
public List<IRegistryAccount> getAccounts() {
final List<IRegistryAccount> accounts = new ArrayList<>();
final ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
final ISecurePreferences dockerNode = preferences.node(// $NON-NLS-1$
"org.eclipse.linuxtools.docker.ui.accounts");
for (String key : dockerNode.keys()) {
// $NON-NLS-1$
final String[] tokens = key.split(",");
if (tokens.length > 1) {
final String serverAddress = tokens[0];
final String username = tokens[1];
// $NON-NLS-1$
final String email = tokens.length > 2 ? tokens[2] : "";
final RegistryAccountInfo account = new RegistryAccountInfo(serverAddress, username, email, null, false);
accounts.add(account);
}
}
return accounts;
}
use of org.eclipse.linuxtools.docker.core.IRegistryAccount in project linuxtools by eclipse.
the class PullImageCommandHandler method performPullImage.
private void performPullImage(final IDockerConnection connection, final String imageName, final AbstractRegistry registry) {
final Job pullImageJob = new Job(DVMessages.getFormattedString(PULL_IMAGE_JOB_TITLE, imageName)) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask(DVMessages.getString(PULL_IMAGE_JOB_TASK), IProgressMonitor.UNKNOWN);
// handler refresh the images when done
try {
if (registry == null || registry.isDockerHubRegistry()) {
((DockerConnection) connection).pullImage(imageName, new DefaultImagePullProgressHandler(connection, imageName));
} else {
String fullImageName = registry.getServerHost() + '/' + imageName;
if (registry instanceof IRegistryAccount) {
IRegistryAccount account = (IRegistryAccount) registry;
((DockerConnection) connection).pullImage(fullImageName, account, new DefaultImagePullProgressHandler(connection, fullImageName));
} else {
((DockerConnection) connection).pullImage(fullImageName, new DefaultImagePullProgressHandler(connection, fullImageName));
}
}
} catch (final DockerException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_PULLING_IMAGE, imageName), e.getMessage()));
// for now
} catch (InterruptedException | DockerCertificateException e) {
// do nothing
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
pullImageJob.schedule();
}
use of org.eclipse.linuxtools.docker.core.IRegistryAccount in project linuxtools by eclipse.
the class PushImageCommandHandler method performPushImage.
private void performPushImage(final ImagePush wizard, final IDockerConnection connection) {
if (connection == null) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_PUSHING_IMAGE, wizard.getSelectedImageTag()), DVMessages.getFormattedString(NO_CONNECTION)));
return;
}
final Job pushImageJob = new Job(DVMessages.getFormattedString(PUSH_IMAGE_JOB_TITLE, wizard.getSelectedImageTag())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
final IDockerImage image = wizard.getImage();
final String defaultImageNameTag = wizard.getDefaultImageName();
final String selectedImageNameTag = wizard.getSelectedImageTag();
// TODO: remove cast once AbstractRegistry methods are
// part of the IRegistry interface
final AbstractRegistry registry = (AbstractRegistry) wizard.getRegistry();
final boolean forceTagging = wizard.isForceTagging();
final boolean keepTaggedImage = wizard.isKeepTaggedImage();
monitor.beginTask(DVMessages.getString(PUSH_IMAGE_JOB_TASK), IProgressMonitor.UNKNOWN);
// push the image and let the progress
// handler refresh the images when done
final String tmpRegistryTag = getNameToTag(selectedImageNameTag, registry);
boolean tagCreated = false;
try {
// selected)
if (!image.repoTags().contains(tmpRegistryTag) || forceTagging) {
// TODO: remove cast to DockerConnection once the
// 'tagImage' is added in the public API
((DockerConnection) connection).tagImage(defaultImageNameTag, tmpRegistryTag, forceTagging);
tagCreated = true;
}
// push image
if (!registry.isAuthProvided()) {
connection.pushImage(tmpRegistryTag, new DefaultImagePushProgressHandler(connection, tmpRegistryTag));
} else {
final IRegistryAccount registryAccount = (IRegistryAccount) registry;
connection.pushImage(tmpRegistryTag, registryAccount, new DefaultImagePushProgressHandler(connection, tmpRegistryTag));
}
} catch (final DockerException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_PUSHING_IMAGE, defaultImageNameTag), e.getMessage()));
Activator.logErrorMessage(DVMessages.getFormattedString(ERROR_PUSHING_IMAGE, defaultImageNameTag), e);
// for now
} catch (InterruptedException e) {
// do nothing
} finally {
if (tagCreated && !keepTaggedImage) {
try {
connection.removeTag(tmpRegistryTag);
connection.getImages(true);
} catch (Exception e) {
// do nothing
}
}
monitor.done();
}
return Status.OK_STATUS;
}
};
pushImageJob.schedule();
}
Aggregations