Skip to content

Commit

Permalink
feat: 提供账号查询、创建、删除的APIGW接口 TencentBlueKing#2472
Browse files Browse the repository at this point in the history
接口实现
  • Loading branch information
jsonwan committed Oct 12, 2023
1 parent f349843 commit 089672a
Show file tree
Hide file tree
Showing 17 changed files with 451 additions and 20 deletions.
8 changes: 2 additions & 6 deletions docs/apidoc/bk-api-gateway/v3/zh/delete_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| Accept | string || 固定值。application/json|
| Content-Type | string || 固定值。application/json|

#### Body参数
#### Query参数

| 字段 | 类型 | 必选 | 描述 |
|---------------|------------|--------|------------|
Expand All @@ -26,11 +26,7 @@

- DELETE
```json
{
"bk_scope_type": "biz",
"bk_scope_id": "1",
"id": 70
}
/api/v3/delete_account?bk_scope_type=biz&bk_scope_id=1&id=70
```

### 返回结果示例
Expand Down
2 changes: 2 additions & 0 deletions docs/apidoc/bk-api-gateway/v3/zh/get_account_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"category": 1,
"type": 1,
"os": "Linux",
"can_use": true,
"creator": "admin",
"bk_scope_type": "biz",
"bk_scope_id": "1",
Expand Down Expand Up @@ -94,6 +95,7 @@
| type | int | 账号类型(1:Linux,2:Windows,9:MySQL,10:Oracle,11:DB2)|
| db_system_account_id | long | 账号用途为DB账号时该字段生效,表示DB账号对应的系统账号ID |
| os | string | 账号用途为系统账号时该字段生效,账号对应的OS |
| can_use | bool | 是否有使用该账号的权限 |
| creator | string | 创建人 |
| create_time | long | 创建时间Unix时间戳(ms) |
| last_modify_user | string | 最近一次修改人 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ validation.constraints.InvalidFileUploadSettingAmount.message=文件大小只能
validation.constraints.InvalidPort.message=端口号只能为1-65535之间的整数
validation.constraints.NotContainSpecialChar.message=不可包含 \\|/:*<>"? 特殊字符
validation.constraints.NotBlankField.message=不能为空
validation.constraints.AccountId_empty.message=账号ID不能为空
validation.constraints.AccountName_empty.message=账号名称[account]不能为空
validation.constraints.AccountType_empty.message=账号类型[type]不能为空
validation.constraints.AccountCategory_empty.message=账号用途[category]不能为空
validation.constraints.AccountPassword_tooLong.message=账号密码[password]不能超过255字符
validation.constraints.AccountAlias_tooLong.message=账号别名[alias]不能超过255字符
validation.constraints.AccountDescription_tooLong.message=账号描述[description]不能超过1024字符
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ validation.constraints.EmptyDynamicGroupId.message=DynamicGroup ID cannot be emp
validation.constraints.InvalidFileUploadSettingAmount.message=File size must be a positive float
validation.constraints.InvalidPort.message=Port must be a integer which is between 1 and 65535
validation.constraints.NotContainSpecialChar.message=Cannot contain special char, such as \\|/:*<>"?
validation.constraints.AccountId_empty.message=Account id cannot be empty
validation.constraints.AccountName_empty.message=Account name (account) cannot be empty
validation.constraints.AccountType_empty.message=Account type cannot be empty
validation.constraints.AccountCategory_empty.message=Account category cannot be empty
validation.constraints.AccountPassword_tooLong.message=Account password length cannot be larger than 255
validation.constraints.AccountAlias_tooLong.message=Account alias length cannot be larger than 255
validation.constraints.AccountDescription_tooLong.message=Account description length cannot be larger than 1024
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ validation.constraints.EmptyDynamicGroupId.message=DynamicGroup ID cannot be emp
validation.constraints.InvalidFileUploadSettingAmount.message=File size must be a positive float
validation.constraints.InvalidPort.message=Port must be a integer which is between 1 and 65535
validation.constraints.NotContainSpecialChar.message=Cannot contain special char, such as \\|/:*<>"?
validation.constraints.AccountId_empty.message=Account id cannot be empty
validation.constraints.AccountName_empty.message=Account name (account) cannot be empty
validation.constraints.AccountType_empty.message=Account type cannot be empty
validation.constraints.AccountCategory_empty.message=Account category cannot be empty
validation.constraints.AccountPassword_tooLong.message=Account password length cannot be larger than 255
validation.constraints.AccountAlias_tooLong.message=Account alias length cannot be larger than 255
validation.constraints.AccountDescription_tooLong.message=Account description length cannot be larger than 1024
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ validation.constraints.EmptyDynamicGroupId.message=动态分组 ID 不可为空
validation.constraints.InvalidFileUploadSettingAmount.message=文件大小只能为大于0的浮点数
validation.constraints.InvalidPort.message=端口号只能为1-65535之间的整数
validation.constraints.NotContainSpecialChar.message=不可包含 \\|/:*<>"? 特殊字符
validation.constraints.AccountId_empty.message=账号ID不能为空
validation.constraints.AccountName_empty.message=账号名称[account]不能为空
validation.constraints.AccountType_empty.message=账号类型[type]不能为空
validation.constraints.AccountCategory_empty.message=账号用途[category]不能为空
validation.constraints.AccountPassword_tooLong.message=账号密码[password]不能超过255字符
validation.constraints.AccountAlias_tooLong.message=账号别名[alias]不能超过255字符
validation.constraints.AccountDescription_tooLong.message=账号描述[description]不能超过1024字符
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ validation.constraints.EmptyDynamicGroupId.message=动态分组ID不可为空
validation.constraints.InvalidFileUploadSettingAmount.message=文件大小只能为大于0的浮点数
validation.constraints.InvalidPort.message=端口号只能为1-65535之间的整数
validation.constraints.NotContainSpecialChar.message=不可包含 \\|/:*<>"? 特殊字符
validation.constraints.AccountId_empty.message=账号ID不能为空
validation.constraints.AccountName_empty.message=账号名称[account]不能为空
validation.constraints.AccountType_empty.message=账号类型[type]不能为空
validation.constraints.AccountCategory_empty.message=账号用途[category]不能为空
validation.constraints.AccountPassword_tooLong.message=账号密码[password]不能超过255字符
validation.constraints.AccountAlias_tooLong.message=账号别名[alias]不能超过255字符
validation.constraints.AccountDescription_tooLong.message=账号描述[description]不能超过1024字符
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import com.tencent.bk.job.common.constant.JobCommonHeaders;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3;
import com.tencent.bk.job.manage.model.esb.v3.request.EsbCreateAccountV3Req;
import com.tencent.bk.job.manage.model.esb.v3.request.EsbDeleteAccountV3Req;
import com.tencent.bk.job.manage.model.esb.v3.request.EsbGetAccountListV3Req;
import com.tencent.bk.job.manage.model.esb.v3.response.EsbAccountV3DTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -65,4 +68,39 @@ EsbResp<EsbPageDataV3<EsbAccountV3DTO>> getAccountList(
@RequestParam(value = "start", required = false) Integer start,
@RequestParam(value = "length", required = false) Integer length);

