IPv6Gateway
Initialization
Confirm Endpoint
Before configuring the endpoint for SDK usage, please refer to the developer guide section on IPv6 Gateway Service Domain Name to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to Region Selection Guide.
Currently supported regions are: "North China-Beijing," "South China-Guangzhou," "East China-Suzhou," "Hong Kong," "Central Finance-Wuhan," and "North China-Baoding." Corresponding details:
| Access region | Endpoint | Protocol |
|---|---|---|
| BJ | bcc.bj.baidubce.com | HTTP and HTTPS |
| GZ | bcc.gz.baidubce.com | HTTP and HTTPS |
| SU | bcc.su.baidubce.com | HTTP and HTTPS |
| HKG | bcc.hkg.baidubce.com | HTTP and HTTPS |
| FWH | bcc.fwh.baidubce.com | HTTP and HTTPS |
| BD | bcc.bd.baidubce.com | HTTP and HTTPS |
Retrieve access key
To use Baidu AI Cloud's IPv6 Gateway, you must have a valid Access Key ID (AK) and Secret Access Key (SK) for signature verification. These system-generated credentials are essential for user identification and secure interaction with the IPv6 Gateway.
Your AK/SK information can be obtained and understood through the following steps:
Register a Baidu AI Cloud account
Create IPv6 gateway client
An IPv6 Gateway client acts as the interface for IPv6 Gateway services, offering developers various methods to interact with these services.
Create a new IPv6 gateway client with AK/SK
Users can refer to the following code to create a new IPv6 gateway client to access IPv6 gateway with AK/SK:
1import (
2 "github.com/baidubce/bce-sdk-go/services/vpc"
3)
4func main() {
5 // User’s Access Key ID and Secret Access Key
6 ACCESS_KEY_ID, SECRET_ACCESS_KEY := <your-access-key-id>, <your-secret-access-key>
7 // User-specified Endpoint
8 ENDPOINT := <domain-name>
9 // Initialize an IPv6 gateway client
10 ipv6GatewayClient, err := vpc.NewClient(AK, SK, ENDPOINT)
11}
In the code above, ACCESS_KEY_ID corresponds to “Access Key ID” in the console. SECRET_ACCESS_KEY corresponds to “Access Key Secret” in the console. Refer to the Guide - How to Retrieve AKSK. The third parameter ENDPOINT is a user-specified domain name. If left empty, the default domain name will be used as the IPv6 gateway service address.
Note:
The endpointparameter must be defined with the domain name of the specified region. For example, if the service is located in Beijing, the endpoint will bebcc.bj.baidubce.com.
Create an IPv6 gateway client with STS
Request STS Token
The IPv6 Gateway provides temporary third-party access authorization through the STS (Security Token Service) mechanism. This service, offered by Baidu AI Cloud, issues temporary access credentials with customizable permissions and validity periods, allowing third parties to call Baidu AI Cloud APIs or SDKs directly to access cloud resources.
To use IPv6 gateway services via STS, users must first obtain a certification string through the STS client.
Create IPv6 gateway client with STS Token
After receiving the STS token, input it into the IPv6 gateway client to enable the creation of an IPv6 gateway client based on the STS token.
Code example
The GO SDK implements the STS service API. Below is a complete example for requesting an STS token and creating an IPv6 gateway client object:
1import (
2 "fmt"
3 "github.com/baidubce/bce-sdk-go/auth" //Import the authentication module
4 "github.com/baidubce/bce-sdk-go/services/vpc" //Import VPC service module
5 "github.com/baidubce/bce-sdk-go/services/sts" //Import the Baige service module
6)
7func main() {
8 //Create a Client object for the STS service, using the default Endpoint
9 AK, SK := <your-access-key-id>, <your-secret-access-key>
10 stsClient, err := sts.NewClient(AK, SK)
11 if err != nil {
12 fmt.Println("create sts client object :", err)
13 return
14 }
15 //Obtain a temporary authentication token with a validity period of 60 seconds and an empty ACL
16 stsObj, err := stsClient.GetSessionToken(60, "")
17 if err != nil {
18 fmt.Println("get session token failed:", err)
19 return
20 }
21 fmt.Println(" GetSessionToken result:")
22 fmt.Println(" accessKeyId:", stsObj.AccessKeyId)
23 fmt.Println(" secretAccessKey:", stsObj.SecretAccessKey)
24 fmt.Println(" sessionToken:", stsObj.SessionToken)
25 fmt.Println(" createTime:", stsObj.CreateTime)
26 fmt.Println(" expiration:", stsObj.Expiration)
27 fmt.Println(" userId:", stsObj.UserId)
28 //Create an IPv6 gateway client object using the requested temporary STS, with the default endpoint
29 ipv6GatewayClient, err := vpc.NewClient(stsObj.AccessKeyId, stsObj.SecretAccessKey, "bcc.bj.baidubce.com")
30 if err != nil {
31 fmt.Println("create ipv6Gateway client failed:", err)
32 return
33 }
34 stsCredential, err := auth.NewSessionBceCredentials(
35 stsObj.AccessKeyId,
36 stsObj.SecretAccessKey,
37 stsObj.SessionToken)
38 if err != nil {
39 fmt.Println("create sts credential object failed:", err)
40 return
41 }
42 ipv6GatewayClient.Config.Credentials = stsCredential
43}
Note: Currently, when configuring an IPv6 gateway client with STS, regardless of where the corresponding IPv6 gateway service endpoint is located, the STS endpoint must be set to http://sts.bj.baidubce.com. This default is utilized when creating an STS object in the above code.
Configure HTTPS access to IPv6 gateway
IPv6 gateway supports the HTTPS transport protocol. To use HTTPS to access IPv6 gateway services with the IPv6 gateway Go SDK, specify HTTPS in the endpoint when creating the IPv6 gateway client object.
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2 ENDPOINT := ""https://bcc.bj.baidubce.com" // Specify the use of HTTPS protocol
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4ipv6GatewayClient, _ := vpc.NewClient(AK, SK, ENDPOINT)
Configure IPv6 gateway client
If users need to configure specific parameters for the IPv6 gateway client, they can customize the configuration using the exported Config field of the IPv6 gateway client object after its creation. This allows for configuring parameters such as proxy and maximum number of connections for the client.
Use a proxy
The following code snippet enables the client to access IPv6 gateway service using a proxy:
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2 // Create an IPv6 gateway client object
3AK, SK := <your-access-key-id>, <your-secret-access-key>
4ENDPOINT := "bcc.bj.baidubce.com"
5client, _ := vpc.NewClient(AK, SK, ENDPOINT)
6 // Use the local port 8080 for the proxy
7client.Config.ProxyUrl = "127.0.0.1:8080"
Set network parameters
Users can configure network parameters using the following example code:
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4client, _ := vpc.NewClient(AK, SK, ENDPOINT)
5 // Configure to not retry, default: Back Off retry
6client.Config.Retry = bce.NewNoRetryPolicy()
7 // Configure connection timeout to 30 seconds
8client.Config.ConnectionTimeoutInMillis = 30 * 1000
Configure options for generating signature strings
1// import "github.com/baidubce/bce-sdk-go/services/vpc"
2AK, SK := <your-access-key-id>, <your-secret-access-key>
3ENDPOINT := "bcc.bj.baidubce.com"
4client, _ := vpc.NewClient(AK, SK, ENDPOINT)
5 // Configure the HTTP request header Host for signing
6headersToSign := map[string]struct{}{"Host": struct{}{}}
7client.Config.SignOption.HeadersToSign = HeadersToSign
8 // Configure the validity period of the signature to 30 seconds
9client.Config.SignOption.ExpireSeconds = 30
Parameter description
When using the GO SDK to access IPv6 gateway, the Config field of the created IPv6 gateway client object supports the following parameters, as shown in the table below:
| ConfigMap name | Types | Meaning |
|---|---|---|
| Endpoint | string | Domain name for service requests |
| ProxyUrl | string | The proxy address for client requests |
| Region | string | Region for resource requests |
| UserAgent | string | User name, HTTP request’s User-Agent header |
| Credentials | *auth.BceCredentials | Authentication object for requests, divided into regular AK/SK and STS |
| SignOption | *auth.SignOptions | Options for authentication string signing |
| Retry | RetryPolicy | Retry policy for connections |
| ConnectionTimeoutInMillis | int | Connection timeout, in milliseconds, defaulting to 20 minutes |
Description:
- The
Credentialsis created using theauth.NewBceCredentialsandauth.NewSessionBceCredentialsfunctions. The former is used by default, while the latter is used for STS certification. See "Create an IPv6 gateway client with STS" for details. - The
SignOptionfield represents options when generating a signature string, as detailed in the table below:
| Name | Types | Meaning |
|---|---|---|
| HeadersToSign | map[string]struct{} | HTTP headers used when generating the signature string |
| Timestamp | int64 | Timestamp used in the generated signature string, defaulting to the value at the time of sending request |
| ExpireSeconds | int | Validity period of the signature string |
1 Among configuration options, HeadersToSign defaults to `Host`, `Content-Type`, `Content-Length` and `Content-MD5`; TimeStamp is typically set to zero, indicating that the timestamp at the time of generating the certification string shall be used, and users generally shall not explicitly specify the value for this field; ExpireSeconds defaults to 1,800 seconds or 30 minutes.
- The
Retryfield specifies the retry policy, currently supporting two types:NoRetryPolicyandBackOffRetryPolicy. By default, the latter is used. This retry policy specifies the maximum number of retries, the maximum retry duration, and the retry base. Retries increase exponentially based on the retry base multiplied by 2 until the maximum number of retries or the maximum retry duration is reached.
IPv6 gateway management
The IPv6 gateway acts as the primary egress for a virtual private cloud to connect to the public network using IPv6. Users can purchase IPv6 public bandwidth on demand and dynamically configure IPv6 Internet egress and ingress bandwidth by setting egress-only policies and applying IP rate limits.
Create IPv6 gateway
Use the code below to create an IPv6 gateway.
Function declaration
1type CreateIPv6GatewayArgs struct {
2 ClientToken string `json:"-"`
3 Name string `json:"name"`
4 VpcId string `json:"vpcId"`
5 BandwidthInMbps int `json:"bandwidthInMbps"`
6 Billing *Billing `json:"billing"`
7}
8type CreateIPv6GatewayResult struct {
9 GatewayId string `json:"gatewayId"`
10}
11func (c *Client) CreateIPv6Gateway(args *CreateIPv6GatewayArgs) (*CreateIPv6GatewayResult, error)
Parameter Meaning
Refer to the OpenAPI documentation:https://cloud.baidu.com/doc/VPC/s/Hkkqieads
Response Value
Operation succeeded:
1{
2 "gatewayId":"gw-5af4eb65"
3}
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_create_ipv6gateway.go
Query IPv6 gateway
Use the code below to query a list of available IPv6 gateways.
Function declaration
1type ListIPv6GatewayArgs struct {
2 VpcId string `json:"vpcId"`
3}
4type ListIPv6GatewayResult struct {
5 GatewayId string `json:"gatewayId"`
6 Name string `json:"name"`
7 BandwidthInMbps int `json:"bandwidthInMbps"`
8 VpcId string `json:"vpcId"`
9 EgressOnlyRules []EgressOnlyRule `json:"egressOnlyRules"`
10 RateLimitRules []RateLimitRule `json:"rateLimitRules"`
11}
12func (c *Client) ListIPv6Gateway(args *ListIPv6GatewayArgs) (*ListIPv6GatewayResult, error)
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Dkkqigf0v
Response Value
Operation succeeded:
1{
2 "name": "test",
3 "gatewayId": "gw-5af4eb65",
4 "bandwidthInMbps": 10,
5 "vpcId": "vpc-dsi78hfsa",
6 "egressOnlyRules": [
7 {
8 "egressOnlyRuleId":"ipv6_seg-c9e3b428",
9 "cidr":"2400:da00:e003:d01::/64"
10 }
11 ],
12 "rateLimitRules":[
13 {
14 "rateLimitRuleId":"ipv6_qos-0b56ec38",
15 "ipv6Address":"240c:4082:0:100::",
16 "ingressBandwidthInMbps":5,
17 "egressBandwidthInMbps":5
18 }
19 ]
20}
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_list_ipv6gateway.go
Delete IPv6 gateway
Use the code below to remove a specific IPv6 gateway.
Function declaration
1type DeleteIPv6GatewayArgs struct {
2 ClientToken string `json:"-"`
3}
4func (c *Client) DeleteIPv6Gateway(gatewayId string, args *DeleteIPv6GatewayArgs) error
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/1kkqihc05
Response Value
Operation succeeded:
There are no special response parameters
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_delete_ipv6gateway.go
Bandwidth resizing for IPv6 gateway
Use the following interface to adjust the bandwidth size for the IPv6 gateway.
Function declaration
1type ResizeIPv6GatewayArgs struct {
2 ClientToken string `json:"-"`
3 BandwidthInMbps int `json:"bandwidthInMbps"`
4}
5func (c *Client) ResizeIPv6Gateway(gatewayId string, args *ResizeIPv6GatewayArgs) error
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/0kkqiiaaz
Response Value
Operation succeeded:
There are no special response parameters
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_resize_ipv6gateway.go
Add IPv6 egress-only policy
Use the code below to add an egress-only policy for the IPv6 gateway.
Function declaration
1type CreateIPv6GatewayEgressOnlyRuleArgs struct {
2 ClientToken string `json:"-"`
3 Cidr string `json:"cidr"`
4}
5type CreateIPv6GatewayEgressOnlyRuleResult struct {
6 EgressOnlyRuleId string `json:"egressOnlyRuleId"`
7}
8func (c *Client) CreateIPv6GatewayEgressOnlyRule(gatewayId string, args *CreateIPv6GatewayEgressOnlyRuleArgs)
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/jkkqijeky
Response Value
Operation succeeded:
1{
2 "egressOnlyRuleId":"ipv6_seg-c9e3b428"
3}
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_create_ipv6gateway_egress_only_rule.go
Query the IPv6 egress-only policy list
Use the code below to query the list of egress-only policies for the IPv6 gateway.
Function declaration
1type ListIPv6GatewayEgressOnlyRuleArgs struct {
2 Marker string
3 MaxKeys int
4}
5type ListIPv6GatewayEgressOnlyRuleResult struct {
6 Marker string `json:"marker"`
7 IsTruncated bool `json:"isTruncated"`
8 NextMarker string `json:"nextMarker"`
9 MaxKeys int `json:"maxKeys"`
10 EgressOnlyRules []EgressOnlyRule `json:"egressOnlyRules"`
11}
12func (c *Client) ListIPv6GatewayEgressOnlyRule(gatewayId string, args *ListIPv6GatewayEgressOnlyRuleArgs) (*ListIPv6GatewayEgressOnlyRuleResult, error)
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/vkkqikkey
Response Value
Operation succeeded:
1{
2 "egressOnlyRules":[
3 {
4 "egressOnlyRuleId":"ipv6_seg-c9e3b428",
5 "cidr":"2400:da00:e003:d01::/64"
6 }
7 ],
8 "marker":"ipv6_seg-c9e3b428",
9 "maxKeys":1000
10 "isTruncated":false
11}
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_list_ipv6gateway_egress_only_rule.go
Delete the IPv6 egress-only policy
Use the code below to delete an IPv6 egress-only policy.
Function declaration
1type DeleteIPv6GatewayEgressOnlyRuleArgs struct {
2 ClientToken string `json:"-"`
3}
4func (c *Client) DeleteIPv6GatewayEgressOnlyRule(gatewayId, egressOnlyRuleId string, args *DeleteIPv6GatewayEgressOnlyRuleArgs) error
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/kkkqily45
Response Value
Operation succeeded:
There are no special response parameters
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_delete_ipv6gateway_egress_only_rule.go
Create IPv6 gateway bandwidth limiting policy
Use the code below to add a bandwidth limiting policy to an IPv6 address.
Function declaration
1type CreateIPv6GatewayRateLimitRuleArgs struct {
2 ClientToken string `json:"-"`
3 IPv6Address string `json:"ipv6Address"`
4 IngressBandwidthInMbps int `json:"ingressBandwidthInMbps"`
5 EgressBandwidthInMbps int `json:"egressBandwidthInMbps"`
6}
7type CreateIPv6GatewayRateLimitRuleResult struct {
8 RateLimitRuleId string `json:"rateLimitRuleId"`
9}
10func (c *Client) CreateIPv6GatewayRateLimitRule(gatewayId string, args *CreateIPv6GatewayRateLimitRuleArgs)
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/Akkqimp6y
Response Value
Operation succeeded:
1{
2 "rateLimitRuleId":"ipv6_qos-0b56ec38"
3}
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_create_ipv6gateway_ratelimit_rule.go
Query IPv6 gateway bandwidth limiting policy list
Use the code below to query the list of bandwidth limiting policies for the IPv6 gateway.
Function declaration
1type ListIPv6GatewayRateLimitRuleArgs struct {
2 Marker string
3 MaxKeys int
4}
5type ListIPv6GatewayRateLimitRuleResult struct {
6 Marker string `json:"marker"`
7 IsTruncated bool `json:"isTruncated"`
8 NextMarker string `json:"nextMarker"`
9 MaxKeys int `json:"maxKeys"`
10 RateLimitRules []RateLimitRule `json:"rateLimitRules"`
11}
12func (c *Client) ListIPv6GatewayRateLimitRule(gatewayId string, args *ListIPv6GatewayRateLimitRuleArgs) (*ListIPv6GatewayRateLimitRuleResult, error)
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/lkkqioqpo
Response Value
Operation succeeded:
1{
2 "rateLimitRules":[
3 {
4 "rateLimitRuleId":"ipv6_qos-0b56ec38"
5 "ipv6Address":"240c:4082:0:100::",
6 "ingressBandwidthInMbps":5,
7 "egressBandwidthInMbps":5
8 }
9 ],
10 "marker":"ipv6_qos-0b56ec38",
11 "maxKeys":1000
12 "isTruncated":false
13}
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_list_ipv6gateway_ratelimit_rule.go
Update IPv6 gateway bandwidth limiting policy
Use the code below to modify an existing bandwidth limiting policy for an IPv6 gateway.
Function declaration
1type UpdateIPv6GatewayRateLimitRuleArgs struct {
2 ClientToken string `json:"-"`
3 IngressBandwidthInMbps int `json:"ingressBandwidthInMbps"`
4 EgressBandwidthInMbps int `json:"egressBandwidthInMbps"`
5}
6func (c *Client) UpdateIPv6GatewayRateLimitRule(gatewayId, rateLimitRuleId string, args *UpdateIPv6GatewayRateLimitRuleArgs) error
Parameter Meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/xkkqincwy
Response Value
Operation succeeded:
There are no special response parameters
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_update_ipv6gateway_ratelimit_rule.go
Delete IPv6 gateway bandwidth limiting policy
Use the code below to remove a bandwidth limiting policy for an IPv6 gateway.
Function declaration
1type DeleteIPv6GatewayRateLimitRuleArgs struct {
2 ClientToken string `json:"-"`
3}
4func (c *Client) DeleteIPv6GatewayRateLimitRule(gatewayId, rateLimitRuleId string, args *DeleteIPv6GatewayRateLimitRuleArgs) error
Parameter meaning
Refer to the OpenAPI documentation: https://cloud.baidu.com/doc/VPC/s/vkkqio03j
Response Value
Operation succeeded:
There are no special response parameters
Operation failed:
Throw an exception. For the exception list, refer to: IPv6 Gateway Exception List
Code example
For specific code examples, please refer to:example_delete_ipv6gateway_ratelimit_rule.go
