Skip to content

Commit

Permalink
feat: 脚本开放管理类API TencentBlueKing#2318
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliaozhong committed Nov 2, 2023
1 parent 1b7d36f commit e7bedd4
Show file tree
Hide file tree
Showing 31 changed files with 1,461 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Create public script
"script_id": "4537fb49ec0840a1b91cef4179c99f9c",
"name": "public script test",
"script_language": 1,
"content": "IyEvYmluL2Jhc2gKbHM=",
"content": "#!/bin/bash\nls",
"creator": "admin",
"create_time": 1691739630000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Create Public Script Version
"script_id": "4537fb49ec0840a1b91cef4179c99f9c",
"name": "public script test",
"script_language": 1,
"content": "IyEvYmluL2Jhc2gKbHM=",
"content": "#!/bin/bash\nls",
"creator": "admin",
"create_time": 1691739630000,
"last_modify_user": "admin",
Expand Down
2 changes: 1 addition & 1 deletion docs/apidoc/esb/jobv3-confapis/apidocs/en/create_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Create Script
"script_language": 1,
"bk_scope_type": "biz",
"bk_scope_id": "2",
"content": "IyEvYmluL2Jhc2gKZGF0ZQo=",
"content": "#!/bin/bash\ndate\n",
"creator": "admin",
"create_time": 1691741073000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Create Script Version
"script_language": 1,
"bk_scope_type": "biz",
"bk_scope_id": "2",
"content": "IyEvYmluL2Jhc2gKZGF0ZQo=",
"content": "#!/bin/bash\ndate\n",
"creator": "admin",
"create_time": 1691743535000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Update public script version
"script_id": "4537fb49ec0840a1b91cef4179c99f9c",
"name": "public script test",
"script_language": 1,
"content": "IyEvYmluL2Jhc2gKbHM=",
"content": "#!/bin/bash\nls",
"creator": "admin",
"create_time": 1691739630000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Update Script Version Information
"script_language": 1,
"bk_scope_type": "biz",
"bk_scope_id": "2",
"content": "IyEvYmluL2Jhc2gKZGF0ZQo=",
"content": "#!/bin/bash\ndate\n",
"creator": "admin",
"create_time": 1691741073000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"script_id": "4537fb49ec0840a1b91cef4179c99f9c",
"name": "public script test",
"script_language": 1,
"content": "IyEvYmluL2Jhc2gKbHM=",
"content": "#!/bin/bash\nls",
"creator": "admin",
"create_time": 1691739630000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"script_id": "4537fb49ec0840a1b91cef4179c99f9c",
"name": "public script test",
"script_language": 1,
"content": "IyEvYmluL2Jhc2gKbHM=",
"content": "#!/bin/bash\nls",
"creator": "admin",
"create_time": 1691739630000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"script_language": 1,
"bk_scope_type": "biz",
"bk_scope_id": "2",
"content": "IyEvYmluL2Jhc2gKZGF0ZQo=",
"content": "#!/bin/bash\ndate\n",
"creator": "admin",
"create_time": 1691741073000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"script_language": 1,
"bk_scope_type": "biz",
"bk_scope_id": "2",
"content": "IyEvYmluL2Jhc2gKZGF0ZQo=",
"content": "#!/bin/bash\ndate\n",
"creator": "admin",
"create_time": 1691743535000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"script_id": "4537fb49ec0840a1b91cef4179c99f9c",
"name": "public script test",
"script_language": 1,
"content": "IyEvYmluL2Jhc2gKbHM=",
"content": "#!/bin/bash\nls",
"creator": "admin",
"create_time": 1691739630000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"script_language": 1,
"bk_scope_type": "biz",
"bk_scope_id": "2",
"content": "IyEvYmluL2Jhc2gKZGF0ZQo=",
"content": "#!/bin/bash\ndate\n",
"creator": "admin",
"create_time": 1691741073000,
"last_modify_user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ErrorCode {
public static final int UPLOAD_SCRIPT_FILE_NAME_EMPTY = 1243010;//上传脚本文件名为空
public static final int UPLOAD_SCRIPT_EXT_TYPE_ILLEGAL = 1243011;//上传脚本文件扩展名不合法
public static final int UPLOAD_SCRIPT_CONTENT_ILLEGAL = 1243012;//上传脚本文件脚本内容不合法
public static final int SCRIPT_VERSION_NAME_EXIST = 1243036;//脚本版本号已存在

