Skip to content

Commit

Permalink
HELLODATA-1881 - adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Slawomir Wieczorek committed Dec 12, 2024
1 parent ef74cf5 commit 9ba9c7f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import static ch.bedag.dap.hellodata.commons.sidecars.events.HDEvent.CREATE_USER;

Expand All @@ -27,14 +28,15 @@ public void createUser(SubsystemUserUpdate subsystemUserUpdate) {
try {
log.info("------- Received SFTPGo user creation request {}", subsystemUserUpdate);
User user = sftpgoService.getUser(subsystemUserUpdate.getUsername());
if (user == null) {
sftpgoService.createUser(subsystemUserUpdate.getPassword(), subsystemUserUpdate.getUsername(), subsystemUserUpdate.getPassword());
if (subsystemUserUpdate.isSendBackUsersList()) {
sftpGoUserResourceProviderService.publishUsers();
}
}
log.info("User {} already created", user);
} catch (WebClientResponseException.NotFound notFound) {
log.debug("", notFound);
sftpgoService.createUser(subsystemUserUpdate.getEmail(), subsystemUserUpdate.getUsername(), subsystemUserUpdate.getPassword());
} catch (Exception e) {
log.error("Could not create user {}", subsystemUserUpdate.getEmail(), e);
}
if (subsystemUserUpdate.isSendBackUsersList()) {
sftpGoUserResourceProviderService.publishUsers();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import ch.bedag.dap.hellodata.commons.nats.annotation.JetStreamSubscribe;
import ch.bedag.dap.hellodata.commons.sidecars.resources.v1.user.data.UserContextRoleUpdate;
import ch.bedag.dap.hellodata.sidecars.sftpgo.client.model.User;
import ch.bedag.dap.hellodata.sidecars.sftpgo.service.SftpGoService;
import ch.bedag.dap.hellodata.sidecars.sftpgo.service.resource.SftpGoUserResourceProviderService;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import java.util.List;
import java.util.UUID;

import static ch.bedag.dap.hellodata.commons.sidecars.events.HDEvent.UPDATE_USER_CONTEXT_ROLE;

Expand All @@ -24,8 +26,30 @@ public class SftpGoUpdateUserContextRoleConsumer {
@JetStreamSubscribe(event = UPDATE_USER_CONTEXT_ROLE)
public void processContextRoleUpdate(UserContextRoleUpdate userContextRoleUpdate) {
log.info("-=-=-=-= RECEIVED USER CONTEXT ROLES UPDATE: payload: {}", userContextRoleUpdate);
List<UserContextRoleUpdate.ContextRole> contextRoles = userContextRoleUpdate.getContextRoles().stream()
.filter(contextRole -> contextRole.getParentContextKey() != null).toList();
User user = fetchUser(userContextRoleUpdate);


// Optional<UserContextRoleUpdate.ContextRole> businessDomainRole = userContextRoleUpdate.getContextRoles().stream()
// .filter(contextRole -> contextRole.getParentContextKey() == null).findFirst();
// businessDomainRole.ifPresent(businessDomainRoleContext -> {
// HdRoleName roleName = businessDomainRoleContext.getRoleName();
// if (roleName != HdRoleName.NONE) {
//
// }
// })

}

private User fetchUser(UserContextRoleUpdate userContextRoleUpdate) {
try {
return sftpgoService.getUser(userContextRoleUpdate.getUsername());
log.info("User {} already created", user);
} catch (WebClientResponseException.NotFound notFound) {
log.debug("", notFound);
return sftpgoService.createUser(userContextRoleUpdate.getEmail(), userContextRoleUpdate.getUsername(), UUID.randomUUID().toString());
} catch (Exception e) {
log.error("Could not create user {}", userContextRoleUpdate.getEmail(), e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ public void enableUser(String username) {
log.info("User {} enabled", username);
}

public void createUser(String email, String username, String password) {
public User createUser(String email, String username, String password) {
refreshToken();
UsersApi usersApi = new UsersApi(apiClient);
User user = new User();
user.setUsername(username);
user.setPassword(password);
user.setEmail(email);
user.setStatus(User.StatusEnum.NUMBER_1);
usersApi.addUser(user, 0).block();
User createdUser = usersApi.addUser(user, 0).block();
usersApi.disableUser2fa(username).block();
log.info("User {} created", username);
return createdUser;
}

public void createGroup(String dataDomainKey, String dataDomainName) {
Expand Down

0 comments on commit 9ba9c7f

Please sign in to comment.