Skip to content

Commit

Permalink
HELLODATA-1881 - rename api client
Browse files Browse the repository at this point in the history
  • Loading branch information
Slawomir Wieczorek committed Dec 19, 2024
1 parent 9365b1b commit 8838558
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static ExchangeFilterFunction logRequest() {
}

@Bean
public ApiClient apiClient() {
public ApiClient sftpGoApiClient() {
WebClient webClient = WebClient.builder()
.baseUrl(baseUrl)
.clientConnector(new ReactorClientHttpConnector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@RequiredArgsConstructor
public class SftpGoService {
public static final String ADMIN_GROUP_NAME = "Admin";
private final ApiClient apiClient;
private final ApiClient sftpGoApiClient;
private final S3ConnectionsConfig s3ConnectionsConfig;

@Value("${hello-data.sftpgo.admin-username}")
Expand All @@ -50,28 +50,28 @@ public void init() {

public List<User> getAllUsers() {
refreshToken();
UsersApi usersApi = new UsersApi(apiClient);
UsersApi usersApi = new UsersApi(sftpGoApiClient);
return usersApi.getUsers(0, Integer.MAX_VALUE, "ASC").collectList().block();
}

public User getUser(String username) {
refreshToken();
UsersApi usersApi = new UsersApi(apiClient);
UsersApi usersApi = new UsersApi(sftpGoApiClient);
return usersApi.getUserByUsername(username, 0).block();
}

public void disableUser(String username) {
refreshToken();
User user = getUser(username);
user.setStatus(User.StatusEnum.NUMBER_0);
UsersApi usersApi = new UsersApi(apiClient);
UsersApi usersApi = new UsersApi(sftpGoApiClient);
usersApi.updateUser(username, user, 1).block();
log.info("User {} disabled", username);
}

public void updateUser(User user) {
refreshToken();
UsersApi usersApi = new UsersApi(apiClient);
UsersApi usersApi = new UsersApi(sftpGoApiClient);
usersApi.updateUser(user.getUsername(), user, 1).block();
log.info("User {} updated", user.getUsername());
}
Expand All @@ -80,14 +80,14 @@ public void enableUser(String username) {
refreshToken();
User user = getUser(username);
user.setStatus(User.StatusEnum.NUMBER_1);
UsersApi usersApi = new UsersApi(apiClient);
UsersApi usersApi = new UsersApi(sftpGoApiClient);
usersApi.updateUser(username, user, 1).block();
log.info("User {} enabled", username);
}

public User createUser(String email, String username, String password) {
refreshToken();
UsersApi usersApi = new UsersApi(apiClient);
UsersApi usersApi = new UsersApi(sftpGoApiClient);
User user = new User();
user.setUsername(username);
user.setPassword(password);
Expand All @@ -106,7 +106,7 @@ public User createUser(String email, String username, String password) {

public void createGroup(String dataDomainKey, String dataDomainName, String groupName, List<Permission> permissions) {
refreshToken();
GroupsApi groupsApi = new GroupsApi(apiClient);
GroupsApi groupsApi = new GroupsApi(sftpGoApiClient);
try {
Group existingGroup = groupsApi.getGroupByName(groupName, 0).block();
log.info("Group {} already exists", existingGroup.getName());
Expand All @@ -133,7 +133,7 @@ public void createGroup(String dataDomainKey, String dataDomainName, String grou

private void initAdminGroup() {
refreshToken();
GroupsApi groupsApi = new GroupsApi(apiClient);
GroupsApi groupsApi = new GroupsApi(sftpGoApiClient);
try {
Group existingGroup = groupsApi.getGroupByName(ADMIN_GROUP_NAME, 0).block();
log.info("Admin group '{}' already exists", existingGroup);
Expand All @@ -149,7 +149,7 @@ private void createAdminGroup(GroupsApi groupsApi) {
BaseVirtualFolder baseVirtualFolder = new BaseVirtualFolder();
baseVirtualFolder.setName(ADMIN_GROUP_NAME);
baseVirtualFolder.setMappedPath(adminVirtualFolder);
FoldersApi foldersApi = new FoldersApi(apiClient);
FoldersApi foldersApi = new FoldersApi(sftpGoApiClient);
BaseVirtualFolder createdFolder = foldersApi.addFolder(baseVirtualFolder, 0).block();

Group group = getGroup(createdFolder);
Expand Down Expand Up @@ -195,7 +195,7 @@ private VirtualFolder createVirtualFolder(String dataDomainKey, String dataDomai
baseVirtualFolder.setDescription(dataDomainName);
baseVirtualFolder.setMappedPath("/" + groupName);
baseVirtualFolder.setFilesystem(filesystemConfig);
FoldersApi foldersApi = new FoldersApi(apiClient);
FoldersApi foldersApi = new FoldersApi(sftpGoApiClient);
log.info("Creating folder {}", baseVirtualFolder);

BaseVirtualFolder createdFolder;
Expand Down Expand Up @@ -227,14 +227,14 @@ private void refreshToken() {
}
}

HttpBasicAuth basicAuth = (HttpBasicAuth) apiClient.getAuthentication("BasicAuth");
HttpBasicAuth basicAuth = (HttpBasicAuth) sftpGoApiClient.getAuthentication("BasicAuth");
basicAuth.setUsername(sftpGoAdminUsername);
basicAuth.setPassword(sftpGoAdminPassword);

TokenApi tokenApi = new TokenApi(apiClient);
TokenApi tokenApi = new TokenApi(sftpGoApiClient);
Token token = tokenApi.getToken(null).block();

HttpBearerAuth BearerAuth = (HttpBearerAuth) apiClient.getAuthentication("BearerAuth");
HttpBearerAuth BearerAuth = (HttpBearerAuth) sftpGoApiClient.getAuthentication("BearerAuth");
BearerAuth.setBearerToken(token.getAccessToken());

lastRefreshTime = OffsetDateTime.now();
Expand Down

0 comments on commit 8838558

Please sign in to comment.