更新时间:2025-09-26 GMT+08:00
分享

创建扫描任务

功能介绍

创建扫描任务

调用方法

请参见如何调用API

URI

POST /v5/{project_id}/image/image-scan/tasks

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产。获取方式请参见获取项目ID

约束限制:

不涉及

取值范围:

字符长度1-256位

默认取值:

不涉及

表2 Query参数

参数

是否必选

参数类型

描述

enterprise_project_id

String

参数解释:

企业项目ID,用于过滤不同企业项目下的资产。获取方式请参见获取企业项目ID

如需查询所有企业项目下的资产请传参“all_granted_eps”。

约束限制:

开通企业项目功能后才需要配置企业项目ID参数。

取值范围:

字符长度1-256位

默认取值:

0,表示默认企业项目(default)。

global_image_type

String

参数解释:

镜像类型

约束限制:

不涉及

取值范围:

  • local:本地镜像。

  • registry:仓库镜像。

默认取值:

registry

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

用户Token,包含了用户的身份、权限等信息,在调用API接口时,可通过Token进行身份认证。获取方式请参见获取用户Token

约束限制:

不涉及

取值范围:

字符长度1-32768位

默认取值:

不涉及

region

String

参数解释:

区域ID,用于查询目的区域内的资产。获取方式请参见获取区域ID

约束限制:

不涉及

取值范围:

字符长度1-128位

默认取值:

不涉及

表4 请求Body参数

参数

是否必选

参数类型

描述

scan_scope

Integer

参数解释:

扫描风险类型

约束限制:

不涉及

取值范围:

  • 0:none。

  • 0x7fffffff:全部。

  • 0x000f0000:漏洞。

  • 0x0000f000:基线检查。

  • 0x00000f00:恶意文件。

  • 0x000000f0:敏感信息。

  • 0x0000000f:软件合规。

默认取值:

不涉及

rate_limit

Integer

参数解释:

扫描限速 单位:个/h

约束限制:

不涉及

取值范围:

0-1000,0表示不限制。

默认取值:

不涉及

is_all

Boolean

参数解释:

扫描全部镜像

约束限制:

不涉及

取值范围:

  • true:扫描全部镜像。

  • false:指定镜像扫描,见image_info字段。

默认取值:

不涉及

query_info

query_info object

按照查询结果扫描

image_info

Array of image_info objects

待扫描镜像

表5 query_info

参数

是否必选

参数类型

描述

local_image_type

String

参数解释:

本地镜像类型

约束限制:

不涉及

取值范围:

  • swr_image:swr镜像。

  • other_image:其他镜像。

默认取值:

不涉及

host_id

String

参数解释:

服务器ID

约束限制:

不涉及

取值范围:

字符长度0-128位。

默认取值:

不涉及

host_name

String

参数解释:

服务器名称

约束限制:

不涉及

取值范围:

字符长度0-128位。

默认取值:

不涉及

public_ip

String

参数解释:

服务器公网IP

约束限制:

不涉及

取值范围:

字符长度0-128位。

默认取值:

不涉及

private_ip

String

参数解释:

私有IP地址

约束限制:

不涉及

取值范围:

字符长度0-128位。

默认取值:

不涉及

cluster_id

String

参数解释:

集群id

约束限制:

不涉及

取值范围:

字符长度0-128位。

默认取值:

不涉及

container_id

String

参数解释:

容器id

约束限制:

不涉及

取值范围:

字符长度0-128位。

默认取值:

不涉及

container_name

String

参数解释:

容器名称

约束限制:

不涉及

取值范围:

字符长度0-128位。

默认取值:

不涉及

pod_id

String

参数解释:

pod id

约束限制:

不涉及

取值范围:

字符长度0-64位。

默认取值:

不涉及

pod_name

String

参数解释:

pod 名称

约束限制:

不涉及

取值范围:

字符长度0-512位。

默认取值:

不涉及

app_name

String

参数解释:

软件名称

约束限制:

不涉及

取值范围:

字符长度0-256位。

默认取值:

不涉及

has_vul

Boolean

参数解释:

是否存在软件漏洞

约束限制:

不涉及

取值范围:

  • true:存在软件漏洞。

  • false:不存在软件漏洞。

