From b13cbd8ccab6bd2ef96be77d3ca2a7d8ed3dcf7f Mon Sep 17 00:00:00 2001 From: lijiahang Date: Thu, 21 Sep 2023 13:50:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=BB=E6=9C=BA=E8=BA=AB?= =?UTF-8?q?=E4=BB=BD=E9=A1=B5=E9=9D=A2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/ErrorMessage.java | 2 + .../common/security/PasswordModifier.java | 40 ++++ .../common/security/UpdatePasswordAction.java | 28 +++ .../controller/HostIdentityController.http | 37 +--- .../controller/HostIdentityController.java | 42 +--- .../asset/controller/HostKeyController.http | 2 +- .../asset/controller/HostKeyController.java | 4 +- .../asset/convert/HostIdentityConvert.java | 15 +- .../orion/ops/module/asset/dao/HostDAO.java | 15 -- .../ops/module/asset/dao/HostIdentityDAO.java | 17 +- .../ops/module/asset/dao/HostKeyDAO.java | 16 -- .../asset/define/HostCacheKeyDefine.java | 8 + .../entity/dto/HostIdentityCacheDTO.java | 31 +++ .../entity/export/HostIdentityExport.java | 67 ------ .../host/HostIdentityUpdateRequest.java | 7 +- .../request/host/HostKeyUpdateRequest.java | 4 +- .../asset/entity/vo/HostIdentityVO.java | 19 +- .../asset/service/HostIdentityService.java | 63 +----- .../service/impl/HostIdentityServiceImpl.java | 199 +++++++++--------- .../service/impl/HostKeyServiceImpl.java | 37 ++-- .../resources/mapper/HostIdentityMapper.xml | 6 + orion-ops-ui/src/api/asset/host-identity.ts | 28 +-- orion-ops-ui/src/api/asset/host-key.ts | 6 +- orion-ops-ui/src/api/meta/tag.ts | 4 +- orion-ops-ui/src/assets/style/global.less | 4 + .../asset/host-key/host-key-selector.vue | 52 +++++ orion-ops-ui/src/store/modules/cache/index.ts | 5 +- orion-ops-ui/src/store/modules/cache/types.ts | 8 +- .../components/host-identity-form-drawer.vue | 145 ------------- .../components/host-identity-form-modal.vue | 30 ++- .../components/host-identity-table.vue | 75 +++---- .../src/views/asset/host-identity/index.vue | 26 ++- .../host-identity/types/table.columns.ts | 24 +-- .../host-key/components/host-key-table.vue | 6 +- .../src/views/asset/host-key/index.vue | 2 +- .../asset/host/components/host-table.vue | 8 + .../views/user/role/components/role-table.vue | 4 + .../views/user/user/components/user-table.vue | 6 +- .../views/user/user/types/table.columns.ts | 1 - 39 files changed, 444 insertions(+), 649 deletions(-) create mode 100644 orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/PasswordModifier.java create mode 100644 orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/UpdatePasswordAction.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/HostIdentityCacheDTO.java delete mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/export/HostIdentityExport.java create mode 100644 orion-ops-ui/src/components/asset/host-key/host-key-selector.vue delete mode 100644 orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-drawer.vue diff --git a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/ErrorMessage.java b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/ErrorMessage.java index c689df11..c2031568 100644 --- a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/ErrorMessage.java +++ b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/constant/ErrorMessage.java @@ -21,6 +21,8 @@ public interface ErrorMessage { String DATA_ABSENT = "数据不存在"; + String KEY_ABSENT = "秘钥不存在"; + String CONFIG_ABSENT = "配置不存在"; String DATA_PRESENT = "数据已存在"; diff --git a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/PasswordModifier.java b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/PasswordModifier.java new file mode 100644 index 00000000..f8d32439 --- /dev/null +++ b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/PasswordModifier.java @@ -0,0 +1,40 @@ +package com.orion.ops.framework.common.security; + +import com.orion.lang.utils.Booleans; +import com.orion.lang.utils.Strings; +import com.orion.ops.framework.common.constant.Const; +import com.orion.ops.framework.common.utils.CryptoUtils; + +/** + * 密码修改器 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/21 11:35 + */ +public class PasswordModifier { + + private PasswordModifier() { + } + + /** + * 获取新密码 + * + * @param action action + * @return password + */ + public static String getEncryptNewPassword(UpdatePasswordAction action) { + if (Booleans.isTrue(action.getUseNewPassword())) { + // 使用新密码 + String password = action.getPassword(); + if (Strings.isBlank(password)) { + return Const.EMPTY; + } else { + return CryptoUtils.encryptAsString(password); + } + } else { + return null; + } + } + +} diff --git a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/UpdatePasswordAction.java b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/UpdatePasswordAction.java new file mode 100644 index 00000000..8a74c51d --- /dev/null +++ b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/security/UpdatePasswordAction.java @@ -0,0 +1,28 @@ +package com.orion.ops.framework.common.security; + +import java.io.Serializable; + +/** + * 更新密码操作 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/21 11:32 + */ +public interface UpdatePasswordAction extends Serializable { + + /** + * 是否使用新密码 + * + * @return use + */ + Boolean getUseNewPassword(); + + /** + * 获取密码 + * + * @return password + */ + String getPassword(); + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.http b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.http index c3822fad..4146e068 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.http +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.http @@ -31,24 +31,10 @@ Authorization: {{token}} ### 通过 id 批量查询主机身份 -GET {{baseUrl}}/asset/host-identity/list?idList=1,2,3 +GET {{baseUrl}}/asset/host-identity/list Authorization: {{token}} -### 查询主机身份 -POST {{baseUrl}}/asset/host-identity/list-all -Content-Type: application/json -Authorization: {{token}} - -{ - "id": "", - "name": "", - "username": "", - "password": "", - "keyId": "" -} - - ### 分页查询主机身份 POST {{baseUrl}}/asset/host-identity/query Content-Type: application/json @@ -69,24 +55,3 @@ Authorization: {{token}} DELETE {{baseUrl}}/asset/host-identity/delete?id=1 Authorization: {{token}} - -### 通过 id 批量删除主机身份 -DELETE {{baseUrl}}/asset/host-identity/delete-batch?idList=1,2,3 -Authorization: {{token}} - - -### 导出主机身份 -POST {{baseUrl}}/asset/host-identity/export -Content-Type: application/json -Authorization: {{token}} - -{ - "id": "", - "name": "", - "username": "", - "password": "", - "keyId": "" -} - - -### diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.java index a6f2e20c..ba323554 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostIdentityController.java @@ -5,11 +5,11 @@ import com.orion.ops.framework.common.annotation.IgnoreLog; import com.orion.ops.framework.common.annotation.RestWrapper; import com.orion.ops.framework.common.constant.IgnoreLogMode; import com.orion.ops.framework.common.valid.group.Page; -import com.orion.ops.module.asset.service.*; -import com.orion.ops.module.asset.entity.vo.*; -import com.orion.ops.module.asset.entity.request.host.*; -import com.orion.ops.module.asset.entity.export.*; -import com.orion.ops.module.asset.convert.*; +import com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest; +import com.orion.ops.module.asset.entity.vo.HostIdentityVO; +import com.orion.ops.module.asset.service.HostIdentityService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -19,8 +19,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.List; /** @@ -67,19 +65,11 @@ public class HostIdentityController { @IgnoreLog(IgnoreLogMode.RET) @GetMapping("/list") - @Operation(summary = "通过 id 批量查询主机身份") + @Operation(summary = "查询主机身份") @Parameter(name = "idList", description = "idList", required = true) @PreAuthorize("@ss.hasPermission('asset:host-identity:query')") - public List getHostIdentityList(@RequestParam("idList") List idList) { - return hostIdentityService.getHostIdentityByIdList(idList); - } - - @IgnoreLog(IgnoreLogMode.RET) - @PostMapping("/list-all") - @Operation(summary = "查询主机身份") - @PreAuthorize("@ss.hasPermission('asset:host-identity:query')") - public List getHostIdentityListAll(@Validated @RequestBody HostIdentityQueryRequest request) { - return hostIdentityService.getHostIdentityList(request); + public List getHostIdentityList() { + return hostIdentityService.getHostIdentityList(); } @IgnoreLog(IgnoreLogMode.RET) @@ -98,21 +88,5 @@ public class HostIdentityController { return hostIdentityService.deleteHostIdentityById(id); } - @DeleteMapping("/delete-batch") - @Operation(summary = "通过 id 批量删除主机身份") - @Parameter(name = "idList", description = "idList", required = true) - @PreAuthorize("@ss.hasPermission('asset:host-identity:delete')") - public Integer batchDeleteHostIdentity(@RequestParam("idList") List idList) { - return hostIdentityService.batchDeleteHostIdentityByIdList(idList); - } - - @PostMapping("/export") - @Operation(summary = "导出主机身份") - @PreAuthorize("@ss.hasPermission('asset:host-identity:export')") - public void exportHostIdentity(@Validated @RequestBody HostIdentityQueryRequest request, - HttpServletResponse response) throws IOException { - hostIdentityService.exportHostIdentity(request, response); - } - } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.http b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.http index 43c9f2c9..c523c5e1 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.http +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.http @@ -30,7 +30,7 @@ GET {{baseUrl}}/asset/host-key/get?id=1 Authorization: {{token}} ### 查询主机秘钥 -POST {{baseUrl}}/asset/host-key/list-all +POST {{baseUrl}}/asset/host-key/list Content-Type: application/json Authorization: {{token}} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java index 0454709c..b8f176da 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/HostKeyController.java @@ -64,10 +64,10 @@ public class HostKeyController { } @IgnoreLog(IgnoreLogMode.RET) - @PostMapping("/list-all") + @PostMapping("/list") @Operation(summary = "查询主机秘钥") @PreAuthorize("@ss.hasPermission('asset:host-key:query')") - public List getHostKeyListAll() { + public List getHostKeyList() { return hostKeyService.getHostKeyList(); } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostIdentityConvert.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostIdentityConvert.java index 3be84d79..619d9a22 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostIdentityConvert.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/HostIdentityConvert.java @@ -1,10 +1,11 @@ package com.orion.ops.module.asset.convert; -import com.orion.ops.module.asset.entity.domain.*; -import com.orion.ops.module.asset.entity.vo.*; -import com.orion.ops.module.asset.entity.request.host.*; -import com.orion.ops.module.asset.entity.export.*; -import com.orion.ops.module.asset.convert.*; +import com.orion.ops.module.asset.entity.domain.HostIdentityDO; +import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO; +import com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest; +import com.orion.ops.module.asset.entity.vo.HostIdentityVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -30,7 +31,9 @@ public interface HostIdentityConvert { HostIdentityVO to(HostIdentityDO domain); - HostIdentityExport toExport(HostIdentityDO domain); + HostIdentityVO to(HostIdentityCacheDTO cache); + + HostIdentityCacheDTO toCache(HostIdentityDO domain); List to(List list); diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostDAO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostDAO.java index 30969e1a..ff6add96 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostDAO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostDAO.java @@ -1,6 +1,5 @@ package com.orion.ops.module.asset.dao; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.ops.framework.mybatis.core.mapper.IMapper; import com.orion.ops.module.asset.entity.domain.HostDO; import org.apache.ibatis.annotations.Mapper; @@ -15,18 +14,4 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface HostDAO extends IMapper { - /** - * 获取查询条件 - * - * @param entity entity - * @return 查询条件 - */ - default LambdaQueryWrapper queryCondition(HostDO entity) { - return this.wrapper() - .eq(HostDO::getId, entity.getId()) - .eq(HostDO::getName, entity.getName()) - .eq(HostDO::getCode, entity.getCode()) - .eq(HostDO::getAddress, entity.getAddress()); - } - } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostIdentityDAO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostIdentityDAO.java index 28ea0bfa..39286a14 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostIdentityDAO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostIdentityDAO.java @@ -1,9 +1,9 @@ package com.orion.ops.module.asset.dao; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.ops.framework.mybatis.core.mapper.IMapper; import com.orion.ops.module.asset.entity.domain.HostIdentityDO; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 主机身份 Mapper 接口 @@ -16,18 +16,11 @@ import org.apache.ibatis.annotations.Mapper; public interface HostIdentityDAO extends IMapper { /** - * 获取查询条件 + * 设置 keyId 为 null * - * @param entity entity - * @return 查询条件 + * @param keyId keyId + * @return effect */ - default LambdaQueryWrapper queryCondition(HostIdentityDO entity) { - return this.wrapper() - .eq(HostIdentityDO::getId, entity.getId()) - .eq(HostIdentityDO::getName, entity.getName()) - .eq(HostIdentityDO::getUsername, entity.getUsername()) - .eq(HostIdentityDO::getPassword, entity.getPassword()) - .eq(HostIdentityDO::getKeyId, entity.getKeyId()); - } + int setKeyWithNull(@Param("keyId") Long keyId); } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostKeyDAO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostKeyDAO.java index 7d9e7346..0a45b3a0 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostKeyDAO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/HostKeyDAO.java @@ -1,6 +1,5 @@ package com.orion.ops.module.asset.dao; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.ops.framework.mybatis.core.mapper.IMapper; import com.orion.ops.module.asset.entity.domain.HostKeyDO; import org.apache.ibatis.annotations.Mapper; @@ -15,19 +14,4 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface HostKeyDAO extends IMapper { - /** - * 获取查询条件 - * - * @param entity entity - * @return 查询条件 - */ - default LambdaQueryWrapper queryCondition(HostKeyDO entity) { - return this.wrapper() - .eq(HostKeyDO::getId, entity.getId()) - .eq(HostKeyDO::getName, entity.getName()) - .eq(HostKeyDO::getPublicKey, entity.getPublicKey()) - .eq(HostKeyDO::getPrivateKey, entity.getPrivateKey()) - .eq(HostKeyDO::getPassword, entity.getPassword()); - } - } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/HostCacheKeyDefine.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/HostCacheKeyDefine.java index 54f605f4..190cac81 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/HostCacheKeyDefine.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/HostCacheKeyDefine.java @@ -2,6 +2,7 @@ package com.orion.ops.module.asset.define; import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.CacheKeyDefine; +import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO; import com.orion.ops.module.asset.entity.dto.HostKeyCacheDTO; import java.util.concurrent.TimeUnit; @@ -22,4 +23,11 @@ public interface HostCacheKeyDefine { .timeout(3, TimeUnit.DAYS) .build(); + CacheKeyDefine HOST_IDENTITY = new CacheKeyBuilder() + .key("host:identity:list") + .desc("主机身份列表") + .type(HostIdentityCacheDTO.class) + .timeout(3, TimeUnit.DAYS) + .build(); + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/HostIdentityCacheDTO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/HostIdentityCacheDTO.java new file mode 100644 index 00000000..d1073937 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/HostIdentityCacheDTO.java @@ -0,0 +1,31 @@ +package com.orion.ops.module.asset.entity.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 主机身份缓存 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/21 12:00 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "HostIdentityCacheDTO", description = "主机身份缓存") +public class HostIdentityCacheDTO implements Serializable { + + @Schema(description = "id") + private Long id; + + @Schema(description = "名称") + private String name; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/export/HostIdentityExport.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/export/HostIdentityExport.java deleted file mode 100644 index 199656a4..00000000 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/export/HostIdentityExport.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.orion.ops.module.asset.entity.export; - -import com.orion.lang.utils.time.Dates; -import com.orion.office.excel.annotation.ExportField; -import com.orion.office.excel.annotation.ExportSheet; -import com.orion.office.excel.annotation.ExportTitle; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -import java.io.Serializable; -import java.util.*; - -/** - * 主机身份 导出对象 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023-9-20 11:55 - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@ExportTitle(title = HostIdentityExport.TITLE) -@ExportSheet(name = "主机身份", filterHeader = true, freezeHeader = true, indexToSort = true) -@Schema(name = "HostIdentityExport", description = "主机身份导出对象") -public class HostIdentityExport implements Serializable { - - public static final String TITLE = "主机身份导出"; - - @Schema(description = "id") - @ExportField(index = 0, header = "id", width = 16) - private Long id; - - @Schema(description = "名称") - @ExportField(index = 1, header = "名称", width = 16) - private String name; - - @Schema(description = "用户名") - @ExportField(index = 2, header = "用户名", width = 16) - private String username; - - @Schema(description = "用户密码") - @ExportField(index = 3, header = "用户密码", width = 16) - private String password; - - @Schema(description = "秘钥id") - @ExportField(index = 4, header = "秘钥id", width = 16) - private Long keyId; - - @ExportField(index = 5, header = "创建时间", width = 16, format = Dates.YMD_HMS) - @Schema(description = "创建时间") - private Date createTime; - - @Schema(description = "修改时间") - @ExportField(index = 6, header = "修改时间", width = 16, format = Dates.YMD_HMS) - private Date updateTime; - - @Schema(description = "创建人") - @ExportField(index = 7, header = "创建人", width = 16) - private String creator; - - @Schema(description = "修改人") - @ExportField(index = 8, header = "修改人", width = 16) - private String updater; - -} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostIdentityUpdateRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostIdentityUpdateRequest.java index e3de0b41..c68e5731 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostIdentityUpdateRequest.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostIdentityUpdateRequest.java @@ -1,5 +1,6 @@ package com.orion.ops.module.asset.entity.request.host; +import com.orion.ops.framework.common.security.UpdatePasswordAction; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -9,7 +10,6 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import java.io.Serializable; /** * 主机身份 更新请求对象 @@ -23,7 +23,7 @@ import java.io.Serializable; @NoArgsConstructor @AllArgsConstructor @Schema(name = "HostIdentityUpdateRequest", description = "主机身份 更新请求对象") -public class HostIdentityUpdateRequest implements Serializable { +public class HostIdentityUpdateRequest implements UpdatePasswordAction { @NotNull @Schema(description = "id") @@ -48,4 +48,7 @@ public class HostIdentityUpdateRequest implements Serializable { @Schema(description = "秘钥id") private Long keyId; + @Schema(description = "是否使用新密码") + private Boolean useNewPassword; + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostKeyUpdateRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostKeyUpdateRequest.java index 9ce99ac5..4c9c9d9a 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostKeyUpdateRequest.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/host/HostKeyUpdateRequest.java @@ -1,5 +1,6 @@ package com.orion.ops.module.asset.entity.request.host; +import com.orion.ops.framework.common.security.UpdatePasswordAction; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -9,7 +10,6 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import java.io.Serializable; /** * 主机秘钥 更新请求对象 @@ -23,7 +23,7 @@ import java.io.Serializable; @NoArgsConstructor @AllArgsConstructor @Schema(name = "HostKeyUpdateRequest", description = "主机秘钥 更新请求对象") -public class HostKeyUpdateRequest implements Serializable { +public class HostKeyUpdateRequest implements UpdatePasswordAction { @NotNull @Schema(description = "id") diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostIdentityVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostIdentityVO.java index 803b918a..3889eb11 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostIdentityVO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostIdentityVO.java @@ -1,10 +1,13 @@ package com.orion.ops.module.asset.entity.vo; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; -import java.util.*; +import java.util.Date; /** * 主机身份 视图响应对象 @@ -31,22 +34,16 @@ public class HostIdentityVO implements Serializable { @Schema(description = "用户名") private String username; - @Schema(description = "用户密码") - private String password; - @Schema(description = "秘钥id") private Long keyId; + @Schema(description = "秘钥名称") + private String keyName; + @Schema(description = "创建时间") private Date createTime; @Schema(description = "修改时间") private Date updateTime; - @Schema(description = "创建人") - private String creator; - - @Schema(description = "修改人") - private String updater; - } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostIdentityService.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostIdentityService.java index a4f8c570..7701f870 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostIdentityService.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/HostIdentityService.java @@ -1,13 +1,11 @@ package com.orion.ops.module.asset.service; import com.orion.lang.define.wrapper.DataGrid; -import com.orion.ops.module.asset.entity.vo.*; -import com.orion.ops.module.asset.entity.request.host.*; -import com.orion.ops.module.asset.entity.export.*; -import com.orion.ops.module.asset.convert.*; +import com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest; +import com.orion.ops.module.asset.entity.vo.HostIdentityVO; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.List; /** @@ -35,15 +33,6 @@ public interface HostIdentityService { */ Integer updateHostIdentityById(HostIdentityUpdateRequest request); - /** - * 更新主机身份 - * - * @param query query - * @param update update - * @return effect - */ - Integer updateHostIdentity(HostIdentityQueryRequest query, HostIdentityUpdateRequest update); - /** * 通过 id 查询主机身份 * @@ -52,29 +41,12 @@ public interface HostIdentityService { */ HostIdentityVO getHostIdentityById(Long id); - /** - * 通过 id 批量查询主机身份 - * - * @param idList idList - * @return rows - */ - List getHostIdentityByIdList(List idList); - /** * 查询主机身份 * - * @param request request * @return rows */ - List getHostIdentityList(HostIdentityQueryRequest request); - - /** - * 查询主机身份数量 - * - * @param request request - * @return count - */ - Long getHostIdentityCount(HostIdentityQueryRequest request); + List getHostIdentityList(); /** * 分页查询主机身份 @@ -92,29 +64,4 @@ public interface HostIdentityService { */ Integer deleteHostIdentityById(Long id); - /** - * 通过 id 批量删除主机身份 - * - * @param idList idList - * @return effect - */ - Integer batchDeleteHostIdentityByIdList(List idList); - - /** - * 删除主机身份 - * - * @param request request - * @return effect - */ - Integer deleteHostIdentity(HostIdentityQueryRequest request); - - /** - * 导出主机身份 - * - * @param request request - * @param response response - * @throws IOException IOException - */ - void exportHostIdentity(HostIdentityQueryRequest request, HttpServletResponse response) throws IOException; - } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostIdentityServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostIdentityServiceImpl.java index 19e933ae..5f98ba9e 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostIdentityServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostIdentityServiceImpl.java @@ -3,28 +3,31 @@ package com.orion.ops.module.asset.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; -import com.orion.lang.utils.collect.Lists; -import com.orion.office.excel.writer.exporting.ExcelExport; -import com.orion.ops.framework.common.constant.ErrorMessage; -import com.orion.ops.framework.common.utils.FileNames; +import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.ErrorMessage; +import com.orion.ops.framework.common.security.PasswordModifier; import com.orion.ops.framework.common.utils.Valid; -import com.orion.ops.module.asset.entity.vo.*; -import com.orion.ops.module.asset.entity.request.host.*; -import com.orion.ops.module.asset.entity.export.*; -import com.orion.ops.module.asset.convert.*; -import com.orion.ops.module.asset.entity.domain.HostIdentityDO; +import com.orion.ops.framework.redis.core.utils.RedisLists; +import com.orion.ops.module.asset.convert.HostIdentityConvert; import com.orion.ops.module.asset.dao.HostIdentityDAO; +import com.orion.ops.module.asset.dao.HostKeyDAO; +import com.orion.ops.module.asset.define.HostCacheKeyDefine; +import com.orion.ops.module.asset.entity.domain.HostIdentityDO; +import com.orion.ops.module.asset.entity.domain.HostKeyDO; +import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO; +import com.orion.ops.module.asset.entity.request.host.HostIdentityCreateRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityQueryRequest; +import com.orion.ops.module.asset.entity.request.host.HostIdentityUpdateRequest; +import com.orion.ops.module.asset.entity.vo.HostIdentityVO; import com.orion.ops.module.asset.service.HostIdentityService; -import com.orion.web.servlet.web.Servlets; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; /** * 主机身份 服务实现类 @@ -40,9 +43,14 @@ public class HostIdentityServiceImpl implements HostIdentityService { @Resource private HostIdentityDAO hostIdentityDAO; + @Resource + private HostKeyDAO hostKeyDAO; + @Override public Long createHostIdentity(HostIdentityCreateRequest request) { log.info("HostIdentityService-createHostIdentity request: {}", JSON.toJSONString(request)); + // 检查秘钥是否存在 + this.checkKeyIdPresent(request.getKeyId()); // 转换 HostIdentityDO record = HostIdentityConvert.MAPPER.to(request); // 查询数据是否冲突 @@ -50,7 +58,11 @@ public class HostIdentityServiceImpl implements HostIdentityService { // 插入 int effect = hostIdentityDAO.insert(record); log.info("HostIdentityService-createHostIdentity effect: {}", effect); - return record.getId(); + Long id = record.getId(); + // 设置缓存 + RedisLists.pushJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record)); + RedisLists.setExpire(HostCacheKeyDefine.HOST_IDENTITY); + return id; } @Override @@ -60,29 +72,26 @@ public class HostIdentityServiceImpl implements HostIdentityService { Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING); HostIdentityDO record = hostIdentityDAO.selectById(id); Valid.notNull(record, ErrorMessage.DATA_ABSENT); + // 检查秘钥是否存在 + this.checkKeyIdPresent(request.getKeyId()); // 转换 HostIdentityDO updateRecord = HostIdentityConvert.MAPPER.to(request); // 查询数据是否冲突 this.checkHostIdentityPresent(updateRecord); + // 设置密码 + String newPassword = PasswordModifier.getEncryptNewPassword(request); + updateRecord.setPassword(newPassword); // 更新 int effect = hostIdentityDAO.updateById(updateRecord); + // 设置缓存 + if (!record.getName().equals(updateRecord.getName())) { + RedisLists.removeJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record)); + RedisLists.pushJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(updateRecord)); + } log.info("HostIdentityService-updateHostIdentityById effect: {}", effect); return effect; } - @Override - public Integer updateHostIdentity(HostIdentityQueryRequest query, HostIdentityUpdateRequest update) { - log.info("HostIdentityService.updateHostIdentity query: {}, update: {}", JSON.toJSONString(query), JSON.toJSONString(update)); - // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(query); - // 转换 - HostIdentityDO updateRecord = HostIdentityConvert.MAPPER.to(update); - // 更新 - int effect = hostIdentityDAO.update(updateRecord, wrapper); - log.info("HostIdentityService.updateHostIdentity effect: {}", effect); - return effect; - } - @Override public HostIdentityVO getHostIdentityById(Long id) { // 查询 @@ -93,30 +102,27 @@ public class HostIdentityServiceImpl implements HostIdentityService { } @Override - public List getHostIdentityByIdList(List idList) { - // 查询 - List records = hostIdentityDAO.selectBatchIds(idList); - if (records.isEmpty()) { - return Lists.empty(); + public List getHostIdentityList() { + // 查询缓存 + List list = RedisLists.rangeJson(HostCacheKeyDefine.HOST_IDENTITY); + if (list.isEmpty()) { + // 查询数据库 + list = hostIdentityDAO.of().list(HostIdentityConvert.MAPPER::toCache); + // 添加默认值 防止穿透 + if (list.isEmpty()) { + list.add(HostIdentityCacheDTO.builder() + .id(Const.NONE_ID) + .build()); + } + // 设置缓存 + RedisLists.pushAllJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), list); + RedisLists.setExpire(HostCacheKeyDefine.HOST_IDENTITY); } - // 转换 - return HostIdentityConvert.MAPPER.to(records); - } - - @Override - public List getHostIdentityList(HostIdentityQueryRequest request) { - // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); - // 查询 - return hostIdentityDAO.of(wrapper).list(HostIdentityConvert.MAPPER::to); - } - - @Override - public Long getHostIdentityCount(HostIdentityQueryRequest request) { - // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); - // 查询 - return hostIdentityDAO.selectCount(wrapper); + // 删除默认值 + return list.stream() + .filter(s -> !s.getId().equals(Const.NONE_ID)) + .map(HostIdentityConvert.MAPPER::to) + .collect(Collectors.toList()); } @Override @@ -124,58 +130,51 @@ public class HostIdentityServiceImpl implements HostIdentityService { // 条件 LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); // 查询 - return hostIdentityDAO.of(wrapper) + DataGrid dataGrid = hostIdentityDAO.of(wrapper) .page(request) .dataGrid(HostIdentityConvert.MAPPER::to); + if (dataGrid.isEmpty()) { + return dataGrid; + } + // 设置秘钥名称 + List keyIdList = dataGrid.stream() + .map(HostIdentityVO::getKeyId) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + if (!keyIdList.isEmpty()) { + // 查询秘钥名称 + Map keyNameMap = hostKeyDAO.selectBatchIds(keyIdList) + .stream() + .collect(Collectors.toMap(HostKeyDO::getId, HostKeyDO::getName)); + dataGrid.forEach(s -> { + if (s.getKeyId() == null) { + return; + } + s.setKeyName(keyNameMap.get(s.getKeyId())); + }); + } + return dataGrid; } @Override public Integer deleteHostIdentityById(Long id) { log.info("HostIdentityService-deleteHostIdentityById id: {}", id); + // 检查数据是否存在 + HostIdentityDO record = hostIdentityDAO.selectById(id); + Valid.notNull(record, ErrorMessage.DATA_ABSENT); + // 删除数据库 int effect = hostIdentityDAO.deleteById(id); + // TODO config + + // 删除缓存 + RedisLists.removeJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), HostIdentityConvert.MAPPER.toCache(record)); log.info("HostIdentityService-deleteHostIdentityById effect: {}", effect); return effect; } - @Override - public Integer batchDeleteHostIdentityByIdList(List idList) { - log.info("HostIdentityService-batchDeleteHostIdentityByIdList idList: {}", idList); - int effect = hostIdentityDAO.deleteBatchIds(idList); - log.info("HostIdentityService-batchDeleteHostIdentityByIdList effect: {}", effect); - return effect; - } - - @Override - public Integer deleteHostIdentity(HostIdentityQueryRequest request) { - log.info("HostIdentityService.deleteHostIdentity request: {}", JSON.toJSONString(request)); - // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); - // 删除 - int effect = hostIdentityDAO.delete(wrapper); - log.info("HostIdentityService.deleteHostIdentity effect: {}", effect); - return effect; - } - - @Override - public void exportHostIdentity(HostIdentityQueryRequest request, HttpServletResponse response) throws IOException { - log.info("HostIdentityService.exportHostIdentity request: {}", JSON.toJSONString(request)); - // 条件 - LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); - // 查询 - List rows = hostIdentityDAO.of(wrapper).list(HostIdentityConvert.MAPPER::toExport); - log.info("HostIdentityService.exportHostIdentity size: {}", rows.size()); - // 导出 - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ExcelExport.create(HostIdentityExport.class) - .addRows(rows) - .write(out) - .close(); - // 传输 - Servlets.transfer(response, out.toByteArray(), FileNames.exportName(HostIdentityExport.TITLE)); - } - /** - * 检测对象是否存在 + * 检查对象是否存在 * * @param domain domain */ @@ -185,15 +184,24 @@ public class HostIdentityServiceImpl implements HostIdentityService { // 更新时忽略当前记录 .ne(HostIdentityDO::getId, domain.getId()) // 用其他字段做重复校验 - .eq(HostIdentityDO::getName, domain.getName()) - .eq(HostIdentityDO::getUsername, domain.getUsername()) - .eq(HostIdentityDO::getPassword, domain.getPassword()) - .eq(HostIdentityDO::getKeyId, domain.getKeyId()); + .eq(HostIdentityDO::getName, domain.getName()); // 检查是否存在 boolean present = hostIdentityDAO.of(wrapper).present(); Valid.isFalse(present, ErrorMessage.DATA_PRESENT); } + /** + * 检查秘钥是否存在 + * + * @param keyId keyId + */ + private void checkKeyIdPresent(Long keyId) { + if (keyId == null) { + return; + } + Valid.notNull(hostKeyDAO.selectById(keyId), ErrorMessage.KEY_ABSENT); + } + /** * 构建查询 wrapper * @@ -203,9 +211,8 @@ public class HostIdentityServiceImpl implements HostIdentityService { private LambdaQueryWrapper buildQueryWrapper(HostIdentityQueryRequest request) { return hostIdentityDAO.wrapper() .eq(HostIdentityDO::getId, request.getId()) - .eq(HostIdentityDO::getName, request.getName()) - .eq(HostIdentityDO::getUsername, request.getUsername()) - .eq(HostIdentityDO::getPassword, request.getPassword()) + .like(HostIdentityDO::getName, request.getName()) + .like(HostIdentityDO::getUsername, request.getUsername()) .eq(HostIdentityDO::getKeyId, request.getKeyId()); } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostKeyServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostKeyServiceImpl.java index cba4b17c..292bc537 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostKeyServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/HostKeyServiceImpl.java @@ -3,14 +3,15 @@ package com.orion.ops.module.asset.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; -import com.orion.lang.utils.Booleans; import com.orion.lang.utils.Strings; import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.ErrorMessage; +import com.orion.ops.framework.common.security.PasswordModifier; import com.orion.ops.framework.common.utils.CryptoUtils; import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.redis.core.utils.RedisLists; import com.orion.ops.module.asset.convert.HostKeyConvert; +import com.orion.ops.module.asset.dao.HostIdentityDAO; import com.orion.ops.module.asset.dao.HostKeyDAO; import com.orion.ops.module.asset.define.HostCacheKeyDefine; import com.orion.ops.module.asset.entity.domain.HostKeyDO; @@ -22,6 +23,7 @@ import com.orion.ops.module.asset.entity.vo.HostKeyVO; import com.orion.ops.module.asset.service.HostKeyService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -41,6 +43,9 @@ public class HostKeyServiceImpl implements HostKeyService { @Resource private HostKeyDAO hostKeyDAO; + @Resource + private HostIdentityDAO hostIdentityDAO; + @Override public Long createHostKey(HostKeyCreateRequest request) { log.info("HostKeyService-createHostKey request: {}", JSON.toJSONString(request)); @@ -73,25 +78,17 @@ public class HostKeyServiceImpl implements HostKeyService { HostKeyDO updateRecord = HostKeyConvert.MAPPER.to(request); // 查询数据是否冲突 this.checkHostKeyPresent(updateRecord); - if (Booleans.isTrue(request.getUseNewPassword())) { - // 使用新密码 - String password = updateRecord.getPassword(); - if (Strings.isBlank(password)) { - updateRecord.setPassword(Const.EMPTY); - } else { - updateRecord.setPassword(CryptoUtils.encryptAsString(password)); - } - } else { - updateRecord.setPassword(null); - } + // 设置密码 + String newPassword = PasswordModifier.getEncryptNewPassword(request); + updateRecord.setPassword(newPassword); // 更新 int effect = hostKeyDAO.updateById(updateRecord); - log.info("HostKeyService-updateHostKeyById effect: {}", effect); // 设置缓存 if (!record.getName().equals(updateRecord.getName())) { RedisLists.removeJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(record)); RedisLists.pushJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(updateRecord)); } + log.info("HostKeyService-updateHostKeyById effect: {}", effect); return effect; } @@ -130,6 +127,7 @@ public class HostKeyServiceImpl implements HostKeyService { } // 设置缓存 RedisLists.pushAllJson(HostCacheKeyDefine.HOST_KEY.getKey(), list); + RedisLists.setExpire(HostCacheKeyDefine.HOST_KEY); } // 删除默认值 return list.stream() @@ -151,15 +149,26 @@ public class HostKeyServiceImpl implements HostKeyService { } @Override + @Transactional(rollbackFor = Exception.class) public Integer deleteHostKeyById(Long id) { log.info("HostKeyService-deleteHostKeyById id: {}", id); + // 检查数据是否存在 + HostKeyDO record = hostKeyDAO.selectById(id); + Valid.notNull(record, ErrorMessage.DATA_ABSENT); + // 删除数据库 int effect = hostKeyDAO.deleteById(id); + // 删除关联 + hostIdentityDAO.setKeyWithNull(id); + // TODO config + + // 删除缓存 + RedisLists.removeJson(HostCacheKeyDefine.HOST_KEY.getKey(), HostKeyConvert.MAPPER.toCache(record)); log.info("HostKeyService-deleteHostKeyById effect: {}", effect); return effect; } /** - * 检测对象是否存在 + * 检查对象是否存在 * * @param domain domain */ diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/HostIdentityMapper.xml b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/HostIdentityMapper.xml index 4074854b..8e446016 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/HostIdentityMapper.xml +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/HostIdentityMapper.xml @@ -21,4 +21,10 @@ id, name, username, password, key_id, create_time, update_time, creator, updater, deleted + + UPDATE host_identity + SET key_id = NULL + WHERE key_id = #{keyId} + + diff --git a/orion-ops-ui/src/api/asset/host-identity.ts b/orion-ops-ui/src/api/asset/host-identity.ts index a2e13114..1494ad97 100644 --- a/orion-ops-ui/src/api/asset/host-identity.ts +++ b/orion-ops-ui/src/api/asset/host-identity.ts @@ -17,6 +17,7 @@ export interface HostIdentityCreateRequest { */ export interface HostIdentityUpdateRequest extends HostIdentityCreateRequest { id: number; + useNewPassword?: boolean; } /** @@ -66,23 +67,11 @@ export function getHostIdentity(id: number) { return axios.get('/asset/host-identity/get', { params: { id } }); } -/** - * 通过 id 批量查询主机身份 - */ -export function getHostIdentityList(idList: Array) { - return axios.get('/asset/host-identity/list', { - params: { idList }, - paramsSerializer: params => { - return qs.stringify(params, { arrayFormat: 'comma' }); - } - }); -} - /** * 查询主机身份 */ -export function getHostIdentityListAll(request: HostIdentityQueryRequest) { - return axios.post>('/asset/host-identity/list-all', request); +export function getHostIdentityList() { + return axios.post>('/asset/host-identity/list'); } /** @@ -99,14 +88,3 @@ export function deleteHostIdentity(id: number) { return axios.delete('/asset/host-identity/delete', { params: { id } }); } -/** - * 通过 id 批量删除主机身份 - */ -export function batchDeleteHostIdentity(idList: Array) { - return axios.delete('/asset/host-identity/delete-batch', { - params: { idList }, - paramsSerializer: params => { - return qs.stringify(params, { arrayFormat: 'comma' }); - } - }); -} diff --git a/orion-ops-ui/src/api/asset/host-key.ts b/orion-ops-ui/src/api/asset/host-key.ts index 81e76318..18273d97 100644 --- a/orion-ops-ui/src/api/asset/host-key.ts +++ b/orion-ops-ui/src/api/asset/host-key.ts @@ -9,7 +9,6 @@ export interface HostKeyCreateRequest { publicKey?: string; privateKey?: string; password?: string; - useNewPassword?: boolean; } /** @@ -17,6 +16,7 @@ export interface HostKeyCreateRequest { */ export interface HostKeyUpdateRequest extends HostKeyCreateRequest { id: number; + useNewPassword?: boolean; } /** @@ -66,8 +66,8 @@ export function getHostKey(id: number) { /** * 查询主机秘钥 */ -export function getHostKeyListAll() { - return axios.post>('/asset/host-key/list-all'); +export function getHostKeyList() { + return axios.post>('/asset/host-key/list'); } /** diff --git a/orion-ops-ui/src/api/meta/tag.ts b/orion-ops-ui/src/api/meta/tag.ts index b0c80d39..4fa5623e 100644 --- a/orion-ops-ui/src/api/meta/tag.ts +++ b/orion-ops-ui/src/api/meta/tag.ts @@ -13,7 +13,7 @@ export interface TagCreateRequest { /** * tag 响应对象 */ -export interface TagResponse { +export interface TagQueryResponse { id: number; name: string; } @@ -29,5 +29,5 @@ export function createTag(request: TagCreateRequest) { * 查询标签 */ export function getTagList(type: TagType) { - return axios.get('/infra/tag/list', { params: { type } }); + return axios.get('/infra/tag/list', { params: { type } }); } diff --git a/orion-ops-ui/src/assets/style/global.less b/orion-ops-ui/src/assets/style/global.less index f7a57aa7..782814cf 100644 --- a/orion-ops-ui/src/assets/style/global.less +++ b/orion-ops-ui/src/assets/style/global.less @@ -115,6 +115,10 @@ body { } } +.span-blue { + color: rgb(var(--arcoblue-6)); +} + #app { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; diff --git a/orion-ops-ui/src/components/asset/host-key/host-key-selector.vue b/orion-ops-ui/src/components/asset/host-key/host-key-selector.vue new file mode 100644 index 00000000..683949b9 --- /dev/null +++ b/orion-ops-ui/src/components/asset/host-key/host-key-selector.vue @@ -0,0 +1,52 @@ + + + + + + + diff --git a/orion-ops-ui/src/store/modules/cache/index.ts b/orion-ops-ui/src/store/modules/cache/index.ts index 2e4ec18e..c020dcab 100644 --- a/orion-ops-ui/src/store/modules/cache/index.ts +++ b/orion-ops-ui/src/store/modules/cache/index.ts @@ -1,13 +1,14 @@ import { defineStore } from 'pinia'; import { CacheState } from './types'; -export type CacheType = 'menus' | 'roles' | 'tags' +export type CacheType = 'menus' | 'roles' | 'tags' | 'hostKeys' const useCacheStore = defineStore('cache', { state: (): CacheState => ({ menus: [], roles: [], - tags: [] + tags: [], + hostKeys: [], }), getters: {}, diff --git a/orion-ops-ui/src/store/modules/cache/types.ts b/orion-ops-ui/src/store/modules/cache/types.ts index 9cb4e509..b3b5b85e 100644 --- a/orion-ops-ui/src/store/modules/cache/types.ts +++ b/orion-ops-ui/src/store/modules/cache/types.ts @@ -1,9 +1,13 @@ import { MenuQueryResponse } from '@/api/system/menu'; import { RoleQueryResponse } from '@/api/user/role'; -import { TagResponse } from '@/api/meta/tag'; +import { TagQueryResponse } from '@/api/meta/tag'; +import { HostKeyQueryResponse } from '@/api/asset/host-key'; export interface CacheState { menus: MenuQueryResponse[]; roles: RoleQueryResponse[]; - tags: TagResponse[]; + tags: TagQueryResponse[]; + hostKeys: HostKeyQueryResponse[]; + + [key: string]: unknown; } diff --git a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-drawer.vue b/orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-drawer.vue deleted file mode 100644 index 93ae0ae3..00000000 --- a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-drawer.vue +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - diff --git a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-modal.vue b/orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-modal.vue index 41727308..bc70f35a 100644 --- a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-modal.vue +++ b/orion-ops-ui/src/views/asset/host-identity/components/host-identity-form-modal.vue @@ -29,12 +29,23 @@ - - + + + - - + + @@ -54,9 +65,7 @@ import formRules from '../types/form.rules'; import { createHostIdentity, updateHostIdentity } from '@/api/asset/host-identity'; import { Message } from '@arco-design/web-vue'; - import {} from '../types/enum.types'; - import {} from '../types/const'; - import { toOptions } from '@/utils/enum'; + import HostKeySelector from '@/components/asset/host-key/host-key-selector.vue'; const { visible, setVisible } = useVisible(); const { loading, setLoading } = useLoading(); @@ -70,6 +79,7 @@ name: undefined, username: undefined, password: undefined, + useNewPassword: false, keyId: undefined, }; }; @@ -147,5 +157,11 @@ diff --git a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-table.vue b/orion-ops-ui/src/views/asset/host-identity/components/host-identity-table.vue index bdb4e736..4f73504e 100644 --- a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-table.vue +++ b/orion-ops-ui/src/views/asset/host-identity/components/host-identity-table.vue @@ -7,23 +7,19 @@ @reset="fetchTableData"> - + - + - + - - - - - - - + + + @@ -32,7 +28,7 @@ - - - - 删除 - - - @@ -71,14 +52,16 @@ label-align="left" :loading="loading" :columns="columns" - v-model:selectedKeys="selectedKeys" - :row-selection="rowSelection" :data="tableRenderData" :pagination="pagination" @page-change="(page) => fetchTableData(page, pagination.pageSize)" @page-size-change="(size) => fetchTableData(pagination.current, size)" :bordered="false"> + +