
# 获取制品版本详情 - ShowInstanceArtifact
#### 功能介绍
获取制品版本详情
#### 接口约束
无
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-swr2/swr_02_0002.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-swr2/swr_02_0131.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                        | 访问级别 | 资源类型（\*为必须）   | 条件键                                                                                                                                                                                                                                                                                                                 | 别名 | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | swr:repository:getArtifact | Read | repository \* | - g:ResourceTag/\<tag-key\>   - g:EnterpriseProjectId    | -  | -      |
     
  
 
#### URI
GET /v2/{project_id}/instances/{instance_id}/namespaces/{namespace_name}/repositories/{repository_name}/artifacts/{reference}
表1路径参数 
| 参数              | 是否必选 | 参数类型   | 描述                                                                                                              |
|:---|:---|:---|:---|
| project_id      | 是    | String | 项目ID                                                                                                            |
| instance_id     | 是    | String | 企业仓库实例ID                                                                                                        |
| namespace_name  | 是    | String | 命名空间名称                                                                                                          |
| repository_name | 是    | String | 制品仓库名称, 如果您的镜像名称repository_name参数中有/，请先把 / 替换成 %2F 再进行请求。注意：使用curl命令请求，需要把 / 替换成 %252F(即 %2F 的 % 被编码为 %25)再次请求。 |
| reference       | 是    | String | 制品摘要                                                                                                            |
   
表2Query参数 
| 参数                 | 是否必选 | 参数类型    | 描述         |
|:---|:---|:---|:---|
| with_scan_overview | 否    | Boolean | 是否返回制品扫描摘要 |
   
#### 请求参数
表3请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                       |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 用户Token。 通过调用IAM服务获取用户Token接口获取（响应消息头中X-Subject-Token的值）。 |
   
#### 响应参数
**状态码：200**
表4响应Body参数 
| 参数                  | 参数类型                                                               | 描述                                                                                                                                                                                                                                     |
|:---|:---|:---|
| digest              | String                                                             | 制品摘要                                                                                                                                                                                                                                   |
| id                  | Integer                                                            | 制品ID                                                                                                                                                                                                                                   |
| repository_id       | Integer                                                            | 仓库ID                                                                                                                                                                                                                                   |
| repository_name     | String                                                             | 仓库名称                                                                                                                                                                                                                                   |
| type                | String                                                             | 制品类型 取值范围： - IMAGE：镜像制品    |
| namespace_id        | Integer                                                            | 命名空间ID                                                                                                                                                                                                                                 |
| media_type          | String                                                             | 制品MIME类型                                                                                                                                                                                                                               |
| manifest_media_type | String                                                             | 制品元数据MIME类型                                                                                                                                                                                                                            |
| pull_time           | String                                                             | 最近一次拉取时间                                                                                                                                                                                                                               |
| push_time           | String                                                             | 最近一次上传时间                                                                                                                                                                                                                               |
| size                | Integer                                                            | 制品大小，单位：Byte                                                                                                                                                                                                                           |
| tags                | Array of [ArtifactTag] objects | 制品版本的Tag列表                                                                                                                                                                                                                             |
| extra_attrs         | Map\<String,Object\>                                               | 制品的一些额外属性，比如制品的构建时间(created)、支持的操作系统(os)、支持CPU架构(architecture)等信息。                                                                                                                                                                     |
| references          | Array of [Reference] objects     | 当制品为多架构镜像索引时，显示其引用的所有子制品。                                                                                                                                                                                                              |
| scan_overview       | [ScanOverview] object         | 制品扫描摘要                                                                                                                                                                                                                                 |
   
 表5ArtifactTag 
| 参数            | 参数类型   | 描述       |
|:---|:---|:---|
| id            | Long   | Tag ID   |
| repository_id | Long   | 制品仓库ID   |
| artifact_id   | Long   | 制品版本ID   |
| name          | String | tag名称    |
| push_time     | String | tag的上传时间 |
| pull_time     | String | tag的下载时间 |
   
 表6Reference 
