更新时间:2024-12-13 GMT+08:00
分享

更新证书

功能介绍

更新证书。

接口约束

如果待更新证书的域名不为空,且被监听器使用;则不允许更新该证书的域名为空,否则系统会返回409响应。

调用方法

请参见如何调用API

URI

PUT /v3/{project_id}/elb/certificates/{certificate_id}

表1 路径参数

参数

是否必选

参数类型

描述

certificate_id

String

证书ID。

project_id

String

证书所在项目ID。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:IAM鉴权Token。

表3 请求Body参数

参数

是否必选

参数类型

描述

certificate

UpdateCertificateOption object

证书对象。

表4 UpdateCertificateOption

参数

是否必选

参数类型

描述

certificate

String

证书的内容。PEM编码格式。

最大长度65536字符。

支持证书链,最大11层(含证书和证书链)。

description

String

证书的描述。

name

String

证书的名称。

private_key

String

服务器证书的私钥。PEM编码格式。

当type为client时,该参数被忽略,不影响证书的创建和使用。若传入不符合格式值,则会报错。

当type为server时,该字段必须符合格式要求,且私钥必须是有效的。

最大长度8192字符。

domain

String

服务器证书所签域名。该字段仅type为server时有效。

总长度为0-10000,由若干普通域名或泛域名组成,域名之间以","分隔,不超过100个域名。

普通域名:由若干字符串组成,字符串间以"."分隔,单个字符串长度不超过63个字符,

只能包含英文字母、数字或"-",且必须以字母或数字开头和结尾。例:www.test.com;

泛域名:在普通域名的基础上仅允许首字母为"*"。例:*.test.com

enc_certificate

String

HTTPS协议使用的SM加密证书内容。支持证书链,最大11层(含证书和证书链)。

取值:PEM编码格式。最大长度65536字符。

使用说明:仅type为server_sm时有效。

enc_private_key

String

HTTPS协议使用的SM加密证书内容。

取值:PEM编码格式。最大长度8192字符。

使用说明:仅type为server_sm时有效。

scm_certificate_id

String

scm证书id

响应参数

状态码: 200

表5 响应Body参数

参数

参数类型

描述

request_id

String

请求ID。

注:自动生成 。

certificate

CertificateInfo object

证书对象。

表6 CertificateInfo

参数

参数类型

描述

admin_state_up

Boolean

证书的管理状态。

不支持该字段,请勿使用。

certificate

String

证书的内容。PEM编码格式。

description

String

证书的描述。

domain

String

服务器证书所签域名。该字段仅type为server时有效。

总长度为0-10000,由若干普通域名或泛域名组成,域名之间以","分隔,不超过100个域名。

普通域名:由若干字符串组成,字符串间以"."分隔,单个字符串长度不超过63个字符,

只能包含英文字母、数字或"-",且必须以字母或数字开头和结尾。例:www.test.com。

泛域名:在普通域名的基础上仅允许首字母为"*"。例:*.test.com

id

String

证书ID。

name

String

证书的名称。

private_key

String

服务器证书的私钥。PEM编码格式。

当type为client时,该参数被忽略,不影响证书的创建和使用。

当type为server时,该字段必须符合格式要求,且私钥必须是有效的。

type

String

SSL证书的类型。分为服务器证书(server)、CA证书(client)。默认值:server。

created_at

String

证书创建时间。

updated_at

String

证书更新时间。

expire_time

String

证书使用截止时间。

project_id

String

证书所在项目ID。

enc_certificate

String

HTTPS协议使用的SM加密证书内容。

取值:PEM编码格式。

注意:仅在当前局点的SM加密证书特性开启才会返回该字段。

enc_private_key

String

HTTPS协议使用的SM加密证书私钥。

取值:PEM编码格式。

注意:仅在当前局点的SM加密证书特性开启才会返回该字段。

scm_certificate_id

String

SCM证书ID

common_name

String

证书绑定的主域名。

fingerprint

String

证书指纹

subject_alternative_names

Array of strings

证书绑定的所有域名。

请求示例

更新证书的名称和描述信息

PUT https://{ELB_Endponit}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/certificates/233a325e5e3e4ce8beeb320aa714cc12

{
  "certificate" : {
    "name" : "My Certificate",
    "description" : "Update my Certificate."
  }
}

响应示例

状态码: 200

操作正常返回。