默认取值:

不涉及

namespace

String

参数解释:

组织名称

约束限制:

不涉及

取值范围:

字符长度0-256位。

默认取值:

不涉及

image_name

String

参数解释:

镜像名称

约束限制:

不涉及

取值范围:

字符长度0-256位。

默认取值:

不涉及

image_version

String

参数解释:

镜像版本

约束限制:

不涉及

取值范围:

字符长度0-256位。

默认取值:

不涉及

image_type

String

参数解释:

镜像类型

约束限制:

不涉及

取值范围:

  • private_image:SWR私有镜像仓库。

  • shared_image:SWR共享镜像仓库。

  • instance_image:SWR企业仓库。

  • harbor:harbor仓库。

  • jfrog:jfrog仓库。

默认取值:

不涉及

scan_status

String

参数解释:

扫描状态

约束限制:

不涉及

取值范围:

  • unscan:未扫描

  • success:扫描完成

  • scanning:扫描中

  • failed:扫描失败

  • download_failed:下载失败

  • image_oversized:镜像超大

默认取值:

不涉及

image_size

Long

参数解释:

镜像大小

约束限制:

不涉及

取值范围:

0-9223372036854775807。

默认取值:

不涉及

start_latest_update_time

Long

参数解释:

创建时间开始日期,时间单位 毫秒(ms)

约束限制:

不涉及

取值范围:

0-9223372036854775807。

默认取值:

不涉及

end_latest_update_time

Long

参数解释:

创建时间结束日期,时间单位 毫秒(ms)

约束限制:

不涉及

取值范围:

0-9223372036854775807。

默认取值:

不涉及

start_latest_scan_time

Long

参数解释:

最近一次扫描完成时间开始日期,时间单位 毫秒(ms)

约束限制:

不涉及

取值范围:

0-9223372036854775807。

默认取值:

不涉及

end_latest_scan_time

Long

参数解释:

最近一次扫描完成时间结束日期,时间单位 毫秒(ms)

约束限制:

不涉及

取值范围:

0-9223372036854775807。

默认取值:

不涉及

表6 image_info

参数

是否必选

参数类型

描述

id

Long

id

image_id

String

image id

image_digest

String

镜像digest

registry_id

String

镜像仓库ID

registry_name

String

镜像仓库名称

image_name

String

镜像名称

image_version

String

镜像版本

namespace

String

命名空间

instance_id

String

企业实例ID

instance_url

String

下载企业镜像URL

registry_type

String

参数解释:

镜像仓库类型

约束限制:

不涉及

取值范围:

  • SwrPrivate:swr私有。

  • SwrShared:swr共享。

  • SwrEnterprise:swr企业。

  • Harbor:harbor仓库。

  • Jfrog:jfrog仓库。

  • Other:其他仓库。

默认取值:

不涉及

响应参数

状态码:200

请求已成功

请求示例

响应示例

SDK代码示例

SDK代码示例如下。

 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
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.hss.v5.region.HssRegion;
import com.huaweicloud.sdk.hss.v5.*;
import com.huaweicloud.sdk.hss.v5.model.*;


public class CreateManualImageScanTaskSolution {

    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");
        String projectId = "{project_id}";

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

        HssClient client = HssClient.newBuilder()
                .withCredential(auth)
                .withRegion(HssRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateManualImageScanTaskRequest request = new CreateManualImageScanTaskRequest();
        CreateManualImageScanTaskReqInfo body = new CreateManualImageScanTaskReqInfo();
        request.withBody(body);
        try {
            CreateManualImageScanTaskResponse response = client.createManualImageScanTask(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());
        }
    }
}
 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkhss.v5.region.hss_region import HssRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkhss.v5 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 = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

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

    try:
        request = CreateManualImageScanTaskRequest()
        request.body = CreateManualImageScanTaskReqInfo(
        )
        response = client.create_manual_image_scan_task(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    hss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/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")
    projectId := "{project_id}"

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

    client := hss.NewHssClient(
        hss.HssClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateManualImageScanTaskRequest{}
	request.Body = &model.CreateManualImageScanTaskReqInfo{
	}
	response, err := client.CreateManualImageScanTask(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

请求已成功

错误码

请参见错误码

相关文档