public static final int SERVER_EMPTY = 1244001;//主机为空
public static final int SERVER_UNREGISTERED = 1244002;//主机未注册:{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ public static ResponseSpecification successResponseSpec() {
return builder.build();
}

/**
* 失败响应通用设置
*/
public static ResponseSpecification failResponseSpec() {
ResponseSpecBuilder builder = new ResponseSpecBuilder();
builder.expectStatusCode(200);
builder.expectBody("result", equalTo(false));
builder.expectBody("code", equalTo(ErrorCode.BAD_REQUEST));
return builder.build();
}

/**
* 失败响应通用设置
*/
public static ResponseSpecification failResponseSpec(Integer code) {
ResponseSpecBuilder builder = new ResponseSpecBuilder();
builder.expectStatusCode(200);
builder.expectBody("result", equalTo(false));
builder.expectBody("code", equalTo(code));
return builder.build();
}

private static Map<String, String> buildRequestHeaders(String username) {
Map<String, String> headers = new HashMap<>();
headers.put(HEADER_BK_API_JWT, buildEsbJwt(TestProps.APP_CODE, username));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import com.tencent.bk.job.api.v3.model.EsbScriptVersionDetailV3DTO;
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.EsbCreatePublicScriptV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbCreateScriptV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbDeletePublicScriptV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbDeletePublicScriptVersionV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbDeleteScriptV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbDeleteScriptVersionV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbExecuteJobV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbFastExecuteScriptV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbFastTransferFileV3Request;
Expand Down Expand Up @@ -54,6 +58,27 @@ public static EsbScriptVersionDetailV3DTO createScript() {
.getData();
}

public static EsbScriptVersionDetailV3DTO createPublicScript() {
EsbCreatePublicScriptV3Req req = new EsbCreatePublicScriptV3Req();
req.setContent(SHELL_SCRIPT_CONTENT_BASE64);
req.setDescription(TestValueGenerator.generateUniqueStrValue("shell_script_desc", 50));
req.setName(TestValueGenerator.generateUniqueStrValue("shell_script", 50));
req.setType(ScriptTypeEnum.SHELL.getValue());
req.setVersion("v1");
req.setVersionDesc("v1_desc");

return given()
.spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.CREATE_PUBLIC_SCRIPT)
.then()
.statusCode(200)
.extract()
.body()
.as(new TypeRef<EsbResp<EsbScriptVersionDetailV3DTO>>() {
})
.getData();
}

public static void deleteScript(EsbDeleteScriptV3Req req) {
given()
Expand All @@ -64,6 +89,33 @@ public static void deleteScript(EsbDeleteScriptV3Req req) {
.statusCode(200);
}

public static void deleteScriptVersion(EsbDeleteScriptVersionV3Req req) {
given()
.spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.DELETE_SCRIPT_VERSION)
.then()
.statusCode(200);
}

public static void deletePublicScript(EsbDeletePublicScriptV3Req req) {
given()
.spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.DELETE_PUBLIC_SCRIPT)
.then()
.statusCode(200);
}

public static void deletePublicScriptVersion(EsbDeletePublicScriptVersionV3Req req) {
given()
.spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.DELETE_PUBLIC_SCRIPT_VERSION)
.then()
.statusCode(200);
}


