Search in sources :

Example 1 with ICluster

use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.

the class AccountService method getToken.

public String getToken(IResource t) {
    String token = null;
    ICluster cluster = getModel().getClusters().get(0);
    List<IAccount> identities = cluster.getAccounts();
    if (identities.isEmpty()) {
        token = performLogin(cluster, null);
    } else {
        IAccount account = identities.get(0);
        AccountStatus status = getStatus(account);
        switch(status) {
            case VALID:
                token = account.getAccessToken();
                break;
            case NEEDS_REFRESH:
                token = performRefresh(account);
                break;
            case NEEDS_LOGIN:
                token = performLogin(cluster, account);
                break;
        }
    }
    return token;
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) ICluster(org.jboss.tools.openshift.io.core.model.ICluster)

Example 2 with ICluster

use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.

the class MainPreferencePage method performOk.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
	 */
@Override
public boolean performOk() {
    if (removed) {
        ICluster cluster = AccountService.getDefault().getModel().getClusters().get(0);
        if (!cluster.getAccounts().isEmpty()) {
            IAccount account = cluster.getAccounts().get(0);
            cluster.removeAccount(account);
            cluster.save();
        }
    }
    return true;
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) ICluster(org.jboss.tools.openshift.io.core.model.ICluster)

Example 3 with ICluster

use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.

the class AccountModel method save.

@Override
public void save() {
    clusters.forEach(ICluster::save);
    Preferences accountRoot = getAccountsPreferences();
    ISecurePreferences accountSecureRoot = getSecureAccountsPreferences();
    removed.forEach(id -> {
        removeAccount(id, accountRoot, accountSecureRoot);
    });
    removed.clear();
}
Also used : ICluster(org.jboss.tools.openshift.io.core.model.ICluster) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 4 with ICluster

use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.

the class AccountModelTest method testAddRemoveAccount.

@Test
public void testAddRemoveAccount() {
    IAccountModel m = AccountService.getDefault().getModel();
    assertNotNull(m);
    final Boolean[] checkAdded = new Boolean[] { false };
    final Boolean[] checkRemoved = new Boolean[] { false };
    IAccountModelListener listener = new AccountModelAdapter() {

        @Override
        public void accountAdded(IAccountModel source, IAccount account) {
            checkAdded[0] = true;
        }

        @Override
        public void accountRemoved(IAccountModel source, IAccount account) {
            checkRemoved[0] = true;
        }
    };
    m.addListener(listener);
    try {
        ICluster cluster = m.createCluster("id1");
        m.addCluster(cluster);
        List<ICluster> clusters = m.getClusters();
        assertEquals(2, clusters.size());
        assertEquals(0, cluster.getAccounts().size());
        IAccount account = cluster.createAccount("id2");
        cluster.addAccount(account);
        assertEquals(1, cluster.getAccounts().size());
        cluster.removeAccount(account);
        assertEquals(0, cluster.getAccounts().size());
        m.removeCluster(cluster);
        clusters = m.getClusters();
        assertEquals(1, clusters.size());
        assertTrue(checkAdded[0]);
        assertTrue(checkRemoved[0]);
    } finally {
        m.removeListener(listener);
    }
}
Also used : IAccountModel(org.jboss.tools.openshift.io.core.model.IAccountModel) IAccount(org.jboss.tools.openshift.io.core.model.IAccount) IAccountModelListener(org.jboss.tools.openshift.io.core.model.IAccountModelListener) ICluster(org.jboss.tools.openshift.io.core.model.ICluster) AccountModelAdapter(org.jboss.tools.openshift.io.core.model.AccountModelAdapter) Test(org.junit.Test)

Example 5 with ICluster

use of org.jboss.tools.openshift.io.core.model.ICluster in project jbosstools-openshift by jbosstools.

the class AccountModelTest method testAddRemoveCluster.

@Test
public void testAddRemoveCluster() {
    IAccountModel m = AccountService.getDefault().getModel();
    assertNotNull(m);
    final Boolean[] checkAdded = new Boolean[] { false };
    final Boolean[] checkRemoved = new Boolean[] { false };
    IAccountModelListener listener = new AccountModelAdapter() {

        @Override
        public void clusterAdded(IAccountModel source, ICluster cluster) {
            checkAdded[0] = true;
        }

        @Override
        public void clusterRemoved(IAccountModel source, ICluster cluster) {
            checkRemoved[0] = true;
        }
    };
    m.addListener(listener);
    try {
        ICluster cluster = m.createCluster("id1");
        m.addCluster(cluster);
        List<ICluster> clusters = m.getClusters();
        assertEquals(2, clusters.size());
        m.removeCluster(cluster);
        clusters = m.getClusters();
        assertEquals(1, clusters.size());
        assertTrue(checkAdded[0]);
        assertTrue(checkRemoved[0]);
    } finally {
        m.removeListener(listener);
    }
}
Also used : IAccountModel(org.jboss.tools.openshift.io.core.model.IAccountModel) IAccountModelListener(org.jboss.tools.openshift.io.core.model.IAccountModelListener) ICluster(org.jboss.tools.openshift.io.core.model.ICluster) AccountModelAdapter(org.jboss.tools.openshift.io.core.model.AccountModelAdapter) Test(org.junit.Test)

Aggregations

ICluster (org.jboss.tools.openshift.io.core.model.ICluster)5 IAccount (org.jboss.tools.openshift.io.core.model.IAccount)3 AccountModelAdapter (org.jboss.tools.openshift.io.core.model.AccountModelAdapter)2 IAccountModel (org.jboss.tools.openshift.io.core.model.IAccountModel)2 IAccountModelListener (org.jboss.tools.openshift.io.core.model.IAccountModelListener)2 Test (org.junit.Test)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)1 Preferences (org.osgi.service.prefs.Preferences)1