Help Center> Content Delivery Network> API Reference> API> Domain Name Configuration> Associating a Certificate with Multiple Domain Names
Updated on 2024-07-19 GMT+08:00

Associating a Certificate with Multiple Domain Names

Function

If you associate a certificate with multiple domain names, you need to set force redirect for the domain names.

Calling Method

For details, see Calling APIs.

URI

PUT /v1.0/cdn/domains/config-https-info

Table 1 Query Parameters

Parameter

Mandatory

Type

Description

enterprise_project_id

No

String

ID of the enterprise project that the domain name to be modified belongs to. This parameter is valid only when the enterprise project function is enabled. The value all indicates all projects. This parameter is mandatory when you use an IAM user to call this API.

Obtain the enterprise project ID by calling the ListEnterpriseProject API of Enterprise Project Management Service (EPS).

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

https

No

UpdateDomainMultiCertificatesRequestBodyContent object

HTTPS settings.

Table 4 UpdateDomainMultiCertificatesRequestBodyContent

Parameter

Mandatory

Type

Description

domain_name

Yes

String

Domain name list. Domain names are separated by commas (,). Up to 50 domain names are supported.

https_switch

Yes

Integer

HTTPS status. Possible values: 0 (disabled) and 1 (enabled). If https_switch is set to 1, the certificate parameters must be specified.

access_origin_way

No

Integer

Origin protocol. Possible values: 1 (same as user requests), 2 (HTTP, default value), and 3 (HTTPS).

force_redirect_https

No

Integer

Whether force HTTPS is enabled. Possible values: 0 (disabled, default value) and 1 (enabled). (This parameter is about to go offline. You are advised to use force_redirect_config.)

force_redirect_config

No

ForceRedirect object

Force redirect.

http2

No

Integer

HTTP/2 status. Possible values: 0 (disabled, default value) and 1 (enabled).

cert_name

No

String

Certificate name. This parameter is mandatory when a certificate is configured. The value contains 3 to 64 characters.

certificate

No

String

SSL certificate content used by HTTPS. Only the PEM format is supported. This parameter is mandatory only when a certificate is configured for the first time.

private_key

No

String

SSL certificate key used by HTTPS. Only the PEM format is supported. This parameter is mandatory only when a certificate is configured for the first time.

certificate_type

No

Integer

Certificate type. Default value: 0 (your own certificate).

Table 5 ForceRedirect

Parameter

Mandatory

Type

Description

switch

Yes

Integer

Force redirect status. 1 enabled. 0: disabled.

redirect_type

No

String

Protocol to which requests are forcibly redirected. Possible values: http and https.

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

https

UpdateDomainMultiCertificatesResponseBodyContent object

HTTPS settings.

Table 7 UpdateDomainMultiCertificatesResponseBodyContent

Parameter

Type

Description

domain_name

String

Domain name list.

https_switch

Integer

HTTPS status. Possible values: 0 (disabled) and 1 (enabled). If you set this parameter to 1, a certificate must be configured.

access_origin_way

Integer

Origin protocol. Possible values: 1 (same as user requests), 2 (HTTP, default value), and 3 (HTTPS, only on Huawei nodes).

force_redirect_https

Integer

Force HTTPS status. Possible values: 0 (disabled) and 1 (enabled).

force_redirect_config

ForceRedirect object

Force redirect.

http2

Integer

HTTP/2 status. Possible values: 0 (disabled) and 1 (enabled).

cert_name

String

Certificate name.

certificate

String

Certificate content.

certificate_type

Integer

Certificate type. Value: 0 (your own certificate).

expiration_time

Long

Certificate expiration time.

Table 8 ForceRedirect

Parameter

Type

Description

switch

Integer

Force redirect status. 1 enabled. 0: disabled.

redirect_type

String

Protocol to which requests are forcibly redirected. Possible values: http and https.

Example Requests

{
  "https" : {
    "domain_name" : "example1.com",
    "access_origin_way" : 2,
    "http2" : 0,
    "certificate_type" : 0,
    "force_redirect_config" : {
      "redirect_type" : "https",
      "switch" : 1
    },
    "https_switch" : 1,
    "cert_name" : "cdn_test_cert",
    "certificate" : "-----BEGIN CERTIFICATE----------END CERTIFICATE-----",
    "private_key" : "-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----"
  }
}

Example Responses

Status code: 200

OK