public static EsbJobExecuteV3DTO fastExecuteScriptTask() {
EsbFastExecuteScriptV3Request req = new EsbFastExecuteScriptV3Request();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@
*/
public interface APIV3Urls {
String CREATE_SCRIPT = "/api/job/v3/job-manage/create_script";
String CREATE_PUBLIC_SCRIPT = "/api/job/v3/job-manage/create_public_script";
String GET_SCRIPT_LIST = "/api/job/v3/job-manage/get_script_list";
String UPDATE_SCRIPT_BASIC = "/api/job/v3/job-manage/update_script_basic";
String UPDATE_PUBLIC_SCRIPT_BASIC = "/api/job/v3/job-manage/update_public_script_basic";
String DELETE_SCRIPT = "/api/job/v3/job-manage/delete_script";
String DELETE_PUBLIC_SCRIPT = "/api/job/v3/job-manage/delete_public_script";
String CREATE_SCRIPT_VERSION = "/api/job/v3/job-manage/create_script_version";
String CREATE_PUBLIC_SCRIPT_VERSION = "/api/job/v3/job-manage/create_public_script_version";
String GET_SCRIPT_VERSION_LIST = "/api/job/v3/job-manage/get_script_version_list";
String GET_PUBLIC_SCRIPT_VERSION_LIST = "/api/job/v3/job-manage/get_public_script_version_list";
String GET_SCRIPT_VERSION_DETAIL = "/api/job/v3/job-manage/get_script_version_detail";
String UPDATE_SCRIPT_VERSION = "/api/job/v3/job-manage/update_script_version";
String UPDATE_PUBLIC_SCRIPT_VERSION = "/api/job/v3/job-manage/update_public_script_version";
String DELETE_SCRIPT_VERSION = "/api/job/v3/job-manage/delete_script_version";
String DELETE_PUBLIC_SCRIPT_VERSION = "/api/job/v3/job-manage/delete_public_script_version";
String PUBLISH_SCRIPT_VERSION = "/api/job/v3/job-manage/publish_script_version";
String PUBLISH_PUBLIC_SCRIPT_VERSION = "/api/job/v3/job-manage/publish_public_script_version";
String DISABLE_SCRIPT_VERSION = "/api/job/v3/job-manage/disable_script_version";
String DISABLE_PUBLIC_SCRIPT_VERSION = "/api/job/v3/job-manage/disable_public_script_version";

String FAST_EXECUTE_SCRIPT = "/api/job/v3/job-execute/get_script_list";
String FAST_TRANSFER_FILE = "/api/job/v3/job-execute/get_script_list";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.tencent.bk.job.api.v3.model.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
* 创建公共脚本请求
*/
@Data
public class EsbCreatePublicScriptV3Req{
/**
* 脚本名称
*/
private String name;

/**
* 脚本描述
*/
private String description;

@JsonProperty("script_language")
private Integer type;

/**
* 脚本内容,需Base64编码
*/
private String content;

/**
* 脚本版本
*/
private String version;

/**
* 版本描述
*/
@JsonProperty("version_desc")
private String versionDesc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.tencent.bk.job.api.v3.model.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
* 创建公共脚本版本请求
*/
@Data
public class EsbCreatePublicScriptVersionV3Req {
/**
* 脚本ID
*/
@JsonProperty("script_id")
private String scriptId;

/**
* 脚本内容,需Base64编码
*/
private String content;

/**
* 脚本版本
*/
private String version;

/**
* 版本描述
*/
@JsonProperty("version_desc")
private String versionDesc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 EsbCreateScriptVersionV3Req extends EsbAppScopeReq {

/**
* 脚本ID
*/
@JsonProperty("script_id")
private String scriptId;

/**
* 脚本内容,需Base64编码
*/
private String content;

/**
* 脚本版本
*/
private String version;

/**
* 版本描述
*/
@JsonProperty("version_desc")
private String versionDesc;
}
Loading

0 comments on commit e7bedd4

Please sign in to comment.