Skip to content

Commit

Permalink
feature: 提供文件源管理、凭据管理相关ESB API TencentBlueKing#92
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan authored and hLinx committed Sep 16, 2021
1 parent f127c35 commit dbd2b22
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public EsbResp<EsbFileSourceSimpleInfoV3DTO> createFileSource(EsbCreateOrUpdateF

@Override
public EsbResp<EsbFileSourceSimpleInfoV3DTO> updateFileSource(EsbCreateOrUpdateFileSourceV3Req req) {
checkUpdateParam(req);
Long appId = req.getAppId();
String username = req.getUserName();
Integer id = req.getId();
AuthResult authResult = checkManageFileSourcePermission(username, appId, id);
if (!authResult.isPass()) {
return authService.buildEsbAuthFailResp(authResult.getRequiredActionResources());
}
checkUpdateParam(req);
FileSourceDTO fileSourceDTO = buildFileSourceDTO(req.getUserName(), appId, req);
Integer fileSourceId = fileSourceService.updateFileSourceById(appId, fileSourceDTO);
return EsbResp.buildSuccessResp(new EsbFileSourceSimpleInfoV3DTO(fileSourceId));
Expand Down Expand Up @@ -98,9 +98,17 @@ private void checkUpdateParam(EsbCreateOrUpdateFileSourceV3Req req) {
checkAppId(req);
Long appId = req.getAppId();
Integer id = req.getId();
String code = req.getCode();
if (id == null && StringUtils.isBlank(code)) {
throw new InvalidParamException("id/code", "id and code cannot be null/blank simultaneously");
}
if (id == null) {
throw new InvalidParamException("id", "code cannot be null");
id = fileSourceService.getFileSourceIdByCode(appId, code);
if (id == null) {
throw new InvalidParamException("code", String.format("cannot find fileSource by code [%s]", code));
}
}
req.setId(id);
if (!fileSourceService.existsFileSource(appId, id)) {
throw new InvalidParamException(
"bk_biz_id/id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ List<FileSourceDTO> listWorkTableFileSource(DSLContext dslContext, List<Long> ap
boolean existsCode(String code);

boolean existsFileSource(Long appId, Integer id);

Integer getFileSourceIdByCode(Long appId, String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,29 @@ public boolean existsFileSource(Long appId, Integer id) {
return query.fetch().size() > 0;
}

@Override
public Integer getFileSourceIdByCode(Long appId, String code) {
List<Condition> conditions = new ArrayList<>();
if (appId != null) {
conditions.add(defaultTable.APP_ID.eq(appId));
}
if (code != null) {
conditions.add(defaultTable.CODE.eq(code));
}
val query = defaultContext.select(
defaultTable.ID
).from(defaultTable)
.where(conditions);
val result = query.fetch();
if (result.size() > 0) {
if (result.size() > 1) {
log.warn("{} records found when get id by code, use first one", result.size());
}
return result.get(0).get(defaultTable.ID);
}
return null;
}

private List<FileSourceDTO> listFileSourceByConditions(DSLContext dslContext, Collection<Condition> conditions,
Integer start, Integer pageSize) {
val query = dslContext.select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ List<FileSourceDTO> listWorkTableFileSource(List<Long> appIdList, List<Integer>
boolean existsCode(String code);

boolean existsFileSource(Long appId, Integer id);

Integer getFileSourceIdByCode(Long appId, String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,9 @@ public boolean existsCode(String code) {
public boolean existsFileSource(Long appId, Integer id) {
return fileSourceDAO.existsFileSource(appId, id);
}

@Override
public Integer getFileSourceIdByCode(Long appId, String code) {
return fileSourceDAO.getFileSourceIdByCode(appId, code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,20 @@ private void checkUpdateParam(EsbCreateOrUpdateCredentialV3Req req) {

private EsbResp<EsbCredentialSimpleInfoV3DTO> saveCredential(EsbCreateOrUpdateCredentialV3Req req) {
CredentialCreateUpdateReq createUpdateReq = convertToCreateUpdateReq(req);
InnerServiceResponse<ServiceBasicCredentialDTO> resp =
credentialService.createCredential(
InnerServiceResponse<ServiceBasicCredentialDTO> resp;
if (req.getId() == null) {
resp = credentialService.createCredential(
req.getUserName(),
req.getAppId(),
createUpdateReq
);
} else {
resp = credentialService.updateCredential(
req.getUserName(),
req.getAppId(),
createUpdateReq
);
}
if (resp.getAuthResult() != null) {
return authService.buildEsbAuthFailResp(
resp.getAuthResult().getRequiredActionResources()
Expand Down

0 comments on commit dbd2b22

Please sign in to comment.