{
  "certificate" : {
    "private_key" : "-----BEGIN PRIVATE KEY-----MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDQVAbOLe5xNf4M253Wn9vhdUzojetjv4J+B7kYwsMhRcgdcJ8KCnX1nfzTvI2ksXlTQ2o9BkpStnPetB4s32ZiJRMlk+61iUUMNsHwK2WBX57JT3JgmyVbH8GbmRY0+H3sH1i72luna7rMMD30gLh6QoP3cq7PGWcuZKV7hjd1tjCTQukwMv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ASUXHSW4fptBnUxACYocdDxtY4VhafI7FPMdvGl8ioYbvlHFh+X0Xs9r1S8yeWnHoXMb6eXWmYKMJrAoveLa+2cFm1Agf7nLhA4R4lqm9IpV6SKegDUkR4fxp9pPyodZPqBLLAoGBAJkD4wHW54Pwd4Ctfk9ojHjWB7pQlUYpTZO9dm+4fpCMn9Okf43AE2yAOaAP94GdzdDJkxfciXKcsYr9IIukfaoXgjKR7p1zERiWZuFF63SB4aiyX1H7IX0MwHDZQO38a5gZaOm/BUlGKMWXzuEd3fy+1rCUwzOp9LSjtJYf4ege-----END PRIVATE KEY-----",
    "description" : "Update my Certificate.",
    "domain" : null,
    "created_at" : "2019-03-31T22:23:51Z",
    "expire_time" : "2045-11-17T13:25:47Z",
    "id" : "233a325e5e3e4ce8beeb320aa714cc12",
    "name" : "My Certificate",
    "certificate" : "-----BEGIN CERTIFICATE-----MIIC4TCCAcmgAwIBAgICEREwDQYJKoZIhvcNAQELBQAwFzEVMBMGA1UEAxMMTXlDb21wYW55IENBMB4XDTE4MDcwMjEzMjU0N1oXDTQ1MTExNzEzMjU0N1owFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0FQGzi3ucTX+DNud1p/b4XVM6I3rY7+Cfge5GMLDIUXIHXCfCgp19Z3807yNpLF5U0NqPQZKUrZz3rQeLN9mYiUTJZPutYlFDDbB8CtlgV+eyU9yYJslWx/Bm5kWNPh97B9Yu9pbp2u6zDA99IC4ekKD93KuzxlnLmSle4Y3dbYwk0LpMDL6lfCHKt/W7jaSIAzlsxD+QM6l7QjhWJ+kUx+UkboOISjTe7E9XmDLJR7u8LRAQylYKy4zgnv1tn/Ky09cxLKAFtgoZWQD2FAZJf9F7k1kYNwqITz3CPlLZUUn7yw3nkOOtLMI28IEv0WyYd7CMJQkS1NPJBKNOGfR/wIDAQABozowODAhBgNVHREEGjAYggpkb21haW4uY29thwQKuUvJhwR/AAABMBMGA1UdJQQMMAoGCCsGAQUFBwMBMA0GCSqGSIb3DQEBCwUAA4IBAQA8lMQJxaTey7EjXtRLSVlEAMftAQPG6jijNQuvIBQYUDauDT4W2XUZ5wAnjiOyQ83va672K1G9s8n6xlH+xwwdSNnozaKzC87vwSeZKIOdl9I5I98TGKI6OoDaezmzCwQYtHBMVQ4c7Ml8554Ft1mWSt4dMAK2rzNYjvPRLYlzp1HMnI6hkjPk4PCZwKnha0dlScati9CCt3UzXSNJOSLalKdHErH08Iqd+1BchScxCfk0xNITn1HZZGmI+vbmunok3A2lucI14rnsrcbkGYqxGikySN6B2cRLBDK4Y3wChiW6NVYtVqcx5/mZiYsGDVN+9QBd0eYUHce+77s96i3I-----END CERTIFICATE-----",
    "admin_state_up" : true,
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "updated_at" : "2019-03-31T23:26:49Z",
    "type" : "server",
    "common_name" : "www.example.com",
    "fingerprint" : "869df7fcb441c2ef3fb9329437815972eeb1ef0e",
    "subject_alternative_names" : [ "www.example.com" ]
  },
  "request_id" : "d9abea6b-98ee-4ad4-8c5d-185ded48742f"
}

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
50
51
52
53
54
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.elb.v3.region.ElbRegion;
import com.huaweicloud.sdk.elb.v3.*;
import com.huaweicloud.sdk.elb.v3.model.*;


public class UpdateCertificateSolution {

    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);

        ElbClient client = ElbClient.newBuilder()
                .withCredential(auth)
                .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateCertificateRequest request = new UpdateCertificateRequest();
        request.withCertificateId("{certificate_id}");
        UpdateCertificateRequestBody body = new UpdateCertificateRequestBody();
        UpdateCertificateOption certificatebody = new UpdateCertificateOption();
        certificatebody.withDescription("Update my Certificate.")
            .withName("My Certificate");
        body.withCertificate(certificatebody);
        request.withBody(body);
        try {
            UpdateCertificateResponse response = client.updateCertificate(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
34
35
36
37
38
39
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkelb.v3 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 = ElbClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(ElbRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateCertificateRequest()
        request.certificate_id = "{certificate_id}"
        certificatebody = UpdateCertificateOption(
            description="Update my Certificate.",
            name="My Certificate"
        )
        request.body = UpdateCertificateRequestBody(
            certificate=certificatebody
        )
        response = client.update_certificate(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
40
41
42
43
44
45
46
47
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/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 := elb.NewElbClient(
        elb.ElbClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateCertificateRequest{}
	request.CertificateId = "{certificate_id}"
	descriptionCertificate:= "Update my Certificate."
	nameCertificate:= "My Certificate"
	certificatebody := &model.UpdateCertificateOption{
		Description: &descriptionCertificate,
		Name: &nameCertificate,
	}
	request.Body = &model.UpdateCertificateRequestBody{
		Certificate: certificatebody,
	}
	response, err := client.UpdateCertificate(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

操作正常返回。

错误码

请参见错误码

相关文档