| 参数           | 参数类型                                               | 描述          |
|:---|:---|:---|
| parent_id    | Long                                               | 父制品的ID。     |
| child_id     | Long                                               | 子制品的ID。     |
| child_digest | String                                             | 子制品的digest。 |
| platform     | [Platform] object | 子制品的平台信息。   |
   
 表7Platform 
| 参数           | 参数类型             | 描述                                                         |
|:---|:---|:---|
| architecture | String           | 制品适用的CPU架构。                                                |
| os           | String           | 制品适用的操作系统。                                                 |
| os.version   | String           | 制品适用的操作系统版本。                                               |
| os.features  | Array of strings | 制品适用的操作系统特性。                                               |
| variant      | String           | 同一系列 CPU 下的细分型号，例如 Intel i5-13400、i5-13600 属于同代不同 variant。 |
   
 表8ScanOverview 
| 参数       | 参数类型                                                                            | 描述                                                                                  |
|:---|:---|:---|
| {自定义key} | Map\<String,[NativeReportSummary]\> | 制品扫描摘要,支持制品扫描报告类型为application/vnd.security.vulnerability.report; version=1.1的制品扫描摘要 |
   
 表9NativeReportSummary 
| 参数               | 参数类型                                                                       | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
|:---|:---|:---|
| report_id        | String                                                                     | 报告ID                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| scan_status      | String                                                                     | 制品扫描状态 取值范围： - Pending：扫描等待中   - Running：扫描中   - Error：扫描失败   - Success：扫描成功    |
| severity         | String                                                                     | 制品扫描报告的总体严重程度，None(无评分), Low(低危), Medium(中危), High(高危), Critical(严重), Security(安全)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| duration         | Integer                                                                    | 生成报告所花费的秒数时间                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| summary          | [VulnerabilitySummary] object | 漏洞信息摘要                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| start_time       | String                                                                     | 报告生成的开始时间                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| end_time         | String                                                                     | 报告生成的结束时间                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| complete_percent | Integer                                                                    | 扫描的完成百分比，该值介于0和100之间                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| scanner          | [Scanner] object                           | 扫描器的信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
   
 表10VulnerabilitySummary 
| 参数      | 参数类型                  | 描述        |
|:---|:---|:---|
| total   | Integer               | 发现的漏洞总数   |
| fixable | Integer               | 可修复漏洞的数量  |
| summary | Map\<String,Integer\> | 不同级别的漏洞数量 |
   
 表11Scanner 
| 参数      | 参数类型   | 描述      |
|:---|:---|:---|
| name    | String | 扫描器的名称  |
| vendor  | String | 扫描器的提供商 |
| version | String | 扫描器的版本号 |
   
**状态码：400**
表12响应Body参数 
| 参数                            | 参数类型   | 描述                                                           |
|:---|:---|:---|
| error_code                    | String | 错误码                                                          |
| error_msg                     | String | 错误信息                                                         |
| encoded_authorization_message | String | 加密后的详细拒绝原因，用户可以自行调用STS服务的decode-authorization-message接口进行解密。 |
   
**状态码：401**
表13响应Body参数 
| 参数                            | 参数类型   | 描述                                                           |
|:---|:---|:---|
| error_code                    | String | 错误码                                                          |
| error_msg                     | String | 错误信息                                                         |
| encoded_authorization_message | String | 加密后的详细拒绝原因，用户可以自行调用STS服务的decode-authorization-message接口进行解密。 |
   
**状态码：403**
表14响应Body参数 
| 参数                            | 参数类型   | 描述                                                           |
|:---|:---|:---|
| error_code                    | String | 错误码                                                          |
| error_msg                     | String | 错误信息                                                         |
| encoded_authorization_message | String | 加密后的详细拒绝原因，用户可以自行调用STS服务的decode-authorization-message接口进行解密。 |
   
