Skip to content

Commit

Permalink
Merge pull request #2870 from liuliaozhong/master_issue_2830
Browse files Browse the repository at this point in the history
feat: 增加查询文件源与凭证详情的ApiGW接口 #2830
  • Loading branch information
jsonwan authored Apr 9, 2024
2 parents 22fe39c + b07d11e commit 2783365
Show file tree
Hide file tree
Showing 54 changed files with 1,480 additions and 74 deletions.
77 changes: 77 additions & 0 deletions docs/apidoc/bk-api-gateway/v3/zh/get_credential_detail.md
Original file line number Diff line number Diff line change
@@ -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) |
85 changes: 85 additions & 0 deletions docs/apidoc/bk-api-gateway/v3/zh/get_file_source_detail.md
Original file line number Diff line number Diff line change
@@ -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) |
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 功能描述

新建凭据
新建凭证

### 请求参数

Expand All @@ -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时填写 |


### 请求参数示例
Expand Down Expand Up @@ -67,4 +67,4 @@

| 字段 | 类型 |字段是否一定存在 | 描述 |
|-----------|-------|---------------|---------|
| id | string || 凭据ID |
| id | string || 凭证ID |
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/update_credential.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 功能描述

更新凭据
更新凭证

### 请求参数

Expand All @@ -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时填写 |


### 请求参数示例
Expand Down Expand Up @@ -69,4 +69,4 @@

| 字段 | 类型 |字段是否一定存在 | 描述 |
|-----------|-------|---------------|---------|
| id | string || 凭据ID |
| id | string || 凭证ID |
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/apidoc/esb/jobv3-confapis/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@

- path: /v2/jobv3/create_credential/
name: create_credential
label: 新建凭据
label: 新建凭证
label_en: Create credential
suggest_method: POST
api_type: operate
Expand All @@ -282,7 +282,7 @@

- path: /v2/jobv3/update_credential/
name: update_credential
label: 更新凭据
label: 更新凭证
label_en: Update credential
suggest_method: POST
api_type: operate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -277,7 +277,7 @@ private StepInstanceDTO buildFastFileStepInstance(String username,
return stepInstance;
}

private List<FileSourceDTO> convertFileSource(List<EsbFileSourceV3DTO> fileSources) throws ServiceException {
private List<FileSourceDTO> convertFileSource(Long appId, List<EsbFileSourceV3DTO> fileSources) throws ServiceException {
if (fileSources == null) {
return null;
}
Expand Down Expand Up @@ -318,7 +318,7 @@ private List<FileSourceDTO> convertFileSource(List<EsbFileSourceV3DTO> fileSourc
fileSourceDTO.setFileSourceId(fileSource.getFileSourceId());
} else if (StringUtils.isNotBlank(fileSourceCode)) {
try {
InternalResponse<Integer> resp = fileSourceResource.getFileSourceIdByCode(fileSourceCode);
InternalResponse<Integer> resp = fileSourceResource.getFileSourceIdByCode(appId, fileSourceCode);
if (resp != null && resp.isSuccess()) {
if (resp.getData() != null) {
fileSourceDTO.setFileSourceId(resp.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -62,4 +66,26 @@ EsbResp<EsbFileSourceSimpleInfoV3DTO> updateFileSource(
EsbCreateOrUpdateFileSourceV3Req req
);

@GetMapping("/get_file_source_detail")
EsbResp<EsbFileSourceV3DTO> 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<EsbFileSourceV3DTO> getFileSourceDetailUsingPost(
@RequestHeader(value = JobCommonHeaders.USERNAME) String username,
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode,
@RequestBody
@Validated
EsbGetFileSourceDetailV3Req req);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +41,15 @@
public interface ServiceFileSourceResource {

@ApiOperation(value = "获取文件源ID", produces = "application/json")
@GetMapping("/service/app/{appId}/fileSource/getFileSourceIdByCode/codes/{code}")
InternalResponse<Integer> 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<Integer> getFileSourceIdByCode(
@ApiParam(value = "文件源标识", required = true) @PathVariable("code") String code);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit 2783365

Please sign in to comment.