diff --git a/docs/apidoc/bk-api-gateway/v3/zh/get_credential_detail.md b/docs/apidoc/bk-api-gateway/v3/zh/get_credential_detail.md new file mode 100644 index 0000000000..249aa62f9c --- /dev/null +++ b/docs/apidoc/bk-api-gateway/v3/zh/get_credential_detail.md @@ -0,0 +1,77 @@ +### 功能描述 + +查询凭证详情 + +### 请求参数 + +{{ bkapi_authorization_description }} + +#### Header参数 + +| 字段 | 类型 | 必选 | 描述 | +|-----------|------------|--------|------------| +| X-Bkapi-Authorization | string | 是 | 认证信息。详情参考[调用网关 API](https://github.com/TencentBlueKing/BKDocs/blob/master/ZH/7.0/APIGateway/apigateway/use-api/use-apigw-api.md) | +| Accept | string | 是 | 固定值。application/json| +| Content-Type | string | 是 | 固定值。application/json| + +#### Query参数 + +| 字段 | 类型 | 必选 | 描述 | +|------------------------|------------|--------|------------| +| bk_scope_type | string | 是 | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | +| bk_scope_id | string | 是 | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | +| bk_biz_id | long | 是 | *已弃用*。业务ID。此字段已被弃用并由字段bk_scope_type+bk_scope_id替换 | +| id | String | 是 | 凭证ID | + +### 请求参数示例 + +- GET +```json +/api/v3/get_credential_detail?bk_scope_type=biz&bk_scope_id=2&id=xxx +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": { + "bk_scope_type": "biz", + "bk_scope_id": "2", + "id": "xxx", + "name": "xxx", + "type": "xxx", + "description": "xxx", + "creator": "admin", + "create_time": 1712049204719, + "last_modify_user": "admin", + "last_modify_time": 1712049204719 + } +} +``` + +### 返回结果参数说明 + +| 字段 | 类型 | 描述 | +|-----------|-----------|-----------| +| result | bool | 请求成功与否。true:请求成功;false请求失败 | +| code | int | 错误编码。 0表示success,>0表示失败错误 | +| message | string | 请求失败返回的错误信息| +| data | object | 请求返回的数据| +| permission | object | 权限信息| + +##### data +| 字段 | 类型 | 描述 | +| ---------------- | ------ | ------------------------------------------------------------ | +| bk_scope_type | string | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | +| bk_scope_id | string | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | +| id | string | 凭证ID | +| name | string | 凭证名称 | +| type | string | 类型。可选值:APP_ID_SECRET_KEY,PASSWORD,USERNAME_PASSWORD,SECRET_KEY| +| description | string | 描述 | +| creator | string | 作业创建人账号 | +| create_time | long | 创建时间,Unix时间戳(ms) | +| last_modify_user | string | 作业修改人账号 | +| last_modify_time | long | 最后修改时间,Unix时间戳(ms) | diff --git a/docs/apidoc/bk-api-gateway/v3/zh/get_file_source_detail.md b/docs/apidoc/bk-api-gateway/v3/zh/get_file_source_detail.md new file mode 100644 index 0000000000..bedc7baffe --- /dev/null +++ b/docs/apidoc/bk-api-gateway/v3/zh/get_file_source_detail.md @@ -0,0 +1,85 @@ +### 功能描述 + +查询文件源详情 + +### 请求参数 + +{{ bkapi_authorization_description }} + +#### Header参数 + +| 字段 | 类型 | 必选 | 描述 | +|-----------|------------|--------|------------| +| X-Bkapi-Authorization | string | 是 | 认证信息。详情参考[调用网关 API](https://github.com/TencentBlueKing/BKDocs/blob/master/ZH/7.0/APIGateway/apigateway/use-api/use-apigw-api.md) | +| Accept | string | 是 | 固定值。application/json| +| Content-Type | string | 是 | 固定值。application/json| + +#### Query参数 + +| 字段 | 类型 | 必选 | 描述 | +|------------------------|------------|--------|------------| +| bk_scope_type | string | 是 | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | +| bk_scope_id | string | 是 | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | +| bk_biz_id | long | 是 | *已弃用*。业务ID。此字段已被弃用并由字段bk_scope_type+bk_scope_id替换 | +| code | String | 是 | 文件源code | + +### 请求参数示例 + +- GET +```json +/api/v3/get_file_source_detail?bk_scope_type=biz&bk_scope_id=2&code=bkrepo-1 +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "", + "data": { + "bk_scope_type": "biz", + "bk_scope_id": "2", + "id": 10001, + "code": "bkrepo-1", + "alias": "xxx", + "status": 0, + "file_source_type_code": "BLUEKING_ARTIFACTORY", + "is_public": false, + "credential_id": "xxx", + "enable": true, + "creator": "admin", + "create_time": 1712050614742, + "last_modify_user": "admin", + "last_modify_time": 1712050614742 + } +} +``` + +### 返回结果参数说明 + +| 字段 | 类型 | 描述 | +|-----------|-----------|-----------| +| result | bool | 请求成功与否。true:请求成功;false请求失败 | +| code | int | 错误编码。 0表示success,>0表示失败错误 | +| message | string | 请求失败返回的错误信息| +| data | object | 请求返回的数据| +| permission | object | 权限信息| + +##### data +| 字段 | 类型 | 描述 | +| ---------------- | ------ | ------------------------------------------------------------ | +| bk_scope_type | string | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | +| bk_scope_id | string | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | +| id | int | 文件源ID | +| code | string | 文件源code | +| alias | string | 文件源别名 | +| status | int | 状态 | +| file_source_type_code | string | 文件源类型code。可选值:BLUEKING_ARTIFACTORY | +| is_public | bool | 是否为公用文件源 | +| credential_id | string | 凭证ID | +| enable | bool | 是否启用 | +| creator | string | 作业创建人账号 | +| create_time | long | 创建时间,Unix时间戳(ms) | +| last_modify_user | string | 作业修改人账号 | +| last_modify_time | long | 最后修改时间,Unix时间戳(ms) | diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_credential.md b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_credential.md index 61a2e8d86f..b24aa2010b 100644 --- a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_credential.md +++ b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_credential.md @@ -1,6 +1,6 @@ ### 功能描述 -新建凭据。 +新建凭证。 ### 请求参数 @@ -12,13 +12,13 @@ |----------------------------|------------|--------|------------| | bk_scope_type | string | 是 | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | | bk_scope_id | string | 是 | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | -| name | string | 是 | 凭据名称 | -| type | string | 是 | 凭据类型,取值可为ACCESS_KEY_SECRET_KEY,PASSWORD,USERNAME_PASSWORD,SECRET_KEY | -| description | string | 否 | 凭据描述 | -| credential_access_key | string | 否 | 凭据类型为ACCESS_KEY_SECRET_KEY时填写 | -| credential_secret_key | string | 否 | 凭据类型为ACCESS_KEY_SECRET_KEY/SECRET_KEY时填写 | -| credential_username | string | 否 | 凭据类型为USERNAME_PASSWORD时填写 | -| credential_password | string | 否 | 凭据类型为USERNAME_PASSWORD/PASSWORD时填写 | +| name | string | 是 | 凭证名称 | +| type | string | 是 | 凭证类型,取值可为ACCESS_KEY_SECRET_KEY,PASSWORD,USERNAME_PASSWORD,SECRET_KEY | +| description | string | 否 | 凭证描述 | +| credential_access_key | string | 否 | 凭证类型为ACCESS_KEY_SECRET_KEY时填写 | +| credential_secret_key | string | 否 | 凭证类型为ACCESS_KEY_SECRET_KEY/SECRET_KEY时填写 | +| credential_username | string | 否 | 凭证类型为USERNAME_PASSWORD时填写 | +| credential_password | string | 否 | 凭证类型为USERNAME_PASSWORD/PASSWORD时填写 | ### 请求参数示例 @@ -67,4 +67,4 @@ | 字段 | 类型 |字段是否一定存在 | 描述 | |-----------|-------|---------------|---------| -| id | string |是 | 凭据ID | +| id | string |是 | 凭证ID | diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_file_source.md b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_file_source.md index 7e9da62c9f..f2a7d0f1cc 100644 --- a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_file_source.md +++ b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/create_file_source.md @@ -25,7 +25,7 @@ | alias | string | 是 | 文件源别名 | | type | string | 是 | 文件源类型,当前仅支持蓝鲸制品库,BLUEKING_ARTIFACTORY | | access_params | object | 是 | 文件源接入参数,根据type传入不同的对象,见后续说明 | -| credential_id | string | 否 | 文件源使用的凭据Id | +| credential_id | string | 否 | 文件源使用的凭证Id | | file_prefix | string | 否 | Job对从该文件源分发的文件加上的前缀,不传默认不加前缀 | ### access_params diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_credential.md b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_credential.md index 2753b91447..12e27ac57a 100644 --- a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_credential.md +++ b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_credential.md @@ -1,6 +1,6 @@ ### 功能描述 -更新凭据。 +更新凭证。 ### 请求参数 @@ -12,14 +12,14 @@ |----------------------------|------------|--------|------------| | bk_scope_type | string | 是 | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | | bk_scope_id | string | 是 | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | -| id | string | 是 | 凭据 ID | -| name | string | 否 | 凭据名称 | -| type | string | 否 | 凭据类型,取值可为ACCESS_KEY_SECRET_KEY,PASSWORD,USERNAME_PASSWORD,SECRET_KEY | -| description | string | 否 | 凭据描述 | -| credential_access_key | string | 否 | 凭据类型为ACCESS_KEY_SECRET_KEY时填写 | -| credential_secret_key | string | 否 | 凭据类型为ACCESS_KEY_SECRET_KEY/SECRET_KEY时填写 | -| credential_username | string | 否 | 凭据类型为USERNAME_PASSWORD时填写 | -| credential_password | string | 否 | 凭据类型为USERNAME_PASSWORD/PASSWORD时填写 | +| id | string | 是 | 凭证 ID | +| name | string | 否 | 凭证名称 | +| type | string | 否 | 凭证类型,取值可为ACCESS_KEY_SECRET_KEY,PASSWORD,USERNAME_PASSWORD,SECRET_KEY | +| description | string | 否 | 凭证描述 | +| credential_access_key | string | 否 | 凭证类型为ACCESS_KEY_SECRET_KEY时填写 | +| credential_secret_key | string | 否 | 凭证类型为ACCESS_KEY_SECRET_KEY/SECRET_KEY时填写 | +| credential_username | string | 否 | 凭证类型为USERNAME_PASSWORD时填写 | +| credential_password | string | 否 | 凭证类型为USERNAME_PASSWORD/PASSWORD时填写 | ### 请求参数示例 @@ -69,4 +69,4 @@ | 字段 | 类型 |字段是否一定存在 | 描述 | |-----------|-------|---------------|---------| -| id | string |是 | 凭据ID | +| id | string |是 | 凭证ID | diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_file_source.md b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_file_source.md index e65e5ee99d..43e2c0c6da 100644 --- a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_file_source.md +++ b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_file_source.md @@ -16,7 +16,7 @@ | alias | string | 否 | 文件源别名 | | type | string | 否 | 文件源类型,当前仅支持蓝鲸制品库,BLUEKING_ARTIFACTORY | | access_params | object | 否 | 文件源接入参数,根据type传入不同的对象,见后续说明 | -| credential_id | string | 否 | 文件源使用的凭据Id | +| credential_id | string | 否 | 文件源使用的凭证Id | | file_prefix | string | 否 | Job对从该文件源分发的文件加上的前缀,不传默认不加前缀 | ### access_params diff --git a/docs/apidoc/esb/jobv3-confapis/job.yaml b/docs/apidoc/esb/jobv3-confapis/job.yaml index a7822d6125..d877135e4f 100644 --- a/docs/apidoc/esb/jobv3-confapis/job.yaml +++ b/docs/apidoc/esb/jobv3-confapis/job.yaml @@ -271,7 +271,7 @@ - path: /v2/jobv3/create_credential/ name: create_credential - label: 新建凭据 + label: 新建凭证 label_en: Create credential suggest_method: POST api_type: operate @@ -282,7 +282,7 @@ - path: /v2/jobv3/update_credential/ name: update_credential - label: 更新凭据 + label: 更新凭证 label_en: Update credential suggest_method: POST api_type: operate diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java index f80b0bae6a..e6518da92f 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbFastTransferFileV3ResourceImpl.java @@ -251,7 +251,7 @@ private StepInstanceDTO buildFastFileStepInstance(String username, stepInstance.setExecuteType(StepExecuteTypeEnum.SEND_FILE); stepInstance.setFileTargetPath(request.getTargetPath()); stepInstance.setFileTargetName(request.getTargetName()); - stepInstance.setFileSourceList(convertFileSource(request.getFileSources())); + stepInstance.setFileSourceList(convertFileSource(request.getAppId(), request.getFileSources())); stepInstance.setAppId(request.getAppId()); stepInstance.setTargetExecuteObjects(convertToServersDTO(request.getTargetServer())); stepInstance.setOperator(username); @@ -277,7 +277,7 @@ private StepInstanceDTO buildFastFileStepInstance(String username, return stepInstance; } - private List convertFileSource(List fileSources) throws ServiceException { + private List convertFileSource(Long appId, List fileSources) throws ServiceException { if (fileSources == null) { return null; } @@ -318,7 +318,7 @@ private List convertFileSource(List fileSourc fileSourceDTO.setFileSourceId(fileSource.getFileSourceId()); } else if (StringUtils.isNotBlank(fileSourceCode)) { try { - InternalResponse resp = fileSourceResource.getFileSourceIdByCode(fileSourceCode); + InternalResponse resp = fileSourceResource.getFileSourceIdByCode(appId, fileSourceCode); if (resp != null && resp.isSuccess()) { if (resp.getData() != null) { fileSourceDTO.setFileSourceId(resp.getData()); diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3Resource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3Resource.java index a2ebf29858..7e27cd2059 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3Resource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3Resource.java @@ -28,12 +28,16 @@ import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.file_gateway.model.req.esb.v3.EsbCreateOrUpdateFileSourceV3Req; +import com.tencent.bk.job.file_gateway.model.req.esb.v3.EsbGetFileSourceDetailV3Req; import com.tencent.bk.job.file_gateway.model.resp.esb.v3.EsbFileSourceSimpleInfoV3DTO; +import com.tencent.bk.job.file_gateway.model.resp.esb.v3.EsbFileSourceV3DTO; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -62,4 +66,26 @@ EsbResp updateFileSource( EsbCreateOrUpdateFileSourceV3Req req ); + @GetMapping("/get_file_source_detail") + EsbResp getFileSourceDetail( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id", required = false) Long bizId, + @RequestParam(value = "bk_scope_type", required = false) String scopeType, + @RequestParam(value = "bk_scope_id", required = false) String scopeId, + @RequestParam(value = "code") String code); + + /** + * 获取文件源详情 + * + * @param req 查询请求 + * @return 文件源详情 + */ + @PostMapping("/get_file_source_detail") + EsbResp getFileSourceDetailUsingPost( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestBody + @Validated + EsbGetFileSourceDetailV3Req req); } diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java index d7f9e48e43..0b8546984a 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResource.java @@ -24,7 +24,9 @@ package com.tencent.bk.job.file_gateway.api.inner; +import com.tencent.bk.job.common.annotation.CompatibleImplementation; import com.tencent.bk.job.common.annotation.InternalAPI; +import com.tencent.bk.job.common.constant.CompatibleType; import com.tencent.bk.job.common.model.InternalResponse; import com.tentent.bk.job.common.api.feign.annotation.SmartFeignClient; import io.swagger.annotations.Api; @@ -39,6 +41,15 @@ public interface ServiceFileSourceResource { @ApiOperation(value = "获取文件源ID", produces = "application/json") + @GetMapping("/service/app/{appId}/fileSource/getFileSourceIdByCode/codes/{code}") + InternalResponse getFileSourceIdByCode( + @ApiParam(value = "Job业务ID", required = true) @PathVariable("appId") Long appId, + @ApiParam(value = "文件源标识", required = true) @PathVariable("code") String code); + + @Deprecated + @CompatibleImplementation(name = "fileSourceId", deprecatedVersion = "3.9.x", type = CompatibleType.DEPLOY, + explain = "文件源标识仅在appId下唯一,发布完成后可删除") + @ApiOperation(value = "获取文件源ID", produces = "application/json") @GetMapping("/service/fileSource/getFileSourceIdByCode/codes/{code}") InternalResponse getFileSourceIdByCode( @ApiParam(value = "文件源标识", required = true) @PathVariable("code") String code); diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/req/esb/v3/EsbGetFileSourceDetailV3Req.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/req/esb/v3/EsbGetFileSourceDetailV3Req.java new file mode 100644 index 0000000000..44ea316d1a --- /dev/null +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/req/esb/v3/EsbGetFileSourceDetailV3Req.java @@ -0,0 +1,21 @@ +package com.tencent.bk.job.file_gateway.model.req.esb.v3; + +import com.tencent.bk.job.common.esb.model.EsbAppScopeReq; +import com.tencent.bk.job.common.validation.NotBlankField; +import com.tencent.bk.job.common.validation.NotContainSpecialChar; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbGetFileSourceDetailV3Req extends EsbAppScopeReq { + + /** + * 文件源Code + */ + @ApiModelProperty(value = "文件源Code") + @NotBlankField(fieldName = "code") + @NotContainSpecialChar(fieldName = "code") + private String code; +} diff --git a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/esb/v3/EsbFileSourceV3DTO.java b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/esb/v3/EsbFileSourceV3DTO.java index 188a87082a..31f17585a8 100644 --- a/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/esb/v3/EsbFileSourceV3DTO.java +++ b/src/backend/job-file-gateway/api-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/resp/esb/v3/EsbFileSourceV3DTO.java @@ -26,9 +26,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.tencent.bk.job.common.esb.model.EsbAppScopeDTO; -import com.tencent.bk.job.common.util.json.LongTimestampSerializer; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -59,11 +57,11 @@ public class EsbFileSourceV3DTO extends EsbAppScopeDTO { @JsonPropertyDescription("File source status") private Integer status; /** - * 类型 + * 文件源类型code */ - @JsonProperty("file_source_type") - @JsonPropertyDescription("File source type") - private Integer fileSourceType; + @JsonProperty("file_source_type_code") + @JsonPropertyDescription("File source type code") + private String fileSourceTypeCode; /** * 是否为公共文件源 @@ -73,7 +71,7 @@ public class EsbFileSourceV3DTO extends EsbAppScopeDTO { private boolean publicFlag; /** - * 凭据Id + * 凭证Id */ @JsonPropertyDescription("File source credential id") @JsonProperty("credential_id") @@ -106,7 +104,6 @@ public class EsbFileSourceV3DTO extends EsbAppScopeDTO { /** * 更新时间 */ - @JsonSerialize(using = LongTimestampSerializer.class) @JsonProperty("last_modify_time") @JsonPropertyDescription("Last modify time") private Long lastModifyTime; diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3ResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3ResourceImpl.java index f7e34dd4d8..184954e022 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3ResourceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/esb/EsbFileSourceV3ResourceImpl.java @@ -3,17 +3,22 @@ import com.tencent.bk.audit.annotations.AuditEntry; import com.tencent.bk.audit.annotations.AuditRequestBody; import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.FailedPreconditionException; import com.tencent.bk.job.common.exception.InvalidParamException; import com.tencent.bk.job.common.exception.MissingParameterException; import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.metrics.CommonMetricNames; +import com.tencent.bk.job.common.service.AppScopeMappingService; import com.tencent.bk.job.file_gateway.consts.WorkerSelectModeEnum; import com.tencent.bk.job.file_gateway.consts.WorkerSelectScopeEnum; import com.tencent.bk.job.file_gateway.model.dto.FileSourceDTO; import com.tencent.bk.job.file_gateway.model.dto.FileSourceTypeDTO; import com.tencent.bk.job.file_gateway.model.req.esb.v3.EsbCreateOrUpdateFileSourceV3Req; +import com.tencent.bk.job.file_gateway.model.req.esb.v3.EsbGetFileSourceDetailV3Req; import com.tencent.bk.job.file_gateway.model.resp.esb.v3.EsbFileSourceSimpleInfoV3DTO; +import com.tencent.bk.job.file_gateway.model.resp.esb.v3.EsbFileSourceV3DTO; import com.tencent.bk.job.file_gateway.service.FileSourceService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -27,14 +32,18 @@ public class EsbFileSourceV3ResourceImpl implements EsbFileSourceV3Resource { private final FileSourceService fileSourceService; + private final AppScopeMappingService appScopeMappingService; @Autowired - public EsbFileSourceV3ResourceImpl(FileSourceService fileSourceService) { + public EsbFileSourceV3ResourceImpl(FileSourceService fileSourceService, + AppScopeMappingService appScopeMappingService) { this.fileSourceService = fileSourceService; + this.appScopeMappingService = appScopeMappingService; } @Override @AuditEntry(actionId = ActionId.CREATE_FILE_SOURCE) + @EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "create_file_source"}) public EsbResp createFileSource( String username, String appCode, @@ -48,6 +57,7 @@ public EsbResp createFileSource( @Override @AuditEntry(actionId = ActionId.MANAGE_FILE_SOURCE) + @EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "update_file_source"}) public EsbResp updateFileSource( String username, String appCode, @@ -60,6 +70,36 @@ public EsbResp updateFileSource( return EsbResp.buildSuccessResp(new EsbFileSourceSimpleInfoV3DTO(updateFileSource.getId())); } + @Override + @AuditEntry(actionId = ActionId.VIEW_FILE_SOURCE) + @EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "get_file_source_detail"}) + public EsbResp getFileSourceDetail( + String username, + String appCode, + Long bizId, + String scopeType, + String scopeId, + String code) { + EsbGetFileSourceDetailV3Req req = new EsbGetFileSourceDetailV3Req(); + req.setBizId(bizId); + req.setScopeType(scopeType); + req.setScopeId(scopeId); + req.setCode(code); + req.fillAppResourceScope(appScopeMappingService); + return getFileSourceDetailUsingPost(username, appCode, req); + } + + @Override + @AuditEntry(actionId = ActionId.VIEW_FILE_SOURCE) + @EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "get_file_source_detail"}) + public EsbResp getFileSourceDetailUsingPost( + String username, + String appCode, + @AuditRequestBody EsbGetFileSourceDetailV3Req req) { + FileSourceDTO fileSourceDTO = fileSourceService.getFileSourceByCode(req.getAppId(), req.getCode()); + return EsbResp.buildSuccessResp(FileSourceDTO.toEsbFileSourceV3DTO(fileSourceDTO)); + } + private void checkCommonParam(EsbCreateOrUpdateFileSourceV3Req req) { if (StringUtils.isBlank(req.getAlias())) { throw new InvalidParamException(ErrorCode.MISSING_PARAM_WITH_PARAM_NAME, new String[]{"alias"}); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResourceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResourceImpl.java index 4aaac4f7d8..e62d319fab 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResourceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/api/inner/ServiceFileSourceResourceImpl.java @@ -45,6 +45,15 @@ public ServiceFileSourceResourceImpl(FileSourceService fileSourceService) { this.fileSourceService = fileSourceService; } + @Override + public InternalResponse getFileSourceIdByCode(Long appId, String code) { + FileSourceDTO fileSourceDTO = fileSourceService.getFileSourceByCode(appId, code); + if (null == fileSourceDTO) { + throw new NotFoundException(ErrorCode.FAIL_TO_FIND_FILE_SOURCE_BY_CODE, new String[]{code}); + } + return InternalResponse.buildSuccessResp(fileSourceDTO.getId()); + } + @Override public InternalResponse getFileSourceIdByCode(String code) { FileSourceDTO fileSourceDTO = fileSourceService.getFileSourceByCode(code); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java index 976f2cb10a..5807ba2e99 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/FileSourceDAO.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.file_gateway.dao.filesource; +import com.tencent.bk.job.common.annotation.CompatibleImplementation; +import com.tencent.bk.job.common.constant.CompatibleType; import com.tencent.bk.job.file_gateway.model.dto.FileSourceBasicInfoDTO; import com.tencent.bk.job.file_gateway.model.dto.FileSourceDTO; @@ -45,8 +47,13 @@ public interface FileSourceDAO { List listFileSourceByIds(Collection ids); + @Deprecated + @CompatibleImplementation(name = "fileSourceId", deprecatedVersion = "3.9.x", type = CompatibleType.DEPLOY, + explain = "文件源标识仅在appId下唯一,发布完成后可删除") FileSourceDTO getFileSourceByCode(String code); + FileSourceDTO getFileSourceByCode(Long appId, String code); + Integer countAvailableLikeFileSource(Long appId, String credentialId, String alias); Integer countFileSource(Long appId, String credentialId, String alias); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java index d740366be6..4d265f5b79 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileSourceDAOImpl.java @@ -313,9 +313,22 @@ public List listFileSourceByIds(Collection ids) @Override public FileSourceDTO getFileSourceByCode(String code) { - val record = dslContext.selectFrom(defaultTable).where( - defaultTable.CODE.eq(code) - ).fetchOne(); + val record = dslContext.selectFrom(defaultTable) + .where(defaultTable.CODE.eq(code)) + .fetchOne(); + if (record == null) { + return null; + } else { + return convertRecordToDto(record); + } + } + + @Override + public FileSourceDTO getFileSourceByCode(Long appId, String code) { + val record = dslContext.selectFrom(defaultTable) + .where(defaultTable.CODE.eq(code)) + .and(defaultTable.APP_ID.eq(appId)) + .fetchOne(); if (record == null) { return null; } else { diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileSourceDTO.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileSourceDTO.java index 0c5b1d19d3..6b1d2e8f2b 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileSourceDTO.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/model/dto/FileSourceDTO.java @@ -92,7 +92,7 @@ public class FileSourceDTO { */ private Boolean shareToAllApp; /** - * 凭据Id + * 凭证Id */ private String credentialId; /** @@ -165,7 +165,7 @@ public static EsbFileSourceV3DTO toEsbFileSourceV3DTO(FileSourceDTO fileSourceDT fileSource.setAlias(fileSourceDTO.getAlias()); fileSource.setCredentialId(fileSourceDTO.getCredentialId()); fileSource.setEnable(fileSourceDTO.getEnable()); - fileSource.setFileSourceType(fileSourceDTO.getFileSourceType().getId()); + fileSource.setFileSourceTypeCode(fileSourceDTO.getFileSourceType().getCode()); fileSource.setPublicFlag(fileSourceDTO.getPublicFlag()); fileSource.setStatus(fileSourceDTO.getStatus()); fileSource.setCreateTime(fileSourceDTO.getCreateTime()); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java index 5dd296a433..93acbc6ad3 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/CredentialService.java @@ -29,7 +29,7 @@ public interface CredentialService { /** - * 获取凭据 + * 获取凭证 * * @param id * @return diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java index e059972f16..9135d578e7 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/FileSourceService.java @@ -24,6 +24,8 @@ package com.tencent.bk.job.file_gateway.service; +import com.tencent.bk.job.common.annotation.CompatibleImplementation; +import com.tencent.bk.job.common.constant.CompatibleType; import com.tencent.bk.job.file_gateway.model.dto.FileSourceBasicInfoDTO; import com.tencent.bk.job.file_gateway.model.dto.FileSourceDTO; import com.tencent.bk.job.file_gateway.model.dto.FileSourceTypeDTO; @@ -90,8 +92,13 @@ List listWorkTableFileSource( List listFileSourceByIds(Collection ids); + @Deprecated + @CompatibleImplementation(name = "fileSourceId", deprecatedVersion = "3.9.x", type = CompatibleType.DEPLOY, + explain = "文件源标识仅在appId下唯一,发布完成后可删除") FileSourceDTO getFileSourceByCode(String code); + FileSourceDTO getFileSourceByCode(Long appId, String code); + List getFileSourceParams(Long appId, String fileSourceTypeCode); Boolean checkFileSourceAlias(Long appId, String alias, Integer fileSourceId); diff --git a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java index ab54ae2f3a..49d94ec7a6 100644 --- a/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java +++ b/src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/service/impl/FileSourceServiceImpl.java @@ -313,6 +313,11 @@ public FileSourceDTO getFileSourceByCode(String code) { return fileSourceDAO.getFileSourceByCode(code); } + @Override + public FileSourceDTO getFileSourceByCode(Long appId, String code) { + return fileSourceDAO.getFileSourceByCode(appId, code); + } + private Long chooseAvailableWorker(String fileSourceTypeCode) { List fileSourceTypeDTOList = fileSourceTypeDAO.listByCodeOrderByVersion(fileSourceTypeCode); diff --git a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java index c4604013a1..fc18e84ffd 100644 --- a/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java +++ b/src/backend/job-file-worker-sdk/api-job-file-worker-sdk/src/main/java/com/tencent/bk/job/file/worker/model/req/BaseReq.java @@ -38,7 +38,7 @@ public class BaseReq { // 文件源类型编码 String fileSourceTypeCode; - // 凭据信息 + // 凭证信息 @SkipLogFields CommonCredential credential; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbCredentialV3Resource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbCredentialV3Resource.java index 7c6b55cf33..38f01c9fb8 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbCredentialV3Resource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/v3/EsbCredentialV3Resource.java @@ -28,16 +28,20 @@ import com.tencent.bk.job.common.constant.JobCommonHeaders; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.manage.model.esb.v3.request.EsbCreateOrUpdateCredentialV3Req; +import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetCredentialDetailV3Req; import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialSimpleInfoV3DTO; +import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialV3DTO; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** - * 凭据API-V3 + * 凭证API-V3 */ @RequestMapping("/esb/api/v3") @RestController @@ -62,4 +66,27 @@ EsbResp updateCredential( EsbCreateOrUpdateCredentialV3Req req ); + @GetMapping("/get_credential_detail") + EsbResp getCredentialDetail( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestParam(value = "bk_biz_id", required = false) Long bizId, + @RequestParam(value = "bk_scope_type", required = false) String scopeType, + @RequestParam(value = "bk_scope_id", required = false) String scopeId, + @RequestParam(value = "id") String id); + + /** + * 获取凭证详情 + * + * @param req 查询请求 + * @return 凭证详情 + */ + @PostMapping("/get_credential_detail") + EsbResp getCredentialDetailUsingPost( + @RequestHeader(value = JobCommonHeaders.USERNAME) String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode, + @RequestBody + @Validated + EsbGetCredentialDetailV3Req req); + } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCredentialResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCredentialResource.java index 8ffce9cb58..dc056cd55b 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCredentialResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/inner/ServiceCredentialResource.java @@ -39,12 +39,12 @@ @InternalAPI public interface ServiceCredentialResource { - @ApiOperation(value = "获取凭据详情", produces = "application/json") + @ApiOperation(value = "获取凭证详情", produces = "application/json") @GetMapping("/service/credentials/app/{appId}/ids/{id}") InternalResponse getCredentialById( @ApiParam(value = "业务ID", required = true) @PathVariable("appId") Long appId, - @ApiParam("凭据ID") + @ApiParam("凭证ID") @PathVariable("id") String id ); diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCredentialResource.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCredentialResource.java index 828f6472a1..82b5a471b6 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCredentialResource.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/WebCredentialResource.java @@ -53,7 +53,7 @@ @WebAPI public interface WebCredentialResource { - @ApiOperation(value = "获取凭据列表", produces = "application/json") + @ApiOperation(value = "获取凭证列表", produces = "application/json") @GetMapping("/list") Response> listCredentials( @ApiParam("用户名,网关自动传入") @@ -91,7 +91,7 @@ Response> listCredentials( Integer pageSize ); - @ApiOperation(value = "分页获取凭据基础信息", produces = "application/json") + @ApiOperation(value = "分页获取凭证基础信息", produces = "application/json") @GetMapping("/basicInfo/list") Response> listCredentialBasicInfo( @ApiParam("用户名,网关自动传入") @@ -115,7 +115,7 @@ Response> listCredentialBasicInfo( ); - @ApiOperation(value = "新增凭据", produces = "application/json") + @ApiOperation(value = "新增凭证", produces = "application/json") @PostMapping Response createCredential( @ApiParam(value = "用户名,网关自动传入", required = true) @@ -135,7 +135,7 @@ Response createCredential( CredentialCreateUpdateReq createUpdateReq ); - @ApiOperation(value = "更新凭据", produces = "application/json") + @ApiOperation(value = "更新凭证", produces = "application/json") @PutMapping("/{credentialId}") Response updateCredential( @ApiParam(value = "用户名,网关自动传入", required = true) @@ -159,7 +159,7 @@ Response updateCredential( ); - @ApiOperation(value = "删除凭据", produces = "application/json") + @ApiOperation(value = "删除凭证", produces = "application/json") @DeleteMapping("/ids/{id}") Response deleteCredentialById( @ApiParam("用户名,网关自动传入") @@ -174,7 +174,7 @@ Response deleteCredentialById( @ApiParam(value = "资源范围ID", required = true) @PathVariable(value = "scopeId") String scopeId, - @ApiParam("凭据ID") + @ApiParam("凭证ID") @PathVariable("id") String id ); diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbCreateOrUpdateCredentialV3Req.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbCreateOrUpdateCredentialV3Req.java index 478324649d..5853f769af 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbCreateOrUpdateCredentialV3Req.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbCreateOrUpdateCredentialV3Req.java @@ -30,24 +30,24 @@ import lombok.EqualsAndHashCode; /** - * 新建凭据请求 + * 新建凭证请求 */ @EqualsAndHashCode(callSuper = true) @Data public class EsbCreateOrUpdateCredentialV3Req extends EsbAppScopeReq { /** - * 凭据ID + * 凭证ID */ private String id; /** - * 凭据名称 + * 凭证名称 */ private String name; /** - * 凭据类型 + * 凭证类型 */ private String type; diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbGetCredentialDetailV3Req.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbGetCredentialDetailV3Req.java new file mode 100644 index 0000000000..b8069035a4 --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/request/EsbGetCredentialDetailV3Req.java @@ -0,0 +1,19 @@ +package com.tencent.bk.job.manage.model.esb.v3.request; + +import com.tencent.bk.job.common.esb.model.EsbAppScopeReq; +import com.tencent.bk.job.common.validation.NotBlankField; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbGetCredentialDetailV3Req extends EsbAppScopeReq { + + /** + * 凭证id + */ + @ApiModelProperty(value = "凭证id") + @NotBlankField(fieldName = "id") + private String id; +} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbCredentialV3DTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbCredentialV3DTO.java new file mode 100644 index 0000000000..bbd4a585a4 --- /dev/null +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/esb/v3/response/EsbCredentialV3DTO.java @@ -0,0 +1,87 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.manage.model.esb.v3.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import com.tencent.bk.job.common.esb.model.EsbAppScopeDTO; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +public class EsbCredentialV3DTO extends EsbAppScopeDTO { + + /** + * id + */ + @JsonPropertyDescription("Credential id") + private String id; + + /** + * 凭证名称 + */ + @JsonPropertyDescription("Credential name") + private String name; + + /** + * 凭证类型 + */ + @JsonPropertyDescription("Credential type") + private String type; + + /** + * 描述 + */ + @JsonPropertyDescription("Credential name") + private String description; + + /** + * 创建人 + */ + @JsonPropertyDescription("Creator") + private String creator; + /** + * 创建时间 + */ + @JsonProperty("create_time") + @JsonPropertyDescription("Create time") + private Long createTime; + /** + * 更新人 + */ + @JsonProperty("last_modify_user") + @JsonPropertyDescription("Last modify user") + private String lastModifyUser; + + /** + * 更新时间 + */ + @JsonProperty("last_modify_time") + @JsonPropertyDescription("Last modify time") + private Long lastModifyTime; +} diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceBasicCredentialDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceBasicCredentialDTO.java index 14e794c26a..f1011c912f 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceBasicCredentialDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceBasicCredentialDTO.java @@ -30,7 +30,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -@ApiModel("凭据基本信息") +@ApiModel("凭证基本信息") @Data @AllArgsConstructor @NoArgsConstructor diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDTO.java index b5e782d06f..7bea9cf96b 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDTO.java @@ -29,7 +29,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; -@ApiModel("凭据") +@ApiModel("凭证") @Data public class ServiceCredentialDTO { /** @@ -53,8 +53,8 @@ public class ServiceCredentialDTO { @ApiModelProperty("类型") private String type; /** - * 凭据 + * 凭证 */ - @ApiModelProperty("凭据") + @ApiModelProperty("凭证") private CommonCredential credential; } diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDisplayDTO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDisplayDTO.java index e0d14539e0..0848b1b1fc 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDisplayDTO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/inner/resp/ServiceCredentialDisplayDTO.java @@ -29,7 +29,7 @@ import lombok.AllArgsConstructor; import lombok.Data; -@ApiModel("凭据") +@ApiModel("凭证") @AllArgsConstructor @Data public class ServiceCredentialDisplayDTO { diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/CredentialCreateUpdateReq.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/CredentialCreateUpdateReq.java index ab246116c1..a85f063f73 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/CredentialCreateUpdateReq.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/request/CredentialCreateUpdateReq.java @@ -36,13 +36,13 @@ import static com.tencent.bk.job.manage.api.common.constants.CredentialTypeEnum.USERNAME_PASSWORD; @Data -@ApiModel("凭据创建/更新请求") +@ApiModel("凭证创建/更新请求") public class CredentialCreateUpdateReq { /** - * 凭据ID + * 凭证ID */ - @ApiModelProperty(value = "凭据 ID", hidden = true) + @ApiModelProperty(value = "凭证 ID", hidden = true) private String id; /** * 名称 diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialBasicVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialBasicVO.java index ffdb666ec6..7e86735736 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialBasicVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialBasicVO.java @@ -28,7 +28,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; -@ApiModel("凭据") +@ApiModel("凭证") @Data public class CredentialBasicVO { /** diff --git a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialVO.java b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialVO.java index de79504482..d019c20600 100644 --- a/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialVO.java +++ b/src/backend/job-manage/api-job-manage/src/main/java/com/tencent/bk/job/manage/model/web/vo/CredentialVO.java @@ -30,7 +30,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; -@ApiModel("凭据") +@ApiModel("凭证") @Data public class CredentialVO { /** diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbCredentialResourceV3Impl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbCredentialResourceV3Impl.java index 90b0973d23..e6eeb134df 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbCredentialResourceV3Impl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/esb/impl/v3/EsbCredentialResourceV3Impl.java @@ -27,14 +27,19 @@ import com.tencent.bk.audit.annotations.AuditEntry; import com.tencent.bk.audit.annotations.AuditRequestBody; import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.esb.metrics.EsbApiTimed; import com.tencent.bk.job.common.esb.model.EsbResp; import com.tencent.bk.job.common.exception.InvalidParamException; import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.metrics.CommonMetricNames; +import com.tencent.bk.job.common.service.AppScopeMappingService; import com.tencent.bk.job.manage.api.common.constants.CredentialTypeEnum; import com.tencent.bk.job.manage.api.esb.v3.EsbCredentialV3Resource; import com.tencent.bk.job.manage.model.dto.CredentialDTO; import com.tencent.bk.job.manage.model.esb.v3.request.EsbCreateOrUpdateCredentialV3Req; +import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetCredentialDetailV3Req; import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialSimpleInfoV3DTO; +import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialV3DTO; import com.tencent.bk.job.manage.model.web.request.CredentialCreateUpdateReq; import com.tencent.bk.job.manage.service.CredentialService; import lombok.extern.slf4j.Slf4j; @@ -47,10 +52,13 @@ @Slf4j public class EsbCredentialResourceV3Impl implements EsbCredentialV3Resource { private final CredentialService credentialService; + private final AppScopeMappingService appScopeMappingService; @Autowired - public EsbCredentialResourceV3Impl(CredentialService credentialService) { + public EsbCredentialResourceV3Impl(CredentialService credentialService, + AppScopeMappingService appScopeMappingService) { this.credentialService = credentialService; + this.appScopeMappingService = appScopeMappingService; } @Override @@ -100,6 +108,34 @@ public EsbResp updateCredential( return EsbResp.buildSuccessResp(updateCredential.toEsbCredentialSimpleInfoV3DTO()); } + @Override + @EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "get_credential_detail"}) + public EsbResp getCredentialDetail( + String username, + String appCode, + Long bizId, + String scopeType, + String scopeId, + String id) { + EsbGetCredentialDetailV3Req req = new EsbGetCredentialDetailV3Req(); + req.setBizId(bizId); + req.setScopeType(scopeType); + req.setScopeId(scopeId); + req.setId(id); + req.fillAppResourceScope(appScopeMappingService); + return getCredentialDetailUsingPost(username, appCode, req); + } + + @Override + @EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "get_credential_detail"}) + public EsbResp getCredentialDetailUsingPost( + String username, + String appCode, + @AuditRequestBody EsbGetCredentialDetailV3Req req) { + CredentialDTO credentialDTO = credentialService.getCredentialById(req.getId()); + return EsbResp.buildSuccessResp(credentialDTO.toEsbCredentialV3DTO()); + } + private void checkUpdateParam(EsbCreateOrUpdateCredentialV3Req req) { if (StringUtils.isBlank(req.getId())) { throw new InvalidParamException(ErrorCode.ILLEGAL_PARAM_WITH_PARAM_NAME_AND_REASON, diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/CredentialDAOImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/CredentialDAOImpl.java index 452c0d5ff9..718035d4c2 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/CredentialDAOImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/impl/CredentialDAOImpl.java @@ -206,7 +206,7 @@ private List buildConditionList( } /** - * 查询符合条件的凭据数量 + * 查询符合条件的凭证数量 */ private long getPageCredentialCount(CredentialDTO credentialQuery, BaseSearchCondition baseSearchCondition) { List conditions = buildConditionList(credentialQuery, baseSearchCondition); @@ -214,7 +214,7 @@ private long getPageCredentialCount(CredentialDTO credentialQuery, BaseSearchCon } /** - * 查询符合条件的凭据数量 + * 查询符合条件的凭证数量 */ private long getPageCredentialCount(Collection conditions) { Long count = dslContext diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/CredentialDTO.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/CredentialDTO.java index 2fac22c632..790afdc3d0 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/CredentialDTO.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/model/dto/CredentialDTO.java @@ -25,8 +25,12 @@ package com.tencent.bk.job.manage.model.dto; import com.tencent.bk.job.common.model.dto.CommonCredential; +import com.tencent.bk.job.common.model.dto.ResourceScope; +import com.tencent.bk.job.common.service.AppScopeMappingService; +import com.tencent.bk.job.common.util.ApplicationContextRegister; import com.tencent.bk.job.manage.api.common.constants.CredentialTypeEnum; import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialSimpleInfoV3DTO; +import com.tencent.bk.job.manage.model.esb.v3.response.EsbCredentialV3DTO; import com.tencent.bk.job.manage.model.inner.resp.ServiceCredentialDTO; import com.tencent.bk.job.manage.model.web.vo.CredentialBasicVO; import com.tencent.bk.job.manage.model.web.vo.CredentialVO; @@ -117,6 +121,24 @@ public ServiceCredentialDTO toServiceCredentialDTO() { return serviceCredentialDTO; } + public EsbCredentialV3DTO toEsbCredentialV3DTO() { + EsbCredentialV3DTO esbCredentialV3DTO = new EsbCredentialV3DTO(); + esbCredentialV3DTO.setId(id); + esbCredentialV3DTO.setName(name); + esbCredentialV3DTO.setType(type); + esbCredentialV3DTO.setDescription(description); + AppScopeMappingService appScopeMappingService = + ApplicationContextRegister.getBean(AppScopeMappingService.class); + ResourceScope resourceScope = appScopeMappingService.getScopeByAppId(appId); + esbCredentialV3DTO.setScopeType(resourceScope.getType().getValue()); + esbCredentialV3DTO.setScopeId(resourceScope.getId()); + esbCredentialV3DTO.setCreator(creator); + esbCredentialV3DTO.setCreateTime(createTime); + esbCredentialV3DTO.setLastModifyUser(lastModifyUser); + esbCredentialV3DTO.setLastModifyTime(lastModifyTime); + return esbCredentialV3DTO; + } + public EsbCredentialSimpleInfoV3DTO toEsbCredentialSimpleInfoV3DTO() { return new EsbCredentialSimpleInfoV3DTO(id, name); } diff --git a/support-files/bkiam/0007_bk_job_20210925-1000_iam.json b/support-files/bkiam/0007_bk_job_20210925-1000_iam.json index 37421f438a..6e80f33aa3 100644 --- a/support-files/bkiam/0007_bk_job_20210925-1000_iam.json +++ b/support-files/bkiam/0007_bk_job_20210925-1000_iam.json @@ -132,7 +132,7 @@ "id": "ticket", "name": "凭证", "name_en": "Tickets", - "description": "用于文件源访问认证的凭据", + "description": "用于文件源访问认证的凭证", "description_en": "Tickets for file-source access authentication", "parents": [ { diff --git a/support-files/bkiam/0008_bk_job_20220218-1000_iam.json b/support-files/bkiam/0008_bk_job_20220218-1000_iam.json index 941019a64a..6adf01acc9 100644 --- a/support-files/bkiam/0008_bk_job_20220218-1000_iam.json +++ b/support-files/bkiam/0008_bk_job_20220218-1000_iam.json @@ -171,7 +171,7 @@ "id": "ticket", "name": "凭证", "name_en": "Tickets", - "description": "用于文件源访问认证的凭据", + "description": "用于文件源访问认证的凭证", "description_en": "Tickets for file-source access authentication", "parents": [ { diff --git a/support-files/sql/job-file-gateway/0001_job_file_gateway_20201214-1000_V3.2.0_mysql.sql b/support-files/sql/job-file-gateway/0001_job_file_gateway_20201214-1000_V3.2.0_mysql.sql index 33f53aff6e..6582736e91 100644 --- a/support-files/sql/job-file-gateway/0001_job_file_gateway_20201214-1000_V3.2.0_mysql.sql +++ b/support-files/sql/job-file-gateway/0001_job_file_gateway_20201214-1000_V3.2.0_mysql.sql @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS `file_source` ( `custom_info` text CHARACTER SET utf8mb4 NULL COMMENT '各不同文件源的差异性自定义信息Json串', `public` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否为公共存储', `share_to_all_app` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否共享至全业务', - `credential_id` varchar(255) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '凭据Id', + `credential_id` varchar(255) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '凭证Id', `file_prefix` varchar(255) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '文件前缀名', `worker_select_scope` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT 'ALL' COMMENT '接入点选择范畴:APP/PUBLIC/ALL', `worker_select_mode` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT 'AUTO' COMMENT '接入点选择模式:AUTO/MANUAL', diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/constant/CredentialTypeEnum.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/constant/CredentialTypeEnum.java new file mode 100644 index 0000000000..404bd38475 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/constant/CredentialTypeEnum.java @@ -0,0 +1,52 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.api.constant; + +public enum CredentialTypeEnum { + APP_ID_SECRET_KEY(1, "AccessKey+SecretKey"), + PASSWORD(2, "单一密码"), + USERNAME_PASSWORD(3, "用户名+密码"), + SECRET_KEY(4, "单一SecretKey"); + + private final Integer value; + private final String description; + + public static String getAllNameStr() { + StringBuilder sb = new StringBuilder(); + CredentialTypeEnum[] values = CredentialTypeEnum.values(); + for (int i = 0; i < values.length; i++) { + sb.append(values[i].name()); + if (i < values.length - 1) { + sb.append(","); + } + } + return sb.toString(); + } + + CredentialTypeEnum(Integer type, String description) { + this.value = type; + this.description = description; + } +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/constant/FileSourceTypeEnum.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/constant/FileSourceTypeEnum.java new file mode 100644 index 0000000000..36ed5f8354 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/constant/FileSourceTypeEnum.java @@ -0,0 +1,30 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.api.constant; + +public enum FileSourceTypeEnum { + TENCENT_CLOUD_COS, + BLUEKING_ARTIFACTORY +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java index 483fdc36a9..abafd69502 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java @@ -1,5 +1,7 @@ package com.tencent.bk.job.api.util; +import com.tencent.bk.job.api.constant.CredentialTypeEnum; +import com.tencent.bk.job.api.constant.FileSourceTypeEnum; import com.tencent.bk.job.api.constant.HighRiskGrammarActionEnum; import com.tencent.bk.job.api.constant.ResourceScopeTypeEnum; import com.tencent.bk.job.api.constant.ScriptTypeEnum; @@ -7,8 +9,10 @@ import com.tencent.bk.job.api.props.TestProps; import com.tencent.bk.job.api.v3.constants.APIV3Urls; import com.tencent.bk.job.api.v3.model.EsbAccountV3BasicDTO; +import com.tencent.bk.job.api.v3.model.EsbCredentialSimpleInfoV3DTO; import com.tencent.bk.job.api.v3.model.EsbCronInfoV3DTO; import com.tencent.bk.job.api.v3.model.EsbDangerousRuleV3DTO; +import com.tencent.bk.job.api.v3.model.EsbFileSourceSimpleInfoV3DTO; import com.tencent.bk.job.api.v3.model.EsbFileSourceV3DTO; import com.tencent.bk.job.api.v3.model.EsbJobExecuteV3DTO; import com.tencent.bk.job.api.v3.model.EsbPageDataV3; @@ -17,6 +21,8 @@ import com.tencent.bk.job.api.v3.model.EsbServerV3DTO; import com.tencent.bk.job.api.v3.model.HostDTO; import com.tencent.bk.job.api.v3.model.request.EsbCreateDangerousRuleV3Req; +import com.tencent.bk.job.api.v3.model.request.EsbCreateOrUpdateCredentialV3Req; +import com.tencent.bk.job.api.v3.model.request.EsbCreateOrUpdateFileSourceV3Req; import com.tencent.bk.job.api.v3.model.request.EsbCreatePublicScriptV3Req; import com.tencent.bk.job.api.v3.model.request.EsbCreateScriptV3Request; import com.tencent.bk.job.api.v3.model.request.EsbDeleteCronV3Request; @@ -35,7 +41,9 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static com.tencent.bk.job.api.constant.Constant.SHELL_SCRIPT_CONTENT_BASE64; import static io.restassured.RestAssured.given; @@ -365,6 +373,54 @@ public static Long getTaskPlanId() { return null; } + public static EsbFileSourceSimpleInfoV3DTO createFileSource() { + EsbCreateOrUpdateFileSourceV3Req req = new EsbCreateOrUpdateFileSourceV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setCode(TestValueGenerator.generateUniqueStrValue("file_source_code", 50)); + req.setAlias(TestValueGenerator.generateUniqueStrValue("file_source_alias", 50)); + req.setType(FileSourceTypeEnum.BLUEKING_ARTIFACTORY.name()); + Map accessParams = new HashMap<>(); + accessParams.put("base_url", "https://bkrepo.com"); + req.setAccessParams(accessParams); + req.setCredentialId(TestValueGenerator.generateUniqueStrValue("credential_id", 50)); + EsbFileSourceSimpleInfoV3DTO fileSourceSimpleInfoV3DTO = given() + .spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_FILE_SOURCE) + .then() + .statusCode(200) + .extract() + .body() + .as(new TypeRef>() { + }) + .getData(); + fileSourceSimpleInfoV3DTO.setCode(req.getCode()); + return fileSourceSimpleInfoV3DTO; + } + + public static EsbCredentialSimpleInfoV3DTO createCredential() { + EsbCreateOrUpdateCredentialV3Req req = new EsbCreateOrUpdateCredentialV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setName(TestValueGenerator.generateUniqueStrValue("credential_name", 50)); + req.setDescription(TestValueGenerator.generateUniqueStrValue("credential_desc", 50)); + req.setType(CredentialTypeEnum.USERNAME_PASSWORD.name()); + req.setCredentialUsername("admin"); + req.setCredentialPassword("password"); + return given() + .spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_CREDENTIAL) + .then() + .statusCode(200) + .extract() + .body() + .as(new TypeRef>() { + }) + .getData(); + } + private static String buildJobName() { return "api.test." + DateUtils.formatLocalDateTime(LocalDateTime.now(), "yyyyMMddhhmmssSSS"); } diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java index 42426a2ff6..78b109206a 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java @@ -73,4 +73,12 @@ public interface APIV3Urls { String GET_JOB_PLAN_LIST = "/api/job/v3/job-manage/get_job_plan_list"; + + String CREATE_FILE_SOURCE = "/api/job/v3/job-file-gateway/create_file_source"; + String UPDATE_FILE_SOURCE = "/api/job/v3/job-file-gateway/update_file_source"; + String GET_FILE_SOURCE_DETAIL = "/api/job/v3/job-file-gateway/get_file_source_detail"; + + String CREATE_CREDENTIAL = "/api/job/v3/job-manage/create_credential"; + String UPDATE_CREDENTIAL = "/api/job/v3/job-manage/update_credential"; + String GET_CREDENTIAL_DETAIL = "/api/job/v3/job-manage/get_credential_detail"; } diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbCredentialSimpleInfoV3DTO.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbCredentialSimpleInfoV3DTO.java new file mode 100644 index 0000000000..77de48825a --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbCredentialSimpleInfoV3DTO.java @@ -0,0 +1,44 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.api.v3.model; + +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class EsbCredentialSimpleInfoV3DTO { + @JsonPropertyDescription("Credential id") + private String id; + + @JsonPropertyDescription("Credential name") + private String name; + + public EsbCredentialSimpleInfoV3DTO(String id, String name) { + this.id = id; + this.name = name; + } +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbCredentialV3DTO.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbCredentialV3DTO.java new file mode 100644 index 0000000000..739903ca57 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbCredentialV3DTO.java @@ -0,0 +1,86 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.api.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +public class EsbCredentialV3DTO extends EsbAppScopeDTO { + + /** + * id + */ + @JsonPropertyDescription("Credential id") + private String id; + + /** + * 凭证名称 + */ + @JsonPropertyDescription("Credential name") + private String name; + + /** + * 凭证类型 + */ + @JsonPropertyDescription("Credential type") + private String type; + + /** + * 描述 + */ + @JsonPropertyDescription("Credential name") + private String description; + + /** + * 创建人 + */ + @JsonPropertyDescription("Creator") + private String creator; + /** + * 创建时间 + */ + @JsonProperty("create_time") + @JsonPropertyDescription("Create time") + private Long createTime; + /** + * 更新人 + */ + @JsonProperty("last_modify_user") + @JsonPropertyDescription("Last modify user") + private String lastModifyUser; + + /** + * 更新时间 + */ + @JsonProperty("last_modify_time") + @JsonPropertyDescription("Last modify time") + private Long lastModifyTime; +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbFileSourceDetailV3DTO.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbFileSourceDetailV3DTO.java new file mode 100644 index 0000000000..80064adc02 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbFileSourceDetailV3DTO.java @@ -0,0 +1,110 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.api.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +public class EsbFileSourceDetailV3DTO extends EsbAppScopeDTO { + /** + * id + */ + @JsonPropertyDescription("File source id") + private Integer id; + /** + * 文件源标识 + */ + @JsonPropertyDescription("File source code") + private String code; + + /** + * 文件源别名 + */ + @JsonPropertyDescription("File source alias") + private String alias; + /** + * 状态 + */ + @JsonPropertyDescription("File source status") + private Integer status; + /** + * 文件源类型code + */ + @JsonProperty("file_source_type_code") + @JsonPropertyDescription("File source type code") + private Integer fileSourceTypeCode; + + /** + * 是否为公共文件源 + */ + @JsonProperty("is_public") + @JsonPropertyDescription("Is public file source") + private boolean publicFlag; + + /** + * 凭证Id + */ + @JsonPropertyDescription("File source credential id") + @JsonProperty("credential_id") + private String credentialId; + + /** + * 是否启用 + */ + @JsonPropertyDescription("Is file source enabled") + private Boolean enable; + + /** + * 创建人 + */ + @JsonPropertyDescription("Creator") + private String creator; + /** + * 创建时间 + */ + @JsonProperty("create_time") + @JsonPropertyDescription("Create time") + private Long createTime; + /** + * 更新人 + */ + @JsonProperty("last_modify_user") + @JsonPropertyDescription("Last modify user") + private String lastModifyUser; + + /** + * 更新时间 + */ + @JsonProperty("last_modify_time") + @JsonPropertyDescription("Last modify time") + private Long lastModifyTime; + +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbFileSourceSimpleInfoV3DTO.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbFileSourceSimpleInfoV3DTO.java new file mode 100644 index 0000000000..e9d1bdbd9f --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/EsbFileSourceSimpleInfoV3DTO.java @@ -0,0 +1,39 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.api.v3.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class EsbFileSourceSimpleInfoV3DTO { + + private Integer id; + + private String code; +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbCreateOrUpdateCredentialV3Req.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbCreateOrUpdateCredentialV3Req.java new file mode 100644 index 0000000000..a6b5cda923 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbCreateOrUpdateCredentialV3Req.java @@ -0,0 +1,82 @@ +/* + * Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. + * + * License for BK-JOB蓝鲸智云作业平台: + * -------------------------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +package com.tencent.bk.job.api.v3.model.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.api.model.EsbAppScopeReq; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 新建凭证请求 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbCreateOrUpdateCredentialV3Req extends EsbAppScopeReq { + + /** + * 凭证ID + */ + private String id; + + /** + * 凭证名称 + */ + private String name; + + /** + * 凭证类型 + */ + private String type; + + /** + * 描述 + */ + private String description; + + /** + * AccessKey + */ + @JsonProperty("credential_access_key") + private String credentialAccessKey; + + /** + * SecretKey + */ + @JsonProperty("credential_secret_key") + private String credentialSecretKey; + + /** + * Username + */ + @JsonProperty("credential_username") + private String credentialUsername; + + /** + * Password + */ + @JsonProperty("credential_password") + private String credentialPassword; +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbCreateOrUpdateFileSourceV3Req.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbCreateOrUpdateFileSourceV3Req.java new file mode 100644 index 0000000000..27140b3fa7 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbCreateOrUpdateFileSourceV3Req.java @@ -0,0 +1,44 @@ +package com.tencent.bk.job.api.v3.model.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.api.model.EsbAppScopeReq; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.HashMap; +import java.util.Map; + +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbCreateOrUpdateFileSourceV3Req extends EsbAppScopeReq { + + /** + * 文件源Code + */ + private String code; + /** + * 文件源别名 + */ + private String alias; + /** + * 文件源类型 + */ + private String type; + + /** + * 文件源信息Map + */ + @JsonProperty(value = "access_params") + private Map accessParams = new HashMap<>(); + + /** + * 文件源凭证Id + */ + @JsonProperty(value = "credential_id") + private String credentialId; + /** + * 文件前缀 + */ + @JsonProperty(value = "file_prefix") + private String filePrefix = ""; +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbGetCredentialDetailV3Req.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbGetCredentialDetailV3Req.java new file mode 100644 index 0000000000..9658dce63e --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbGetCredentialDetailV3Req.java @@ -0,0 +1,15 @@ +package com.tencent.bk.job.api.v3.model.request; + +import com.tencent.bk.job.api.model.EsbAppScopeReq; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbGetCredentialDetailV3Req extends EsbAppScopeReq { + + /** + * 凭证id + */ + private String id; +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbGetFileSourceDetailV3Req.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbGetFileSourceDetailV3Req.java new file mode 100644 index 0000000000..1626aa9fb5 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbGetFileSourceDetailV3Req.java @@ -0,0 +1,15 @@ +package com.tencent.bk.job.api.v3.model.request; + +import com.tencent.bk.job.api.model.EsbAppScopeReq; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class EsbGetFileSourceDetailV3Req extends EsbAppScopeReq { + + /** + * 文件源Code + */ + private String code; +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CredentialResourceAPITest.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CredentialResourceAPITest.java new file mode 100644 index 0000000000..ab6f677ccd --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CredentialResourceAPITest.java @@ -0,0 +1,151 @@ +package com.tencent.bk.job.api.v3.testcase; + +import com.tencent.bk.job.api.constant.CredentialTypeEnum; +import com.tencent.bk.job.api.constant.ErrorCode; +import com.tencent.bk.job.api.constant.ResourceScopeTypeEnum; +import com.tencent.bk.job.api.model.EsbResp; +import com.tencent.bk.job.api.props.TestProps; +import com.tencent.bk.job.api.util.ApiUtil; +import com.tencent.bk.job.api.util.JsonUtil; +import com.tencent.bk.job.api.util.Operations; +import com.tencent.bk.job.api.util.TestValueGenerator; +import com.tencent.bk.job.api.v3.constants.APIV3Urls; +import com.tencent.bk.job.api.v3.model.EsbCredentialSimpleInfoV3DTO; +import com.tencent.bk.job.api.v3.model.request.EsbCreateOrUpdateCredentialV3Req; +import com.tencent.bk.job.api.v3.model.request.EsbGetCredentialDetailV3Req; +import io.restassured.common.mapper.TypeRef; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.notNullValue; + +/** + * 凭证 API 测试 + */ +@DisplayName("v3.CredentialResourceAPITest") +class CredentialResourceAPITest extends BaseTest { + + private static final List createdCredentialList = new ArrayList<>(); + + @Nested + class CredentialCreateTest { + @Test + @DisplayName("测试凭证正常创建") + void testCreateCredential() { + EsbCreateOrUpdateCredentialV3Req req = new EsbCreateOrUpdateCredentialV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setName(TestValueGenerator.generateUniqueStrValue("credential_name", 50)); + req.setDescription(TestValueGenerator.generateUniqueStrValue("credential_desc", 50)); + req.setType(CredentialTypeEnum.USERNAME_PASSWORD.name()); + req.setCredentialUsername("admin"); + req.setCredentialPassword("password"); + EsbCredentialSimpleInfoV3DTO createdCredential = + given() + .spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_CREDENTIAL) + .then() + .spec(ApiUtil.successResponseSpec()) + .body("data", notNullValue()) + .extract() + .body() + .as(new TypeRef>() { + }) + .getData(); + createdCredentialList.add(createdCredential); + } + + @Test + @DisplayName("异常创建凭证测试-比如参数校验不通过") + void givenInvalidCreateCredentialParamThenFail() { + EsbCreateOrUpdateCredentialV3Req req = new EsbCreateOrUpdateCredentialV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setName(TestValueGenerator.generateUniqueStrValue("credential_name", 50)); + req.setDescription(TestValueGenerator.generateUniqueStrValue("credential_desc", 50)); + req.setType(CredentialTypeEnum.USERNAME_PASSWORD.name()); + req.setCredentialUsername("admin"); + req.setCredentialPassword("password"); + + req.setName(null); + // 名称为空,创建失败 + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_CREDENTIAL) + .then() + .spec(ApiUtil.failResponseSpec(ErrorCode.ILLEGAL_PARAM_WITH_PARAM_NAME_AND_REASON)); + + req.setName(TestValueGenerator.generateUniqueStrValue("credential_name", 50)); + req.setType(null); + // 凭证类型为空,创建失败 + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_CREDENTIAL) + .then() + .spec(ApiUtil.failResponseSpec(ErrorCode.ILLEGAL_PARAM_WITH_PARAM_NAME_AND_REASON)); + } + } + + @Nested + class CredentialGetTest { + @Test + @DisplayName("测试查询凭证-通过id查询详情") + void testGetCredentialDetail() { + EsbCredentialSimpleInfoV3DTO CredentialSimpleInfoV3DTO = Operations.createCredential(); + createdCredentialList.add(CredentialSimpleInfoV3DTO); + EsbGetCredentialDetailV3Req req = new EsbGetCredentialDetailV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setId(CredentialSimpleInfoV3DTO.getId()); + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.GET_CREDENTIAL_DETAIL) + .then() + .spec(ApiUtil.successResponseSpec()) + .body("data", notNullValue()) + .body("data.id", equalTo(req.getId())) + .body("data.name", notNullValue()) + .body("data.type", notNullValue()) + .body("data.description", notNullValue()) + .body("data.bk_scope_type", equalTo(req.getScopeType())) + .body("data.bk_scope_id", equalTo(req.getScopeId())) + .body("data.creator", notNullValue()) + .body("data.create_time", greaterThan(0L)) + .body("data.last_modify_user", equalTo(TestProps.DEFAULT_TEST_USER)) + .body("data.last_modify_time", greaterThan(0L)); + } + } + + @Nested + class CredentialUpdateTest { + // 更新操作 + @Test + @DisplayName("测试凭证修改") + void testUpdateCredential() { + EsbCredentialSimpleInfoV3DTO CredentialSimpleInfoV3DTO = Operations.createCredential(); + createdCredentialList.add(CredentialSimpleInfoV3DTO); + EsbCreateOrUpdateCredentialV3Req req = new EsbCreateOrUpdateCredentialV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setId(CredentialSimpleInfoV3DTO.getId()); + req.setName(TestValueGenerator.generateUniqueStrValue("update_credential_name", 50)); + req.setType(CredentialTypeEnum.PASSWORD.name()); + req.setCredentialPassword("password"); + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.UPDATE_CREDENTIAL) + .then() + .spec(ApiUtil.successResponseSpec()) + .body("data", notNullValue()) + .body("data.id", equalTo(CredentialSimpleInfoV3DTO.getId())); + } + } +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/FileSourceResourceAPITest.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/FileSourceResourceAPITest.java new file mode 100644 index 0000000000..c1fb5753ea --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/FileSourceResourceAPITest.java @@ -0,0 +1,185 @@ +package com.tencent.bk.job.api.v3.testcase; + +import com.tencent.bk.job.api.constant.ErrorCode; +import com.tencent.bk.job.api.constant.FileSourceTypeEnum; +import com.tencent.bk.job.api.constant.ResourceScopeTypeEnum; +import com.tencent.bk.job.api.model.EsbResp; +import com.tencent.bk.job.api.props.TestProps; +import com.tencent.bk.job.api.util.ApiUtil; +import com.tencent.bk.job.api.util.JsonUtil; +import com.tencent.bk.job.api.util.Operations; +import com.tencent.bk.job.api.util.TestValueGenerator; +import com.tencent.bk.job.api.v3.constants.APIV3Urls; +import com.tencent.bk.job.api.v3.model.EsbFileSourceSimpleInfoV3DTO; +import com.tencent.bk.job.api.v3.model.request.EsbCreateOrUpdateFileSourceV3Req; +import com.tencent.bk.job.api.v3.model.request.EsbGetFileSourceDetailV3Req; +import io.restassured.common.mapper.TypeRef; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.notNullValue; + +/** + * 文件源 API 测试 + */ +@DisplayName("v3.FileSourceResourceAPITest") +class FileSourceResourceAPITest extends BaseTest { + + private static final List createdFileSourceList = new ArrayList<>(); + + @Nested + class FileSourceCreateTest { + @Test + @DisplayName("测试文件源正常创建") + void testCreateFileSource() { + EsbCreateOrUpdateFileSourceV3Req req = new EsbCreateOrUpdateFileSourceV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setCode(TestValueGenerator.generateUniqueStrValue("file_source_code", 50)); + req.setAlias(TestValueGenerator.generateUniqueStrValue("file_source_alias", 50)); + req.setType(FileSourceTypeEnum.BLUEKING_ARTIFACTORY.name()); + Map accessParams = new HashMap<>(); + accessParams.put("base_url", "https://bkrepo.com"); + req.setAccessParams(accessParams); + req.setCredentialId(TestValueGenerator.generateUniqueStrValue("credential_id", 50)); + EsbFileSourceSimpleInfoV3DTO createdFileSource = + given() + .spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_FILE_SOURCE) + .then() + .spec(ApiUtil.successResponseSpec()) + .body("data", notNullValue()) + .body("data.id", greaterThan(0)) + .extract() + .body() + .as(new TypeRef>() { + }) + .getData(); + createdFileSource.setCode(req.getCode()); + createdFileSourceList.add(createdFileSource); + } + + @Test + @DisplayName("异常创建文件源测试-比如参数校验不通过") + void givenInvalidCreateFileSourceParamThenFail() { + EsbCreateOrUpdateFileSourceV3Req req = new EsbCreateOrUpdateFileSourceV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setCode(TestValueGenerator.generateUniqueStrValue("file_source_code", 50)); + req.setAlias(TestValueGenerator.generateUniqueStrValue("file_source_alias", 50)); + req.setType(FileSourceTypeEnum.BLUEKING_ARTIFACTORY.name()); + Map accessParams = new HashMap<>(); + accessParams.put("base_url", "https://bkrepo.com"); + req.setAccessParams(accessParams); + req.setCredentialId(TestValueGenerator.generateUniqueStrValue("credential_id", 50)); + + req.setCode(null); + // code为空,创建失败 + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_FILE_SOURCE) + .then() + .spec(ApiUtil.failResponseSpec(ErrorCode.MISSING_PARAM_WITH_PARAM_NAME)); + + req.setCode("file_source_code_?<"); + // code有非法字符,创建失败 + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_FILE_SOURCE) + .then() + .spec(ApiUtil.failResponseSpec(ErrorCode.BAD_REQUEST)); + + req.setCode(TestValueGenerator.generateUniqueStrValue("file_source_code", 50)); + // 别名为空,创建失败 + req.setAlias(null); + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_FILE_SOURCE) + .then() + .spec(ApiUtil.failResponseSpec(ErrorCode.MISSING_PARAM_WITH_PARAM_NAME)); + + // 别名有非法字符,创建失败 + req.setAlias("alias|*"); + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_FILE_SOURCE) + .then() + .spec(ApiUtil.failResponseSpec(ErrorCode.BAD_REQUEST)); + + // 类型为空,创建失败 + req.setAlias(TestValueGenerator.generateUniqueStrValue("file_source_alias", 50)); + req.setType(null); + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.CREATE_FILE_SOURCE) + .then() + .spec(ApiUtil.failResponseSpec(ErrorCode.ILLEGAL_PARAM_WITH_PARAM_NAME)); + } + } + + @Nested + class FileSourceGetTest { + @Test + @DisplayName("测试查询文件源-通过code查询详情") + void testGetFileSourceDetail() { + EsbFileSourceSimpleInfoV3DTO fileSourceSimpleInfoV3DTO = Operations.createFileSource(); + createdFileSourceList.add(fileSourceSimpleInfoV3DTO); + EsbGetFileSourceDetailV3Req req = new EsbGetFileSourceDetailV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setCode(fileSourceSimpleInfoV3DTO.getCode()); + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.GET_FILE_SOURCE_DETAIL) + .then() + .spec(ApiUtil.successResponseSpec()) + .body("data", notNullValue()) + .body("data.id", greaterThan(0)) + .body("data.code", equalTo(req.getCode())) + .body("data.alias", notNullValue()) + .body("data.file_source_type_code", notNullValue()) + .body("data.is_public", notNullValue()) + .body("data.credential_id", notNullValue()) + .body("data.enable", notNullValue()) + .body("data.bk_scope_type", equalTo(req.getScopeType())) + .body("data.bk_scope_id", equalTo(req.getScopeId())) + .body("data.creator", notNullValue()) + .body("data.create_time", greaterThan(0L)) + .body("data.last_modify_user", equalTo(TestProps.DEFAULT_TEST_USER)) + .body("data.last_modify_time", greaterThan(0L)); + } + } + + @Nested + class FileSourceUpdateTest { + // 更新操作 + @Test + @DisplayName("测试文件源修改") + void testUpdateFileSource() { + EsbFileSourceSimpleInfoV3DTO fileSourceSimpleInfoV3DTO = Operations.createFileSource(); + createdFileSourceList.add(fileSourceSimpleInfoV3DTO); + EsbCreateOrUpdateFileSourceV3Req req = new EsbCreateOrUpdateFileSourceV3Req(); + req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ)); + req.setScopeType(ResourceScopeTypeEnum.BIZ.getValue()); + req.setCode(fileSourceSimpleInfoV3DTO.getCode()); + req.setAlias(TestValueGenerator.generateUniqueStrValue("update_file_source_alias", 50)); + given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.UPDATE_FILE_SOURCE) + .then() + .spec(ApiUtil.successResponseSpec()) + .body("data", notNullValue()) + .body("data.id", equalTo(fileSourceSimpleInfoV3DTO.getId())); + } + } +} diff --git a/versionLogs/zh_CN/V3.8.4_2023-11-10.md b/versionLogs/zh_CN/V3.8.4_2023-11-10.md index 1949097afe..283a7211ef 100644 --- a/versionLogs/zh_CN/V3.8.4_2023-11-10.md +++ b/versionLogs/zh_CN/V3.8.4_2023-11-10.md @@ -6,10 +6,10 @@ - [ 修复 ] 解决 IP选择器输入重复IP会报错的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2591) - [ 修复 ] 修复凭证表单字段校验提示错位问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2588) -- [ 修复 ] 解决各字段输入空格符也可成功创建凭据的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2587) +- [ 修复 ] 解决各字段输入空格符也可成功创建凭证的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2587) - [ 修复 ] 补全国际化相关缺漏 [详情](http://github.com/TencentBlueKing/bk-job/issues/2585) - [ 修复 ] 解决当主机类型全局变量为空时,查看任务的全局变量详情可能出现请求内部异常的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2583) -- [ 修复 ] 解决文件源引用的凭据在编辑表单页没有正常回显的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2576) +- [ 修复 ] 解决文件源引用的凭证在编辑表单页没有正常回显的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2576) - [ 修复 ] 解决文件源引用的凭证无法选取到列表第一页后面数据的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2579) - [ 修复 ] 解决执行历史详情页的表格字段显示设置在只有一个字段时,呼出的窗口会突破浏览器边界导致无法看全的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2574) - [ 修复 ] 修复作业模版调试操作没有正常生成审计事件问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2557) @@ -20,4 +20,4 @@ - [ 修复 ] 修复编辑文件源报 404 错误问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2554) - [ 修复 ] 解决因执行详情任务名称过长导致样式错乱的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2545) - [ 修复 ] 解决审计中心回调 Job 获取资源实例的 schema 报错问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2541) -- [ 修复 ] 解决权限中心回调作业平台API 请求脚本列表报错的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2540) \ No newline at end of file +- [ 修复 ] 解决权限中心回调作业平台API 请求脚本列表报错的问题 [详情](http://github.com/TencentBlueKing/bk-job/issues/2540)