@GetMapping("/search_account")
EsbResp<EsbPageDataV3<EsbAccountV3DTO>> searchAccount(
@RequestHeader(value = JobCommonHeaders.USERNAME) String username,
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode,
@RequestParam(value = "bk_scope_type", required = false) String scopeType,
@RequestParam(value = "bk_scope_id", required = false) String scopeId,
@RequestParam(value = "category", required = false) Integer category,
@RequestParam(value = "account", required = false) String account,
@RequestParam(value = "alias", required = false) String alias,
@RequestParam(value = "start", required = false) Integer start,
@RequestParam(value = "length", required = false) Integer length);

@PostMapping("/create_account")
EsbResp<EsbAccountV3DTO> createAccount(
@RequestBody
@Validated
EsbCreateAccountV3Req req
);

@DeleteMapping("/delete_account")
EsbResp<EsbAccountV3DTO> deleteAccount(
@RequestHeader(value = JobCommonHeaders.USERNAME) String username,
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode,
@RequestParam(value = "bk_scope_type", required = false) String scopeType,
@RequestParam(value = "bk_scope_id", required = false) String scopeId,
@RequestParam(value = "id") Long id
);

@PostMapping("/delete_account")
EsbResp<EsbAccountV3DTO> deleteAccountUsingPost(
@RequestBody
@Validated
EsbDeleteAccountV3Req req
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.esb.model.EsbAppScopeReq;
import com.tencent.bk.job.common.util.json.SkipLogFields;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

@Data
@ApiModel("账号创建请求")
@ToString(exclude = {"password"})
public class EsbCreateAccountV3Req extends EsbAppScopeReq {

/**
* 帐号名称
*/
@NotEmpty(message = "{validation.constraints.AccountName_empty.message}")
private String account;

/**
* 账号类型:1-Linux,2-Windows,9-Mysql,10-Oracle,11-DB2
*/
@NotNull(message = "{validation.constraints.AccountType_empty.message}")
private Integer type;

/**
* 账号用途:1-系统账号,2-数据库账号
*/
@NotNull(message = "{validation.constraints.AccountCategory_empty.message}")
private Integer category;

/**
* 系统账号的密码(Windows)
*/
@SkipLogFields
@Length(max = 255, message = "{validation.constraints.AccountPassword_tooLong.message}")
private String password;

/**
* 别名
*/
@Length(max = 255, message = "{validation.constraints.AccountAlias_tooLong.message}")
private String alias;

/**
* 描述
*/
@JsonProperty("description")
@Length(max = 1024, message = "{validation.constraints.AccountDescription_tooLong.message}")
private String remark;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.request;

import com.tencent.bk.job.common.esb.model.EsbAppScopeReq;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
@ApiModel("账号删除请求")
public class EsbDeleteAccountV3Req extends EsbAppScopeReq {

/**
* 帐号ID
*/
@NotNull(message = "{validation.constraints.AccountId_empty.message}")
private Long id;

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public class EsbAccountV3DTO extends EsbAppScopeDTO {
*/
@JsonProperty("description")
private String description;

/**
* 是否有权限使用
*/
@JsonProperty("can_use")
private Boolean canUse;
}
Loading

0 comments on commit 089672a

Please sign in to comment.