{
  "https" : {
    "domain_name" : "example1.com",
    "https_switch" : 1,
    "access_origin_way" : 2,
    "force_redirect_https" : 1,
    "force_redirect_config" : {
      "redirect_type" : "https",
      "switch" : 1
    },
    "http2" : 0,
    "expiration_time" : 1925791912000,
    "cert_name" : "cdn_test_cert",
    "certificate" : "-----BEGIN CERTIFICATE----------END CERTIFICATE-----",
    "certificate_type" : 0
  }
}

SDK Sample Code

The SDK sample code is as follows.

 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
55
56
57
58
59
60
61
62
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
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.cdn.v2.region.CdnRegion;
import com.huaweicloud.sdk.cdn.v2.*;
import com.huaweicloud.sdk.cdn.v2.model.*;


public class UpdateDomainMultiCertificatesSolution {

    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 GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        CdnClient client = CdnClient.newBuilder()
                .withCredential(auth)
                .withRegion(CdnRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateDomainMultiCertificatesRequest request = new UpdateDomainMultiCertificatesRequest();
        request.withEnterpriseProjectId("<enterprise_project_id>");
        UpdateDomainMultiCertificatesRequestBody body = new UpdateDomainMultiCertificatesRequestBody();
        ForceRedirect forceRedirectConfigHttps = new ForceRedirect();
        forceRedirectConfigHttps.withSwitch(1)
            .withRedirectType("https");
        UpdateDomainMultiCertificatesRequestBodyContent httpsbody = new UpdateDomainMultiCertificatesRequestBodyContent();
        httpsbody.withDomainName("example1.com")
            .withHttpsSwitch(1)
            .withAccessOriginWay(2)
            .withForceRedirectConfig(forceRedirectConfigHttps)
            .withHttp2(0)
            .withCertName("cdn_test_cert")
            .withCertificate("-----BEGIN CERTIFICATE----------END CERTIFICATE-----")
            .withPrivateKey("-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----")
            .withCertificateType(0);
        body.withHttps(httpsbody);
        request.withBody(body);
        try {
            UpdateDomainMultiCertificatesResponse response = client.updateDomainMultiCertificates(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
40
41
42
43
44
45
46
47
48
49
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcdn.v2.region.cdn_region import CdnRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcdn.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"]

    credentials = GlobalCredentials(ak, sk)

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

    try:
        request = UpdateDomainMultiCertificatesRequest()
        request.enterprise_project_id = "<enterprise_project_id>"
        forceRedirectConfigHttps = ForceRedirect(
            switch=1,
            redirect_type="https"
        )
        httpsbody = UpdateDomainMultiCertificatesRequestBodyContent(
            domain_name="example1.com",
            https_switch=1,
            access_origin_way=2,
            force_redirect_config=forceRedirectConfigHttps,
            http2=0,
            cert_name="cdn_test_cert",
            certificate="-----BEGIN CERTIFICATE----------END CERTIFICATE-----",
            private_key="-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----",
            certificate_type=0
        )
        request.body = UpdateDomainMultiCertificatesRequestBody(
            https=httpsbody
        )
        response = client.update_domain_multi_certificates(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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    cdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/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")

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

    client := cdn.NewCdnClient(
        cdn.CdnClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateDomainMultiCertificatesRequest{}
	enterpriseProjectIdRequest:= "<enterprise_project_id>"
	request.EnterpriseProjectId = &enterpriseProjectIdRequest
	redirectTypeForceRedirectConfig:= "https"
	forceRedirectConfigHttps := &model.ForceRedirect{
		Switch: int32(1),
		RedirectType: &redirectTypeForceRedirectConfig,
	}
	accessOriginWayHttps:= int32(2)
	http2Https:= int32(0)
	certNameHttps:= "cdn_test_cert"
	certificateHttps:= "-----BEGIN CERTIFICATE----------END CERTIFICATE-----"
	privateKeyHttps:= "-----BEGIN RSA PRIVATE KEY---------END RSA PRIVATE KEY-----"
	certificateTypeHttps:= int32(0)
	httpsbody := &model.UpdateDomainMultiCertificatesRequestBodyContent{
		DomainName: "example1.com",
		HttpsSwitch: int32(1),
		AccessOriginWay: &accessOriginWayHttps,
		ForceRedirectConfig: forceRedirectConfigHttps,
		Http2: &http2Https,
		CertName: &certNameHttps,
		Certificate: &certificateHttps,
		PrivateKey: &privateKeyHttps,
		CertificateType: &certificateTypeHttps,
	}
	request.Body = &model.UpdateDomainMultiCertificatesRequestBody{
		Https: httpsbody,
	}
	response, err := client.UpdateDomainMultiCertificates(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

OK

Error Codes

See Error Codes.