**状态码：404**
表15响应Body参数 
| 参数                            | 参数类型   | 描述                                                           |
|:---|:---|:---|
| error_code                    | String | 错误码                                                          |
| error_msg                     | String | 错误信息                                                         |
| encoded_authorization_message | String | 加密后的详细拒绝原因，用户可以自行调用STS服务的decode-authorization-message接口进行解密。 |
   
**状态码：500**
表16响应Body参数 
| 参数                            | 参数类型   | 描述                                                           |
|:---|:---|:---|
| error_code                    | String | 错误码                                                          |
| error_msg                     | String | 错误信息                                                         |
| encoded_authorization_message | String | 加密后的详细拒绝原因，用户可以自行调用STS服务的decode-authorization-message接口进行解密。 |
   
#### 请求示例
```
GET https://{endpoint}/v2/{project_id}/instances/{instance_id}/namespaces/{namespace_name}/repositories/{repository_name}/artifacts/{reference}
```
#### 响应示例
**状态码：200**
查询制品版本详情成功
```
{
  "digest" : "sha256:d086845138397686ea70e11f069031370534dcc1617d02ae9b501504f91af50a",
  "id" : 448,
  "manifest_media_type" : "application/vnd.docker.distribution.manifest.v2+json",
  "media_type" : "application/vnd.docker.container.image.v1+json",
  "pull_time" : "2022-11-12T00:53:48.696Z",
  "push_time" : "2022-11-03T10:20:23.753Z",
  "repository_id" : 49,
  "size" : 127999644,
  "tags" : [ {
    "artifact_id" : 448,
    "id" : 352,
    "name" : "v1.0.3.test1",
    "pull_time" : "2022-11-12T00:53:48.696Z",
    "push_time" : "2022-11-03T10:20:23.870Z",
    "repository_id" : 49
  } ],
  "type" : "IMAGE",
  "repository_name" : "namespace/repo-name",
  "namespace_id" : 1,
  "scan_overview" : {
    "application/vnd.security.vulnerability.report; version=1.1" : {
      "report_id" : "12345",
      "scan_status" : "Success",
      "severity" : "High",
      "duration" : 10,
      "summary" : {
        "total" : 5,
        "fixable" : 3
      }
    }
  }
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  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.swr.v2.region.SwrRegion;
  import com.huaweicloud.sdk.swr.v2.*;
  import com.huaweicloud.sdk.swr.v2.model.*;
  public class ShowInstanceArtifactSolution {
      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);
          SwrClient client = SwrClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(SwrRegion.valueOf("<YOUR REGION>"))
                  .build();
          ShowInstanceArtifactRequest request = new ShowInstanceArtifactRequest();
          request.withInstanceId("{instance_id}");
          request.withNamespaceName("{namespace_name}");
          request.withRepositoryName("{repository_name}");
          request.withReference("{reference}");
          try {
              ShowInstanceArtifactResponse response = client.showInstanceArtifact(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());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkswr.v2.region.swr_region import SwrRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkswr.v2 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 = SwrClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(SwrRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ShowInstanceArtifactRequest()
          request.instance_id = "{instance_id}"
          request.namespace_name = "{namespace_name}"
          request.repository_name = "{repository_name}"
          request.reference = "{reference}"
          response = client.show_instance_artifact(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      swr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/swr/v2"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/swr/v2/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/swr/v2/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, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := swr.SwrClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := swr.NewSwrClient(hcClient)
      request := &model.ShowInstanceArtifactRequest{}
  request.InstanceId = "{instance_id}"
  request.NamespaceName = "{namespace_name}"
  request.RepositoryName = "{repository_name}"
  request.Reference = "{reference}"
  response, err := client.ShowInstanceArtifact(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/SWR/sdk?api=ShowInstanceArtifact)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述         |
|:---|:---|
| 200 | 查询制品版本详情成功 |
| 400 | 错误的请求      |
| 401 | 鉴权失败       |
| 403 | 禁止访问       |
| 404 | 未找到资源      |
| 500 | 内部错误       |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-swr2/ErrorCode.html)。
