fix: removed secrets creation on event
Signed-off-by: xbaran4 <pbaran@redhat.com>pull/117/head
parent
048e35863c
commit
8aa275101a
|
|
@ -27,10 +27,8 @@ import javax.inject.Inject;
|
|||
import org.eclipse.che.api.core.NotFoundException;
|
||||
import org.eclipse.che.api.core.ServerException;
|
||||
import org.eclipse.che.api.core.model.user.User;
|
||||
import org.eclipse.che.api.core.notification.EventSubscriber;
|
||||
import org.eclipse.che.api.user.server.PreferenceManager;
|
||||
import org.eclipse.che.api.user.server.UserManager;
|
||||
import org.eclipse.che.api.user.server.event.PostUserPersistedEvent;
|
||||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
|
||||
import org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory;
|
||||
|
|
@ -40,14 +38,12 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* On namespace provisioning, creates k8s {@link Secret} profile and preferences
|
||||
* from information about the User.
|
||||
*
|
||||
* Implements {@link EventSubscriber<PostUserPersistedEvent>} for updating these Secrets.
|
||||
* On namespace provisioning, creates k8s {@link Secret} profile and preferences from information
|
||||
* about the User.
|
||||
*
|
||||
* @author Pavol Baran
|
||||
*/
|
||||
public class NamespaceProvisioner implements EventSubscriber<PostUserPersistedEvent> {
|
||||
public class NamespaceProvisioner {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NamespaceProvisioner.class);
|
||||
private static final String USER_PROFILE_SECRET_NAME = "user-profile";
|
||||
private static final String USER_PREFERENCES_SECRET_NAME = "user-preferences";
|
||||
|
|
@ -79,16 +75,13 @@ public class NamespaceProvisioner implements EventSubscriber<PostUserPersistedEv
|
|||
try {
|
||||
createOrUpdateSecrets(userManager.getById(namespaceResolutionContext.getUserId()));
|
||||
} catch (NotFoundException | ServerException e) {
|
||||
LOG.error("Could not find current user. Skipping creation of user information secrets.", e);
|
||||
throw new InfrastructureException(
|
||||
"Could not find current user. Because of this, cannot create user profile and preferences secrets.",
|
||||
e);
|
||||
}
|
||||
return kubernetesNamespaceMeta;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onEvent(PostUserPersistedEvent event) {
|
||||
createOrUpdateSecrets(event.getUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates k8s user profile and user preferences k8s secrets. This serves as a way for
|
||||
* DevWorkspaces to acquire information about the user.
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ package org.eclipse.che.workspace.infrastructure.kubernetes.provision;
|
|||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
|
@ -108,20 +107,11 @@ public class NamespaceProvisionerTest {
|
|||
assertEquals(createdSecrets.get(0).getMetadata().getName(), "user-profile");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateNoSecretOnException()
|
||||
@Test(expectedExceptions = InfrastructureException.class)
|
||||
public void shouldCreateNoSecretWithInvalidUser()
|
||||
throws InfrastructureException, NotFoundException, ServerException {
|
||||
when(userManager.getById(USER_ID)).thenThrow(new ServerException("Test server exception"));
|
||||
when(userManager.getById(USER_ID)).thenThrow(new NotFoundException("Test exception"));
|
||||
namespaceProvisioner.provision(new NamespaceResolutionContext(null, USER_ID, USER_NAME));
|
||||
assertTrue(
|
||||
kubernetesServer
|
||||
.getClient()
|
||||
.secrets()
|
||||
.inNamespace(USER_NAMESPACE)
|
||||
.list()
|
||||
.getItems()
|
||||
.isEmpty());
|
||||
verifyNoInteractions(clientFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue