更新时间:2024-05-14 GMT+08:00

脚本版本查询

功能介绍

该接口可查询指定脚本ID下的所有版本,返回该名称的脚本版本列表信息。

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/cms/script-version-list

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户从IAM申请到的projectid,一般为32位字符串。

最小长度:32

最大长度:32

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token。

最小长度:1

最大长度:40960

Content-Type

String

指定类型为application/json。

最小长度:1

最大长度:32

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

查询接收的参数,版本管理时,name为脚本名称(版本管理查询时name不能为空),脚本管理页面查询时,name为接收模糊查询的参数,name是null,表示查询所有默认脚本。

最小长度:0

最大长度:128

is_default

String

查询规则,如果是类型为default,则为模糊查询和脚本管理主页展示,no_default为版本管理。

最小长度:0

最大长度:16

create_by

String

创建人,默认按照创建人搜索脚本。

最小长度:1

最大长度:64

script_id

String

版本管理时需要查询的脚本id。

最小长度:1

最大长度:64

page_num

Integer

page_num为正整数。

最小值:1

最大值:100

page_size

Integer

每页显示的条数,默认值是10。

最小值:1

最大值:1000

project_id

String

项目id。

最小长度:32

最大长度:32

order_by_column

String

需要排序的字段(默认为更新时间),支持字段有name,create_time和update_time。

最小长度:1

最大长度:16

sort_order

String

排序规则(默认降序) 传入升序或降序,升序:ASC,降序:DESC。

最小长度:1

最大长度:16

enterprise_project_id

String

企业项目id,根据企业项目id搜索。

最小长度:1

最大长度:64

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

elements

Array of ScriptVersion objects

查询结果集合。

数组长度:0 - 9999999

total_elements

Integer

查询到的结果数量。

最小值:0

最大值:9999999

表5 ScriptVersion

参数

参数类型

描述

content

String

脚本内容,脚本内容不能为空

最小长度:1

最大长度:30000

create_by

String

创建人,比如为:张三

最小长度:1

最大长度:64

create_time

Long

创建时间

最小值:0

最大值:9999999999999

enterprise_project_id

String

企业项目id

最小长度:1

最大长度:64

name

String

脚本名称,支持数字,下划线,大小写字母 ,中文

最小长度:1

最大长度:64

project_id

String

租户从IAM申请到的projectid,一般为32位字符串

最小长度:32

最大长度:32

job_reference_number

Integer

脚本版本的引用次数,脚本版本被作业引用的次数。默认是0次,引用次数为非负整数,不能出现负数

最小值:0

最大值:9999999

script_id

String

脚本id,根据UUID.randomUUID生成。

最小长度:1

最大长度:64

script_language

String

脚本语言,目前支持四种,分别是:SHELL BAT PYTHON POWER_SHELL

最小长度:1

最大长度:32

status_desc

Integer

状态说明 0代表 未上线,1代表已上线 2代表已下线 3代表已禁用

最小值:0

最大值:4

update_by

String

修改人

最小长度:1

最大长度:64

update_time

Long

实体的最后更新时间戳。 注意:执行创建/修改/删除操作时,update_time将更新。

最小值:0

最大值:9999999999999

version_id

String

版本id,根据UUID.randomUUID生成。

最小长度:1

最大长度:64

version_number

String

脚本版本号,支持数字,下划线,大小写字母和小数点

最小长度:1

最大长度:64

job_reference_name

Array of ReferenceInfo objects

脚本引用的作业详情

数组长度:0 - 9999999

表6 ReferenceInfo

参数

参数类型

描述

job_id

String

作业ID。

最小长度:1

最大长度:64

job_name

String

作业名称。

最小长度:1

最大长度:64

状态码: 400

表7 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:32

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

Http返回码

最小值:1

最大值:999

状态码: 401

表8 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:32

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

Http返回码

最小值:1

最大值:999

状态码: 500

表9 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:1

最大长度:32

error_msg

String

调用失败响应信息描述。

最小长度:1

最大长度:1024

http_code

Integer

Http返回码

最小值:1

最大值:999

请求示例

查询指定script_id下脚本版本信息。

POST https://{Endpoint}/v1/{project_id}/cms/script-version-list

{
  "script_id" : "xxxxxxxxxx",
  "page_num" : 1,
  "page_size" : 10,
  "order_by_column" : "update_time",
  "sort_order" : "ASC"
}

响应示例

状态码: 200

请求响应成功,返回指定ID脚本下版本列表。

{
  "elements" : [ {
    "content" : "1",
    "create_by" : "cxxxxx",
    "create_time" : 1676892212509,
    "enterprise_project_id" : "0",
    "job_reference_name" : [ {
      "job_id" : "012b43a3xxxxx684a30b52xxxx98cbe",
      "job_name" : "onxx_cxxxxxxxx"
    } ],
    "job_reference_number" : 1,
    "name" : "xxxxx",
    "project_id" : "2axxxxxcca548xxxxe891bxxxf",
    "script_id" : "xxxxaef-dbxx-41x9-8xx2-8exxxx4e159d2",
    "script_language" : "SHELL",
    "status_desc" : 1,
    "update_by" : "cxxxxx",
    "update_time" : 1672294768193,
    "version_id" : "xxxec4xx0-5x5-4bx0-a2xx-efeexx1c559f",
    "version_number" : "1"
  } ],
  "total_elements" : 1
}

状态码: 400

BadRequest。非法请求。建议直接修改该请求,不要重试该请求。

{
  "error_code" : "AOM.31002002",
  "error_msg" : "Invalid script parameter.",
  "http_code" : 400
}

状态码: 401

Unauthorized。在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。

{
  "error_code" : "AOM.31009011",
  "error_msg" : "auth failed.",
  "http_code" : 401
}

状态码: 500

InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。

{
  "error_code" : "AOM.31002005",
  "error_msg" : "script internal server error.",
  "http_code" : 500
}

SDK代码示例

SDK代码示例如下。

查询指定script_id下脚本版本信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.aom.v1.region.AomRegion;
import com.huaweicloud.sdk.aom.v1.*;
import com.huaweicloud.sdk.aom.v1.model.*;


public class ListAllVersionByVersionIdSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        AomClient client = AomClient.newBuilder()
                .withCredential(auth)
                .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                .build();
        ListAllVersionByVersionIdRequest request = new ListAllVersionByVersionIdRequest();
        SearchScriptsRequestBody body = new SearchScriptsRequestBody();
        body.withSortOrder("ASC");
        body.withOrderByColumn("update_time");
        body.withPageSize(10);
        body.withPageNum(1);
        body.withScriptId("xxxxxxxxxx");
        request.withBody(body);
        try {
            ListAllVersionByVersionIdResponse response = client.listAllVersionByVersionId(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

查询指定script_id下脚本版本信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkaom.v1.region.aom_region import AomRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkaom.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = AomClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(AomRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListAllVersionByVersionIdRequest()
        request.body = SearchScriptsRequestBody(
            sort_order="ASC",
            order_by_column="update_time",
            page_size=10,
            page_num=1,
            script_id="xxxxxxxxxx"
        )
        response = client.list_all_version_by_version_id(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

查询指定script_id下脚本版本信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := aom.NewAomClient(
        aom.AomClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListAllVersionByVersionIdRequest{}
	pageSizeSearchScriptsRequestBody:= int32(10)
	pageNumSearchScriptsRequestBody:= int32(1)
	request.Body = &model.SearchScriptsRequestBody{
		SortOrder: "ASC",
		OrderByColumn: "update_time",
		PageSize: &pageSizeSearchScriptsRequestBody,
		PageNum: &pageNumSearchScriptsRequestBody,
		ScriptId: "xxxxxxxxxx",
	}
	response, err := client.ListAllVersionByVersionId(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求响应成功,返回指定ID脚本下版本列表。

400

BadRequest。非法请求。建议直接修改该请求,不要重试该请求。

401

Unauthorized。在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。

500

InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。

错误码

请参见错误码