From 8838558a93c2a7ee18c342675256a13e851eacb1 Mon Sep 17 00:00:00 2001 From: Slawomir Wieczorek Date: Thu, 19 Dec 2024 10:37:19 +0100 Subject: [PATCH] HELLODATA-1881 - rename api client --- .../sftpgo/config/WebClientConfig.java | 2 +- .../sftpgo/service/SftpGoService.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/config/WebClientConfig.java b/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/config/WebClientConfig.java index 255cded4..8951241b 100644 --- a/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/config/WebClientConfig.java +++ b/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/config/WebClientConfig.java @@ -27,7 +27,7 @@ private static ExchangeFilterFunction logRequest() { } @Bean - public ApiClient apiClient() { + public ApiClient sftpGoApiClient() { WebClient webClient = WebClient.builder() .baseUrl(baseUrl) .clientConnector(new ReactorClientHttpConnector( diff --git a/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/service/SftpGoService.java b/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/service/SftpGoService.java index d866aa40..74441e64 100644 --- a/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/service/SftpGoService.java +++ b/hello-data-sidecars/hello-data-sidecar-sftpgo/src/main/java/ch/bedag/dap/hellodata/sidecars/sftpgo/service/SftpGoService.java @@ -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}") @@ -50,13 +50,13 @@ public void init() { public List 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(); } @@ -64,14 +64,14 @@ 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()); } @@ -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); @@ -106,7 +106,7 @@ public User createUser(String email, String username, String password) { public void createGroup(String dataDomainKey, String dataDomainName, String groupName, List 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()); @@ -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); @@ -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); @@ -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; @@ -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();