Search in sources :

Example 1 with IRegistryAccount

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;
        }
    }
}
Also used : IRegistryAccount(org.eclipse.linuxtools.docker.core.IRegistryAccount) RegistryAccountDialog(org.eclipse.linuxtools.internal.docker.ui.wizards.RegistryAccountDialog)

Example 2 with IRegistryAccount

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;
}
Also used : ArrayList(java.util.ArrayList) IRegistryAccount(org.eclipse.linuxtools.docker.core.IRegistryAccount) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 3 with IRegistryAccount

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();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRegistryAccount(org.eclipse.linuxtools.docker.core.IRegistryAccount) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) Job(org.eclipse.core.runtime.jobs.Job) DefaultImagePullProgressHandler(org.eclipse.linuxtools.internal.docker.core.DefaultImagePullProgressHandler)

Example 4 with IRegistryAccount

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();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractRegistry(org.eclipse.linuxtools.docker.core.AbstractRegistry) DefaultImagePushProgressHandler(org.eclipse.linuxtools.internal.docker.core.DefaultImagePushProgressHandler) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IRegistryAccount(org.eclipse.linuxtools.docker.core.IRegistryAccount) Job(org.eclipse.core.runtime.jobs.Job) DockerException(org.eclipse.linuxtools.docker.core.DockerException)

Aggregations

IRegistryAccount (org.eclipse.linuxtools.docker.core.IRegistryAccount)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 DockerException (org.eclipse.linuxtools.docker.core.DockerException)2 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)2 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)2 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)1 ArrayList (java.util.ArrayList)1 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)1 AbstractRegistry (org.eclipse.linuxtools.docker.core.AbstractRegistry)1 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)1 DefaultImagePullProgressHandler (org.eclipse.linuxtools.internal.docker.core.DefaultImagePullProgressHandler)1 DefaultImagePushProgressHandler (org.eclipse.linuxtools.internal.docker.core.DefaultImagePushProgressHandler)1 RegistryAccountDialog (org.eclipse.linuxtools.internal.docker.ui.wizards.RegistryAccountDialog)1