Creating a script
Function
This API is used to create custom job scripts.
-
A script with a tag attribute is a high-risk script. When creating such script, you do not need to perform secondary verification on whether it is high-risk.
-
Tenants are isolated. For scripts created through the northbound interface, if the reviewer field is not set, review is not required by default.
Constraints
Script name: The script name must be unique under the same tenant. The value can contain a maximum of 64 characters, including letters, digits, and underscores (_).
-
The name of a single parameter contains 64 characters, including only letters, digits, and underscores (_).
-
The value of a single parameter can contain a maximum of 1024 characters. The regular expression is ^((?!.{2,})[a-zA-Z0-9_-/.\x20?:",=+@[{]}])$.
-
The maximum size of logs generated by the script can only be 1 MB.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, the following identity policy-based permissions are required.
Action
Access Level
Resource Type (*: required)
Condition Key
Alias
Dependencies
coc:document:create
Write
document *
-
-
-
URI
POST /v1/job/scripts
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
X-Auth-Token |
Yes |
String |
Definition: Tenant token. Constraints: Tenant token obtained from IAM. Value range: N/A. Default value: N/A. |
|
x-project-id |
No |
String |
Definition: The project ID. Constraints: Project ID corresponding to the region. Value range: N/A. Default value: N/A. |
|
x-user-profile |
No |
String |
Definition: IAM 5.0 user information. Constraints: N/A. Value range: N/A. Default value: N/A. |
|
X-Language |
No |
String |
Definition: Internationalization tag. zh-cn indicates Chinese, and en-us or no value indicates English. Constraints: zh-cn indicates Chinese, and en-us or no value indicates English. Value range: zh-cn and en-us Default value: N/A. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
name |
Yes |
String |
Definition: Script name. Constraints: Only letters, digits, and underscores (_) are allowed. Value range: N/A. Default value: N/A. |
|
properties |
Yes |
ScriptPropertiesModel object |
Definition: Script attribute. Constraints: N/A. Value range: N/A. Default value: N/A. |
|
description |
Yes |
String |
Definition: Script description. Constraints: N/A. Value range: N/A. Default value: N/A. |
|
type |
Yes |
String |
Definition: Script type. Suffixes of various script types: Constraints: The value can only be SHELL, PYTHON, or BAT. Value range: SHELL, PYTHON, or BAT. Default value: N/A. |
|
content |
Yes |
String |
Definition: Script content. Constraints: Script content of the corresponding language. Value range: N/A. Default value: N/A. |
|
enterprise_project_id |
No |
String |
Definition: Enterprise project ID. The preset value is 0. Constraints: Actual enterprise project ID. Value range: N/A. Default value: N/A. |
|
script_params |
No |
Array of ScriptParamDefine objects |
Definition: Input parameters of the script. Constraints: Number of parameters: 0–20 Value range: N/A. Default value: N/A. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
risk_level |
Yes |
String |
Definition: Risk level. Constraints: Value range: LOW, MEDIUM, or HIGH. Default value: N/A. |
|
version |
Yes |
String |
Definition: Script version. Constraints: Format: 1.0.0 Value range: N/A. Default value: N/A. |
|
reviewers |
No |
Array of ReviewerInfo objects |
Definition: Reviewer. If this parameter is not specified, review is not required. Constraints: N/A. Value range: N/A. Default value: N/A. |
|
protocol |
No |
String |
Definition: Review message notification protocol, which is used to notify the reviewer. Constraints: EMAIL, DING_TALK, WE_LINK, WECHAT, CALLNOTIFY, and NOT_TO_NOTIFY. Value range: DEFAULT, SMS, EMAIL, DING_TALK, WE_LINK, WECHAT, CALLNOTIFY, or NOT_TO_NOTIFY. Default value: N/A. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
reviewer_name |
Yes |
String |
Definition: Reviewer name (IAM username). Constraints: IAM username. Value range: N/A. Default value: N/A. |
|
reviewer_id |
Yes |
String |
Definition: Reviewer ID (IAM user ID). Constraints: IAM user ID. Value range: N/A. Default value: N/A. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
param_name |
Yes |
String |
Definition: Parameter name. Constraints: The parameter name can contain only letters, digits, and underscores (_). Value range: N/A. Default value: N/A. |
|
param_value |
Yes |
String |
Definition: Parameter value. Constraints: The parameter value contains 1 to 4096 characters. The value can contain uppercase letters, lowercase letters, digits, and special characters (_-/.*?:",=+@#[{]}). Consecutive periods (.) are not allowed. Value range: N/A. Default value: N/A. |
|
param_description |
Yes |
String |
Definition: Parameter description. Constraints: N/A. Value range: N/A. Default value: N/A. |
|
param_order |
Yes |
Integer |
Definition: Parameter sequence. This parameter has been discarded and does not take effect when it is configured. Constraints: N/A. Value range: N/A. Default value: N/A. |
|
sensitive |
Yes |
Boolean |
Definition: Whether a parameter is sensitive. Constraints: The value can be true or false. Value range: The value can be true or false. Default value: N/A. |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
data |
String |
Definition: Script ID returned by the system after a script is created. Value range: N/A. |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Definition: Error code. Value range: See the error code section. |
|
error_msg |
String |
Definition: Error description. Value range: See the error code section. |
Example Requests
Create a SHELL script and notify the reviewer via WeChat.
POST https://{Endpoint}/v1/job/scripts
{
"type" : "SHELL",
"content" : "echo ${value}",
"name" : "09101112",
"description" : "Instance script",
"properties" : {
"risk_level" : "HIGH",
"version" : "1.0.0",
"reviewers" : [ {
"reviewer_name" : "test",
"reviewer_id" : "7a8513cd87b7448283xxxxxxxxx"
} ],
"protocol" : "WECHAT"
},
"script_params" : [ {
"param_name" : "a",
"param_value" : "string",
"param_description" : "string",
"param_order" : 1,
"sensitive" : true
} ]
}
Example Responses
Status code: 200
The UUID of the created script is returned.
For more status codes, see Status Codes.
{
"data" : "SC2023102521xxxxxxxxxx"
}
Status code: 400
The contained error information is returned.
For more status codes, see Status Codes.
{
"error_code" : "COC.00040701",
"error_msg" : "script_params size must be between 0 and 50"
}
Status Codes
|
Status Code |
Description |
|---|---|
|
200 |
The UUID of the created script is returned. For more status codes, see Status Codes. |
|
400 |
The contained error information is returned. For more status codes, see Status Codes. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot