diff --git a/bce/config.go b/bce/config.go index 041df89..3bfc2c0 100644 --- a/bce/config.go +++ b/bce/config.go @@ -26,7 +26,7 @@ import ( // Constants and default values for the package bce const ( - SDK_VERSION = "0.9.173" + SDK_VERSION = "0.9.174" URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path DEFAULT_DOMAIN = "baidubce.com" DEFAULT_PROTOCOL = "http" diff --git a/doc/CDN.md b/doc/CDN.md index 09ae827..7f05ad9 100644 --- a/doc/CDN.md +++ b/doc/CDN.md @@ -165,6 +165,37 @@ fmt.Printf("err:%+v\n", err) | Backup | bool | 表示是否为备用源站,备用源站在主源站都不可用的情况下才会使用,false表示这个源站是主源站。需要注意的是在golang中bool对象默认值为false,如果没有显式设置Backup的值,那么默认就是false。 | | Follow302 | bool | true表示当回源到源站时源站返回302时,CDN系统会处理Location重定向,主动获取资源返回给客户端。false表示当源站返回302时,CDN系统透传302给客户端。**需要注意的是,目前Follow302已经修改为所有源站级别的配置,所以要求所有的源站Follow302必须一致,否则可能会出现不可预料的结果**。 | + +另外,您也可以使用更高级的 **CreateDomainWithOptions** 方法创建域名,目前支持的 Option 有以下几项: +- CreateDomainWithForm:配置域名的form(类型、类别) +- CreateDomainWithOriginDefaultHost:配置域名的域名级别回源Host,优先级低于源站级别回源Host +- CreateDomainWithTags:绑定域名到标签 + +下面通过代码展示如何调用 CreateDomainWithOptions。 + +```go +cli := client.GetDefaultClient() +domainCreatedInfo, err := testCli.CreateDomainWithOptions("test_go_sdk.baidu.com", []api.OriginPeer{ + { + Peer: "1.2.3.4", + Host: "www.baidu.com", + }, + }, CreateDomainWithTags([]model.TagModel{ + { + TagKey: "service", + TagValue: "web", + }, + { + TagKey: "域名类型", + TagValue: "网站服务", + }, + }), CreateDomainWithForm("image"), CreateDomainWithOriginDefaultHost("origin.baidu.com")) + +fmt.Printf("domainCreatedInfo:%+v\n", domainCreatedInfo) +fmt.Printf("err:%+v\n", err) +``` + + ### 启用/停止/删除加速域名 EnableDomain/DisableDomain/DeleteDomain ```go @@ -1098,6 +1129,52 @@ fmt.Printf("err:%+v\n", err) fmt.Printf("ocspSwitch:%+v\n", ocspSwitch) ``` + +### 设置/查询标签 + +> 标签是一组标识,您可以将具备某些共同点的域名进行归类,即打上标签,以此对资源进行组织。 + +一组标签定义为tags,他的类型如下: + +| 字段 | 类型 | 说明 | +| :----------| :----- | :------- | +| tags | model.TagModel[] | 目标关联到的标签集合,需传入资源的全量标签信息,如原有3个标签,现删除1个标签的情况下新增2个标签,则应传入全量4个标签。当 tags 为空时,表示将域名关联的所有标签清空。标签个数最多为 10 个。 | + + +model.TagModel 类型如下: + +| 参数 | 类型 | 说明 | +| ---------------- | ------ | ---------------------------------------------------------- | +| tagKey | string | 标签的键,可包含大小写字母、数字、中文以及-_ /.特殊字符,长度 1-65 | +| tagValue | string | 标签的值,可包含大小写字母、数字、中文以及-_ /.特殊字符,长度 0-65 | + + +下面展示通过SDK方法配置标签与查询标签。 + +```go +cli := client.GetDefaultClient() +testDomain := "test_go_sdk.baidu.com" + +// 配置标签 +err := testCli.SetTags(testDomain, []model.TagModel{ + { + TagKey: "service", + TagValue: "download", + }, + }) +fmt.Printf("err: %+v\n", err) + +// 查询标签 +tags, err := testCli.GetTags(testDomain) +fmt.Printf("tags: %+v\n", tags) + +// 移除所有标签 +err := testCli.SetTags(testDomain, []model.TagModel{}) // 等同于 testCli.SetTags(testDomain, nil) +fmt.Printf("err: %+v\n", err) + +``` + + ## 证书管理接口 ### 添加/修改域名证书 PutCert diff --git a/examples/bbc/example_bind_bbc_reserved_tags.go b/examples/bbc/example_bind_bbc_reserved_tags.go new file mode 100644 index 0000000..fae9464 --- /dev/null +++ b/examples/bbc/example_bind_bbc_reserved_tags.go @@ -0,0 +1,27 @@ +package bbc + +import ( + "github.com/baidubce/bce-sdk-go/model" + "github.com/baidubce/bce-sdk-go/services/bbc" +) + +func BindReservedTagsDemo() { + // 初始化AK/SK/Endpoint + ak, sk, endpoint := "ak", "sk", "bbc.bj.baidubce.com" + client, _ := bbc.NewClient(ak, sk, endpoint) // 创建BBC Client + args := &bbc.ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + } + err := client.BindReservedInstanceToTags(args) + if err != nil { + panic(err) + } +} diff --git a/examples/bbc/example_unbind_bbc_reserved_tags.go b/examples/bbc/example_unbind_bbc_reserved_tags.go new file mode 100644 index 0000000..ae6715f --- /dev/null +++ b/examples/bbc/example_unbind_bbc_reserved_tags.go @@ -0,0 +1,27 @@ +package bbc + +import ( + "github.com/baidubce/bce-sdk-go/model" + "github.com/baidubce/bce-sdk-go/services/bbc" +) + +func UnbindReservedTagsDemo() { + // 初始化AK/SK/Endpoint + ak, sk, endpoint := "ak", "sk", "bbc.bj.baidubce.com" + client, _ := bbc.NewClient(ak, sk, endpoint) // 创建BBC Client + args := &bbc.ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + } + err := client.UnbindReservedInstanceFromTags(args) + if err != nil { + panic(err) + } +} diff --git a/examples/bcc/example_bind_bcc_reserved_tags.go b/examples/bcc/example_bind_bcc_reserved_tags.go new file mode 100644 index 0000000..aeea909 --- /dev/null +++ b/examples/bcc/example_bind_bcc_reserved_tags.go @@ -0,0 +1,29 @@ +package bcc + +import ( + "github.com/baidubce/bce-sdk-go/model" + "github.com/baidubce/bce-sdk-go/services/bcc/api" + + "github.com/baidubce/bce-sdk-go/services/bcc" +) + +func BindBccReservedTagsDemo() { + // 初始化AK/SK/Endpoint + ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com" + client, _ := bcc.NewClient(ak, sk, endpoint) // 创建BCC Client + args := &api.ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + } + err := client.BindReservedInstanceToTags(args) + if err != nil { + panic(err) + } +} diff --git a/examples/bcc/example_unbind_bcc_reserved_tags.go b/examples/bcc/example_unbind_bcc_reserved_tags.go new file mode 100644 index 0000000..b11ace6 --- /dev/null +++ b/examples/bcc/example_unbind_bcc_reserved_tags.go @@ -0,0 +1,29 @@ +package bcc + +import ( + "github.com/baidubce/bce-sdk-go/model" + "github.com/baidubce/bce-sdk-go/services/bcc/api" + + "github.com/baidubce/bce-sdk-go/services/bcc" +) + +func UnbindBccReservedTagsDemo() { + // 初始化AK/SK/Endpoint + ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com" + client, _ := bcc.NewClient(ak, sk, endpoint) // 创建BCC Client + args := &api.ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + } + err := client.UnbindReservedInstanceFromTags(args) + if err != nil { + panic(err) + } +} diff --git a/examples/bcc/tag/example_bind_tags_by_resource_type.go b/examples/bcc/tag/example_bind_tags_by_resource_type.go new file mode 100644 index 0000000..a420fc2 --- /dev/null +++ b/examples/bcc/tag/example_bind_tags_by_resource_type.go @@ -0,0 +1,31 @@ +package tag + +import ( + "github.com/baidubce/bce-sdk-go/model" + "github.com/baidubce/bce-sdk-go/services/bcc/api" + + "github.com/baidubce/bce-sdk-go/services/bcc" +) + +func BindTagsByResourceTypeDemo() { + // 初始化AK/SK/Endpoint + ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com" + client, _ := bcc.NewClient(ak, sk, endpoint) // 创建BCC Client + args := &api.TagsOperationRequest{ + ResourceType: "bccri", + ResourceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + Tags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + IsRelationTag: false, + } + err := client.BindInstanceToTagsByResourceType(args) + if err != nil { + panic(err) + } +} diff --git a/examples/bcc/tag/example_unbind_tags_by_resource_type.go b/examples/bcc/tag/example_unbind_tags_by_resource_type.go new file mode 100644 index 0000000..cd1199c --- /dev/null +++ b/examples/bcc/tag/example_unbind_tags_by_resource_type.go @@ -0,0 +1,31 @@ +package tag + +import ( + "github.com/baidubce/bce-sdk-go/model" + "github.com/baidubce/bce-sdk-go/services/bcc/api" + + "github.com/baidubce/bce-sdk-go/services/bcc" +) + +func UnbindTagsByResourceTypeDemo() { + // 初始化AK/SK/Endpoint + ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com" + client, _ := bcc.NewClient(ak, sk, endpoint) // 创建BCC Client + args := &api.TagsOperationRequest{ + ResourceType: "bccri", + ResourceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + Tags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + IsRelationTag: false, + } + err := client.UnbindInstanceToTagsByResourceType(args) + if err != nil { + panic(err) + } +} diff --git a/services/bbc/client.go b/services/bbc/client.go index bfa40e0..050558e 100644 --- a/services/bbc/client.go +++ b/services/bbc/client.go @@ -61,10 +61,11 @@ func NewClient(ak, sk, endPoint string) (*Client, error) { // CreateInstance - create an instance with the specific parameters // // PARAMS: -// - args: the arguments to create instance +// - args: the arguments to create instance +// // RETURNS: -// - *CreateInstanceResult: the result of create Instance, contains new Instance ID -// - error: nil if success otherwise the specific error +// - *CreateInstanceResult: the result of create Instance, contains new Instance ID +// - error: nil if success otherwise the specific error func (c *Client) CreateInstance(args *CreateInstanceArgs) (*CreateInstanceResult, error) { if len(args.AdminPass) > 0 { cryptedPass, err := Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass) @@ -97,10 +98,11 @@ func (c *Client) CreateInstance(args *CreateInstanceArgs) (*CreateInstanceResult // CreateInstance - create an instance with specific parameters and support the passing in of label // // PARAMS: -// - args: the arguments to create instance +// - args: the arguments to create instance +// // RETURNS: -// - *CreateInstanceResult: the result of create Instance, contains new Instance ID -// - error: nil if success otherwise the specific erro +// - *CreateInstanceResult: the result of create Instance, contains new Instance ID +// - error: nil if success otherwise the specific erro func (c *Client) CreateInstanceByLabel(args *CreateSpecialInstanceArgs) (*CreateInstanceResult, error) { if len(args.AdminPass) > 0 { cryptedPass, err := Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass) @@ -133,10 +135,11 @@ func (c *Client) CreateInstanceByLabel(args *CreateSpecialInstanceArgs) (*Create // CreateInstanceByLabelV2 - create an instance with specific parameters and support the passing in of label // // PARAMS: -// - args: the arguments to create instance +// - args: the arguments to create instance +// // RETURNS: -// - *CreateInstanceResult: the result of create Instance, contains new Instance ID -// - error: nil if success otherwise the specific erro +// - *CreateInstanceResult: the result of create Instance, contains new Instance ID +// - error: nil if success otherwise the specific erro func (c *Client) CreateInstanceByLabelV2(argsV2 *CreateSpecialInstanceArgsV2) (*CreateInstanceResult, error) { if len(argsV2.AdminPass) > 0 { cryptedPass, err := Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, argsV2.AdminPass) @@ -183,10 +186,11 @@ func (c *Client) CreateInstanceByLabelV2(argsV2 *CreateSpecialInstanceArgsV2) (* // ListInstances - list all instance with the specific parameters // // PARAMS: -// - args: the arguments to list all instance +// - args: the arguments to list all instance +// // RETURNS: -// - *ListInstanceResult: the result of list Instance -// - error: nil if success otherwise the specific error +// - *ListInstanceResult: the result of list Instance +// - error: nil if success otherwise the specific error func (c *Client) ListInstances(args *ListInstancesArgs) (*ListInstancesResult, error) { return ListInstances(c, args) } @@ -194,10 +198,11 @@ func (c *Client) ListInstances(args *ListInstancesArgs) (*ListInstancesResult, e // GetInstanceDetail - get a specific instance detail info // // PARAMS: -// - instanceId: the specific instance ID +// - instanceId: the specific instance ID +// // RETURNS: -// - *GetInstanceDetailResult: the result of get instance detail info -// - error: nil if success otherwise the specific error +// - *GetInstanceDetailResult: the result of get instance detail info +// - error: nil if success otherwise the specific error func (c *Client) GetInstanceDetail(instanceId string) (*InstanceModel, error) { return GetInstanceDetail(c, instanceId) } @@ -214,9 +219,10 @@ func (c *Client) GetInstanceDetailWithDeploySetAndFailed(instanceId string, // StartInstance - start an instance // // PARAMS: -// - instanceId: the specific instance ID +// - instanceId: the specific instance ID +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) StartInstance(instanceId string) error { return StartInstance(c, instanceId) } @@ -224,10 +230,11 @@ func (c *Client) StartInstance(instanceId string) error { // StopInstance - stop an instance // // PARAMS: -// - instanceId: the specific instance ID -// - forceStop: choose to force stop an instance or not +// - instanceId: the specific instance ID +// - forceStop: choose to force stop an instance or not +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) StopInstance(instanceId string, forceStop bool) error { args := &StopInstanceArgs{ ForceStop: forceStop, @@ -248,10 +255,11 @@ func (c *Client) StopInstance(instanceId string, forceStop bool) error { // RebootInstance - restart an instance // // PARAMS: -// - instanceId: the specific instance ID -// - forceStop: choose to force stop an instance or not +// - instanceId: the specific instance ID +// - forceStop: choose to force stop an instance or not +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) RebootInstance(instanceId string, forceStop bool) error { args := &StopInstanceArgs{ ForceStop: forceStop, @@ -272,10 +280,11 @@ func (c *Client) RebootInstance(instanceId string, forceStop bool) error { // ModifyInstanceName - modify an instance's name // // PARAMS: -// - instanceId: the specific instance ID -// - args: the arguments of now instance's name +// - instanceId: the specific instance ID +// - args: the arguments of now instance's name +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) ModifyInstanceName(instanceId string, args *ModifyInstanceNameArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -292,10 +301,11 @@ func (c *Client) ModifyInstanceName(instanceId string, args *ModifyInstanceNameA // ModifyInstanceDesc - modify an instance's description // // PARAMS: -// - instanceId: the specific instance ID -// - args: the arguments of now instance's description +// - instanceId: the specific instance ID +// - args: the arguments of now instance's description +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) ModifyInstanceDesc(instanceId string, args *ModifyInstanceDescArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -313,11 +323,12 @@ func (c *Client) ModifyInstanceDesc(instanceId string, args *ModifyInstanceDescA // RebuildInstance - rebuild an instance // // PARAMS: -// - instanceId: the specific instance ID -// - isPreserveData: choose to preserve data or not -// - args: the arguments to rebuild an instance +// - instanceId: the specific instance ID +// - isPreserveData: choose to preserve data or not +// - args: the arguments to rebuild an instance +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) RebuildInstance(instanceId string, isPreserveData bool, args *RebuildInstanceArgs) error { cryptedPass, err := Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass) if err != nil { @@ -346,10 +357,11 @@ func (c *Client) RebuildInstance(instanceId string, isPreserveData bool, args *R // GetInstanceVNC - get an instance's VNC url // // PARAMS: -// - instanceId: the specific instance ID +// - instanceId: the specific instance ID +// // RETURNS: -// - *api.GetInstanceVNCResult: the result of get instance's VNC url -// - error: nil if success otherwise the specific error +// - *api.GetInstanceVNCResult: the result of get instance's VNC url +// - error: nil if success otherwise the specific error func (c *Client) GetInstanceVNC(instanceId string) (*GetInstanceVNCResult, error) { return GetInstanceVNC(c, instanceId) } @@ -357,10 +369,11 @@ func (c *Client) GetInstanceVNC(instanceId string) (*GetInstanceVNCResult, error // RebuildBatchInstance - batch rebuild instances // // PARAMS: -// - args: the arguments to batch rebuild instances +// - args: the arguments to batch rebuild instances +// // RETURNS: -// - *BatchRebuildResponse: the result of batch rebuild the instances -// - error: nil if success otherwise the specific error +// - *BatchRebuildResponse: the result of batch rebuild the instances +// - error: nil if success otherwise the specific error func (c *Client) BatchRebuildInstances(args *RebuildBatchInstanceArgs) (*BatchRebuildResponse, error) { if len(args.AdminPass) > 0 { encryptedPass, err := api.Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass) @@ -385,10 +398,11 @@ func (c *Client) BatchRebuildInstances(args *RebuildBatchInstanceArgs) (*BatchRe // BatchRebuildInstancesV2 - batch rebuild instances // // PARAMS: -// - args: the arguments to batch rebuild instances +// - args: the arguments to batch rebuild instances +// // RETURNS: -// - *BatchRebuildResponse: the result of batch rebuild the instances -// - error: nil if success otherwise the specific error +// - *BatchRebuildResponse: the result of batch rebuild the instances +// - error: nil if success otherwise the specific error func (c *Client) BatchRebuildInstancesV2(argsV2 *RebuildBatchInstanceArgsV2) (*BatchRebuildResponse, error) { if len(argsV2.AdminPass) > 0 { encryptedPass, err := api.Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, argsV2.AdminPass) @@ -416,10 +430,11 @@ func (c *Client) BatchRebuildInstancesV2(argsV2 *RebuildBatchInstanceArgsV2) (*B // InstancePurchaseReserved - purchase reserve an instance // // PARAMS: -// - instanceId: the specific instance ID -// - args: the arguments to purchase reserved an instance +// - instanceId: the specific instance ID +// - args: the arguments to purchase reserved an instance +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) InstancePurchaseReserved(instanceId string, args *PurchaseReservedArgs) error { // this api only support Prepaid instance args.Billing.PaymentTiming = PaymentTimingPrePaid @@ -439,9 +454,10 @@ func (c *Client) InstancePurchaseReserved(instanceId string, args *PurchaseReser // DeleteInstance - delete an instance // // PARAMS: -// - instanceId: the specific instance ID +// - instanceId: the specific instance ID +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DeleteInstance(instanceId string) error { return DeleteInstance(c, instanceId) } @@ -449,10 +465,11 @@ func (c *Client) DeleteInstance(instanceId string) error { // ListInstances - list all instance with the specific parameters // // PARAMS: -// - args: the arguments to list all instance +// - args: the arguments to list all instance +// // RETURNS: -// - *ListInstanceResult: the result of list Instance -// - error: nil if success otherwise the specific error +// - *ListInstanceResult: the result of list Instance +// - error: nil if success otherwise the specific error func (c *Client) ListRecycledInstances(args *ListRecycledInstancesArgs) (*ListRecycledInstancesResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -468,10 +485,11 @@ func (c *Client) ListRecycledInstances(args *ListRecycledInstancesArgs) (*ListRe // ListInstances - list all instance with the specific parameters // // PARAMS: -// - args: the arguments to list all instance +// - args: the arguments to list all instance +// // RETURNS: -// - *ListInstanceResult: the result of list Instance -// - error: nil if success otherwise the specific error +// - *ListInstanceResult: the result of list Instance +// - error: nil if success otherwise the specific error func (c *Client) RecoveryInstances(args *RecoveryInstancesArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -487,9 +505,10 @@ func (c *Client) RecoveryInstances(args *RecoveryInstancesArgs) error { // DeleteInstance - delete an instance // // PARAMS: -// - instanceId: the specific instance ID +// - instanceId: the specific instance ID +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DeleteInstances(args *DeleteInstanceArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -505,10 +524,11 @@ func (c *Client) DeleteInstances(args *DeleteInstanceArgs) error { // ModifyInstancePassword - modify an instance's password // // PARAMS: -// - instanceId: the specific instance ID -// - args: the arguments of now instance's password +// - instanceId: the specific instance ID +// - args: the arguments of now instance's password +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) ModifyInstancePassword(instanceId string, args *ModifyInstancePasswordArgs) error { cryptedPass, err := Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass) if err != nil { @@ -531,9 +551,10 @@ func (c *Client) ModifyInstancePassword(instanceId string, args *ModifyInstanceP // InstanceChangeSubnet - change an instance's subnet // // PARAMS: -// - args: the arguments to change an instance's subnet +// - args: the arguments to change an instance's subnet +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) InstanceChangeSubnet(args *InstanceChangeSubnetArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -550,9 +571,10 @@ func (c *Client) InstanceChangeSubnet(args *InstanceChangeSubnetArgs) error { // InstanceChangeVpc - change an instance's vpc // // PARAMS: -// - args: the arguments to change an instance's vpc +// - args: the arguments to change an instance's vpc +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) InstanceChangeVpc(args *InstanceChangeVpcArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -569,10 +591,11 @@ func (c *Client) InstanceChangeVpc(args *InstanceChangeVpcArgs) error { // GetVpcSubnet - get multi instances vpc and subnet // // PARAMS: -// - args: the instanceId of bbc instances +// - args: the instanceId of bbc instances +// // RETURNS: -// - *GetVpcSubnetResult: result of vpc and subnet -// - error: nil if success otherwise the specific error +// - *GetVpcSubnetResult: result of vpc and subnet +// - error: nil if success otherwise the specific error func (c *Client) GetVpcSubnet(args *GetVpcSubnetArgs) (*GetVpcSubnetResult, error) { jsonBytes, jsonErr := json.Marshal(args) @@ -589,9 +612,10 @@ func (c *Client) GetVpcSubnet(args *GetVpcSubnetArgs) (*GetVpcSubnetResult, erro // BatchAddIP - Add ips to instance // // PARAMS: -// - args: the arguments to add ips to bbc instance +// - args: the arguments to add ips to bbc instance +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) BatchAddIP(args *BatchAddIpArgs) (*BatchAddIpResponse, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -607,9 +631,10 @@ func (c *Client) BatchAddIP(args *BatchAddIpArgs) (*BatchAddIpResponse, error) { // BatchDelIP - Delete ips of instance // // PARAMS: -// - args: the arguments to add ips to bbc instance +// - args: the arguments to add ips to bbc instance +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) BatchDelIP(args *BatchDelIpArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -625,9 +650,10 @@ func (c *Client) BatchDelIP(args *BatchDelIpArgs) error { // BatchAddIPCrossSubnet - Add ips to instance cross subnet // // PARAMS: -// - args: the arguments to add ips to bbc instance +// - args: the arguments to add ips to bbc instance +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) BatchAddIPCrossSubnet(args *BatchAddIpCrossSubnetArgs) (*BatchAddIpResponse, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -643,10 +669,11 @@ func (c *Client) BatchAddIPCrossSubnet(args *BatchAddIpCrossSubnetArgs) (*BatchA // BindTags - bind an instance tags // // PARAMS: -// - instanceId: the id of the instance -// - args: tags of an instance to bind +// - instanceId: the id of the instance +// - args: tags of an instance to bind +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) BindTags(instanceId string, args *BindTagsArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -662,10 +689,11 @@ func (c *Client) BindTags(instanceId string, args *BindTagsArgs) error { // UnbindTags - unbind an instance tags // // PARAMS: -// - instanceId: the id of the instance -// - args: tags of an instance to unbind +// - instanceId: the id of the instance +// - args: tags of an instance to unbind +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) UnbindTags(instanceId string, args *UnbindTagsArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -678,11 +706,37 @@ func (c *Client) UnbindTags(instanceId string, args *UnbindTagsArgs) error { return UnbindTags(c, instanceId, body) } +func (c *Client) BindReservedInstanceToTags(args *ReservedTagsRequest) error { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + + return BindReservedInstanceToTags(c, body) +} + +func (c *Client) UnbindReservedInstanceFromTags(args *ReservedTagsRequest) error { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + + return UnbindReservedInstanceFromTags(c, body) +} + // ListFlavors - list all available flavors // // RETURNS: -// - *ListFlavorsResult: the result of list all flavors -// - error: nil if success otherwise the specific error +// - *ListFlavorsResult: the result of list all flavors +// - error: nil if success otherwise the specific error func (c *Client) ListFlavors() (*ListFlavorsResult, error) { return ListFlavors(c) } @@ -690,10 +744,11 @@ func (c *Client) ListFlavors() (*ListFlavorsResult, error) { // GetFlavorDetail - get details of the specified flavor // // PARAMS: -// - flavorId: the id of the flavor +// - flavorId: the id of the flavor +// // RETURNS: -// - *GetFlavorDetailResult: the detail of the specified flavor -// - error: nil if success otherwise the specific error +// - *GetFlavorDetailResult: the detail of the specified flavor +// - error: nil if success otherwise the specific error func (c *Client) GetFlavorDetail(flavorId string) (*GetFlavorDetailResult, error) { return GetFlavorDetail(c, flavorId) } @@ -701,10 +756,11 @@ func (c *Client) GetFlavorDetail(flavorId string) (*GetFlavorDetailResult, error // GetFlavorRaid - get the RAID detail and disk size of the specified flavor // // PARAMS: -// - flavorId: the id of the flavor +// - flavorId: the id of the flavor +// // RETURNS: -// - *GetFlavorRaidResult: the detail of the raid of the specified flavor -// - error: nil if success otherwise the specific error +// - *GetFlavorRaidResult: the detail of the raid of the specified flavor +// - error: nil if success otherwise the specific error func (c *Client) GetFlavorRaid(flavorId string) (*GetFlavorRaidResult, error) { return GetFlavorRaid(c, flavorId) } @@ -712,10 +768,11 @@ func (c *Client) GetFlavorRaid(flavorId string) (*GetFlavorRaidResult, error) { // CreateImageFromInstanceId - create image from specified instance // // PARAMS: -// - args: the arguments to create image +// - args: the arguments to create image +// // RETURNS: -// - *CreateImageResult: the result of create Image -// - error: nil if success otherwise the specific error +// - *CreateImageResult: the result of create Image +// - error: nil if success otherwise the specific error func (c *Client) CreateImageFromInstanceId(args *CreateImageArgs) (*CreateImageResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -728,13 +785,14 @@ func (c *Client) CreateImageFromInstanceId(args *CreateImageArgs) (*CreateImageR return CreateImageFromInstanceId(c, args.ClientToken, body) } -//ListImage - list all images +// ListImage - list all images // // PARAMS: -// - args: the arguments to list all images +// - args: the arguments to list all images +// // RETURNS: -// - *ListImageResult: the result of list all images -// - error: nil if success otherwise the specific error +// - *ListImageResult: the result of list all images +// - error: nil if success otherwise the specific error func (c *Client) ListImage(args *ListImageArgs) (*ListImageResult, error) { return ListImage(c, args) } @@ -742,10 +800,11 @@ func (c *Client) ListImage(args *ListImageArgs) (*ListImageResult, error) { // GetImageDetail - get an image's detail info // // PARAMS: -// - imageId: the specific image ID +// - imageId: the specific image ID +// // RETURNS: -// - *GetImageDetailResult: the result of get image's detail -// - error: nil if success otherwise the specific error +// - *GetImageDetailResult: the result of get image's detail +// - error: nil if success otherwise the specific error func (c *Client) GetImageDetail(imageId string) (*GetImageDetailResult, error) { return GetImageDetail(c, imageId) } @@ -753,9 +812,10 @@ func (c *Client) GetImageDetail(imageId string) (*GetImageDetailResult, error) { // DeleteImage - delete an image // // PARAMS: -// - imageId: the specific image ID +// - imageId: the specific image ID +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DeleteImage(imageId string) error { return DeleteImage(c, imageId) } @@ -763,10 +823,11 @@ func (c *Client) DeleteImage(imageId string) error { // GetOperationLog - get operation log // // PARAMS: -// - args: the arguments to get operation log +// - args: the arguments to get operation log +// // RETURNS: -// - *GetOperationLogResult: results of getting operation log -// - error: nil if success otherwise the specific error +// - *GetOperationLogResult: results of getting operation log +// - error: nil if success otherwise the specific error func (c *Client) GetOperationLog(args *GetOperationLogArgs) (*GetOperationLogResult, error) { return GetOperationLog(c, args) } @@ -774,10 +835,11 @@ func (c *Client) GetOperationLog(args *GetOperationLogArgs) (*GetOperationLogRes // CreateDeploySet - create a deploy set // // PARAMS: -// - args: the arguments to create a deploy set +// - args: the arguments to create a deploy set +// // RETURNS: -// - *CreateDeploySetResult: results of creating a deploy set -// - error: nil if success otherwise the specific error +// - *CreateDeploySetResult: results of creating a deploy set +// - error: nil if success otherwise the specific error func (c *Client) CreateDeploySet(args *CreateDeploySetArgs) (*CreateDeploySetResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -793,18 +855,19 @@ func (c *Client) CreateDeploySet(args *CreateDeploySetArgs) (*CreateDeploySetRes // ListDeploySets - list all deploy sets // // RETURNS: -// - *ListDeploySetsResult: the result of list all deploy sets -// - error: nil if success otherwise the specific error +// - *ListDeploySetsResult: the result of list all deploy sets +// - error: nil if success otherwise the specific error func (c *Client) ListDeploySets() (*ListDeploySetsResult, error) { return ListDeploySets(c) } // ListDeploySets - list all deploy sets // PARAMS: -// - args: the arguments to filter +// - args: the arguments to filter +// // RETURNS: -// - *ListDeploySetsResult: the result of list all deploy sets -// - error: nil if success otherwise the specific error +// - *ListDeploySetsResult: the result of list all deploy sets +// - error: nil if success otherwise the specific error func (c *Client) ListDeploySetsPage(args *ListDeploySetsArgs) (*ListDeploySetsResult, error) { return ListDeploySetsPage(c, args) } @@ -812,10 +875,11 @@ func (c *Client) ListDeploySetsPage(args *ListDeploySetsArgs) (*ListDeploySetsRe // GetDeploySet - get details of the deploy set // // PARAMS: -// - deploySetId: the id of the deploy set +// - deploySetId: the id of the deploy set +// // RETURNS: -// - *GetDeploySetResult: the detail of the deploy set -// - error: nil if success otherwise the specific error +// - *GetDeploySetResult: the detail of the deploy set +// - error: nil if success otherwise the specific error func (c *Client) GetDeploySet(deploySetId string) (*DeploySetResult, error) { return GetDeploySet(c, deploySetId) } @@ -823,9 +887,10 @@ func (c *Client) GetDeploySet(deploySetId string) (*DeploySetResult, error) { // DeleteDeploySet - delete a deploy set // // PARAMS: -// - deploySetId: the id of the deploy set +// - deploySetId: the id of the deploy set +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DeleteDeploySet(deploySetId string) error { return DeleteDeploySet(c, deploySetId) } @@ -833,9 +898,10 @@ func (c *Client) DeleteDeploySet(deploySetId string) error { // BindSecurityGroups - Bind Security Groups // // PARAMS: -// - args: the arguments of bind security groups +// - args: the arguments of bind security groups +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) BindSecurityGroups(args *BindSecurityGroupsArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -852,9 +918,10 @@ func (c *Client) BindSecurityGroups(args *BindSecurityGroupsArgs) error { // UnBindSecurityGroups - UnBind Security Groups // // PARAMS: -// - args: the arguments of bind security groups +// - args: the arguments of bind security groups +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) UnBindSecurityGroups(args *UnBindSecurityGroupsArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -870,11 +937,12 @@ func (c *Client) UnBindSecurityGroups(args *UnBindSecurityGroupsArgs) error { // ListFlavorZones - get the zone list of the specified flavor which can buy // // PARAMS: -// - cli: the client agent which can perform sending request -// - flavorId: the id of the flavor +// - cli: the client agent which can perform sending request +// - flavorId: the id of the flavor +// // RETURNS: -// - *ListZonesResult: the list of zone names -// - error: nil if success otherwise the specific error +// - *ListZonesResult: the list of zone names +// - error: nil if success otherwise the specific error func (c *Client) ListFlavorZones(args *ListFlavorZonesArgs) (*ListZonesResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -890,11 +958,12 @@ func (c *Client) ListFlavorZones(args *ListFlavorZonesArgs) (*ListZonesResult, e // ListZoneFlavors - get the flavor detail of the specific zone // // PARAMS: -// - cli: the client agent which can perform sending request -// - zoneName: the zone name +// - cli: the client agent which can perform sending request +// - zoneName: the zone name +// // RETURNS: -// - *ListZoneResult: flavor detail of the specific zone -// - error: nil if success otherwise the specific error +// - *ListZoneResult: flavor detail of the specific zone +// - error: nil if success otherwise the specific error func (c *Client) ListZoneFlavors(args *ListZoneFlavorsArgs) (*ListFlavorInfosResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -910,11 +979,12 @@ func (c *Client) ListZoneFlavors(args *ListZoneFlavorsArgs) (*ListFlavorInfosRes // GetCommonImage - get common flavor image list // // PARAMS: -// - cli: the client agent which can perform sending request -// - flavorIds: the specific flavorIds, can be nil +// - cli: the client agent which can perform sending request +// - flavorIds: the specific flavorIds, can be nil +// // RETURNS: -// - *GetImageDetailResult: the result of get image's detail -// - error: nil if success otherwise the specific error +// - *GetImageDetailResult: the result of get image's detail +// - error: nil if success otherwise the specific error func (c *Client) GetCommonImage(args *GetFlavorImageArgs) (*GetImagesResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -930,11 +1000,12 @@ func (c *Client) GetCommonImage(args *GetFlavorImageArgs) (*GetImagesResult, err // GetCustomImage - get user onwer flavor image list // // PARAMS: -// - cli: the client agent which can perform sending request -// - flavorIds: the specific flavorIds, can be nil +// - cli: the client agent which can perform sending request +// - flavorIds: the specific flavorIds, can be nil +// // RETURNS: -// - *GetImageDetailResult: the result of get image's detail -// - error: nil if success otherwise the specific error +// - *GetImageDetailResult: the result of get image's detail +// - error: nil if success otherwise the specific error func (c *Client) GetCustomImage(args *GetFlavorImageArgs) (*GetImagesResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -950,10 +1021,11 @@ func (c *Client) GetCustomImage(args *GetFlavorImageArgs) (*GetImagesResult, err // ShareImage - share an image // // PARAMS: -// - imageId: the specific image ID -// - args: the arguments to share an image +// - imageId: the specific image ID +// - args: the arguments to share an image +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) ShareImage(imageId string, args *SharedUser) error { return ShareImage(c, imageId, args) } @@ -961,10 +1033,11 @@ func (c *Client) ShareImage(imageId string, args *SharedUser) error { // UnShareImage - cancel share an image // // PARAMS: -// - imageId: the specific image ID -// - args: the arguments to cancel share an image +// - imageId: the specific image ID +// - args: the arguments to cancel share an image +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) UnShareImage(imageId string, args *SharedUser) error { return UnShareImage(c, imageId, args) } @@ -972,10 +1045,11 @@ func (c *Client) UnShareImage(imageId string, args *SharedUser) error { // GetImageSharedUser - get user list use this image // // PARAMS: -// - imageId: the specific image ID +// - imageId: the specific image ID +// // RETURNS: -// - *api.GetImageSharedUserResult: the result of user list -// - error: nil if success otherwise the specific error +// - *api.GetImageSharedUserResult: the result of user list +// - error: nil if success otherwise the specific error func (c *Client) GetImageSharedUser(imageId string) (*GetImageSharedUserResult, error) { return GetImageSharedUser(c, imageId) } @@ -983,10 +1057,11 @@ func (c *Client) GetImageSharedUser(imageId string) (*GetImageSharedUserResult, // RemoteCopyImage - copy a bbc image from other region // // PARAMS: -// - imageId: the specific image ID -// - args: the arguments to remote copy an image +// - imageId: the specific image ID +// - args: the arguments to remote copy an image +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) RemoteCopyImage(imageId string, args *RemoteCopyImageArgs) error { return RemoteCopyImage(c, imageId, args) } @@ -994,10 +1069,11 @@ func (c *Client) RemoteCopyImage(imageId string, args *RemoteCopyImageArgs) erro // RemoteCopyImageReturnImageIds - copy an image from other region // // PARAMS: -// - imageId: the specific image ID -// - args: the arguments to remote copy an image +// - imageId: the specific image ID +// - args: the arguments to remote copy an image +// // RETURNS: -// - imageIds of destination region if success otherwise the specific error +// - imageIds of destination region if success otherwise the specific error func (c *Client) RemoteCopyImageReturnImageIds(imageId string, args *RemoteCopyImageArgs) (*RemoteCopyImageResult, error) { return RemoteCopyImageReturnImageIds(c, imageId, args) } @@ -1005,9 +1081,10 @@ func (c *Client) RemoteCopyImageReturnImageIds(imageId string, args *RemoteCopyI // CancelRemoteCopyImage - cancel a copy image from other region operation // // PARAMS: -// - imageId: the specific image ID +// - imageId: the specific image ID +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) CancelRemoteCopyImage(imageId string) error { return CancelRemoteCopyImage(c, imageId) } @@ -1111,10 +1188,11 @@ func (c *Client) GetRepairTaskRecord(args *TaskIdArgs) (*GetRepairRecords, error // ListRule - list the repair plat rules // // PARAMS: -// - args: the arguments of listing the repair plat rules +// - args: the arguments of listing the repair plat rules +// // RETURNS: -// - *ListRuleResult: results of listing the repair plat rules -// - error: nil if success otherwise the specific error +// - *ListRuleResult: results of listing the repair plat rules +// - error: nil if success otherwise the specific error func (c *Client) ListRule(args *ListRuleArgs) (*ListRuleResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -1130,10 +1208,11 @@ func (c *Client) ListRule(args *ListRuleArgs) (*ListRuleResult, error) { // GetRuleDetail - list the repair plat rules // // PARAMS: -// - ruleId: the specified rule id +// - ruleId: the specified rule id +// // RETURNS: -// - *Rule: results of the specified repair plat rule -// - error: nil if success otherwise the specific error +// - *Rule: results of the specified repair plat rule +// - error: nil if success otherwise the specific error func (c *Client) GetRuleDetail(ruleId string) (*Rule, error) { return GetRuleDetail(c, ruleId) } @@ -1141,10 +1220,11 @@ func (c *Client) GetRuleDetail(ruleId string) (*Rule, error) { // CreateRule - create the repair plat rule // // PARAMS: -// - args: the arguments of creating the repair plat rule +// - args: the arguments of creating the repair plat rule +// // RETURNS: -// - *CreateRuleResult: results of the id of the repair plat rule which is created -// - error: nil if success otherwise the specific error +// - *CreateRuleResult: results of the id of the repair plat rule which is created +// - error: nil if success otherwise the specific error func (c *Client) CreateRule(args *CreateRuleArgs) (*CreateRuleResult, error) { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -1160,9 +1240,10 @@ func (c *Client) CreateRule(args *CreateRuleArgs) (*CreateRuleResult, error) { // DeleteRule - delete the repair plat rule // // PARAMS: -// - args: the arguments of deleting the repair plat rule +// - args: the arguments of deleting the repair plat rule +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DeleteRule(args *DeleteRuleArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -1178,9 +1259,10 @@ func (c *Client) DeleteRule(args *DeleteRuleArgs) error { // DisableRule - disable the repair plat rule // // PARAMS: -// - args: the arguments of disabling the repair plat rule +// - args: the arguments of disabling the repair plat rule +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DisableRule(args *DisableRuleArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -1196,9 +1278,10 @@ func (c *Client) DisableRule(args *DisableRuleArgs) error { // EnableRule - enable the repair plat rule // // PARAMS: -// - args: the arguments of enabling the repair plat rule +// - args: the arguments of enabling the repair plat rule +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) EnableRule(args *EnableRuleArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -1214,9 +1297,10 @@ func (c *Client) EnableRule(args *EnableRuleArgs) error { // BatchCreateAutoRenewRules - Batch Create AutoRenew Rules // // PARAMS: -// - args: the arguments to batch create autorenew rules +// - args: the arguments to batch create autorenew rules +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) BatchCreateAutoRenewRules(args *BbcCreateAutoRenewArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -1232,9 +1316,10 @@ func (c *Client) BatchCreateAutoRenewRules(args *BbcCreateAutoRenewArgs) error { // BatchDeleteAutoRenewRules - Batch Delete AutoRenew Rules // // PARAMS: -// - args: the arguments to batch delete autorenew rules +// - args: the arguments to batch delete autorenew rules +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) BatchDeleteAutoRenewRules(args *BbcDeleteAutoRenewArgs) error { jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { @@ -1254,9 +1339,10 @@ func (c *Client) DeleteInstanceIngorePayment(args *DeleteInstanceIngorePaymentAr // DeleteRecycledInstance - delete an recycled instance // // PARAMS: -// - instanceId: the specific instance ID +// - instanceId: the specific instance ID +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DeleteRecycledInstance(instanceId string) error { return DeleteRecycledInstance(c, instanceId) } @@ -1264,10 +1350,11 @@ func (c *Client) DeleteRecycledInstance(instanceId string) error { // ListCDSVolume - list all cds volume with the specific parameters // // PARAMS: -// - args: the arguments to list all cds +// - args: the arguments to list all cds +// // RETURNS: -// - *api.ListCDSVolumeResult: the result of list all CDS volume -// - error: nil if success otherwise the specific error +// - *api.ListCDSVolumeResult: the result of list all CDS volume +// - error: nil if success otherwise the specific error func (c *Client) ListCDSVolume(queryArgs *ListCDSVolumeArgs) (*ListCDSVolumeResult, error) { return ListCDSVolume(c, queryArgs) } @@ -1275,8 +1362,8 @@ func (c *Client) ListCDSVolume(queryArgs *ListCDSVolumeArgs) (*ListCDSVolumeResu // GetBbcStockWithDeploySet - get the bbc's stock with deploySet // // RETURNS: -// - *GetBbcStocksResult: the result of the bbc's stock -// - error: nil if success otherwise the specific error +// - *GetBbcStocksResult: the result of the bbc's stock +// - error: nil if success otherwise the specific error func (c *Client) GetBbcStockWithDeploySet(args *GetBbcStockArgs) (*GetBbcStocksResult, error) { return GetStockWithDeploySet(c, args) } @@ -1284,8 +1371,8 @@ func (c *Client) GetBbcStockWithDeploySet(args *GetBbcStockArgs) (*GetBbcStocksR // ListInstanceByInstanceIds - list bbc detail info by instanceId // // RETURNS: -// - *ListInstancesResult: the result of list bbc detail info -// - error: nil if success otherwise the specific error +// - *ListInstancesResult: the result of list bbc detail info +// - error: nil if success otherwise the specific error func (c *Client) ListInstanceByInstanceIds(args *ListInstanceByInstanceIdArgs) (*ListInstancesResult, error) { return ListInstanceByInstanceIds(c, args) } diff --git a/services/bbc/client_test.go b/services/bbc/client_test.go index 5f66808..a804770 100644 --- a/services/bbc/client_test.go +++ b/services/bbc/client_test.go @@ -40,14 +40,9 @@ type Conf struct { func init() { _, f, _, _ := runtime.Caller(0) - for i := 0; i < 6; i++ { - f = filepath.Dir(f) - } - conf := filepath.Join(f, "config.json") - fmt.Println(conf) + conf := filepath.Join(filepath.Dir(f), "config.json") fp, err := os.Open(conf) if err != nil { - fmt.Println("config json file of ak/sk not given: ", conf) log.Fatal("config json file of ak/sk not given:", conf) os.Exit(1) } @@ -403,6 +398,38 @@ func TestUnbindTags(t *testing.T) { ExpectEqual(t.Errorf, err, nil) } +func TestBindReservedInstanceToTags(t *testing.T) { + args := &ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-Aev4dfQV", "r-0OlWLZ4p", + }, + } + err := BBC_CLIENT.BindReservedInstanceToTags(args) + ExpectEqual(t.Errorf, err, nil) +} + +func TestUnbindReservedInstanceFromTags(t *testing.T) { + args := &ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-Aev4dfQV", "r-0OlWLZ4p", + }, + } + err := BBC_CLIENT.UnbindReservedInstanceFromTags(args) + ExpectEqual(t.Errorf, err, nil) +} + func TestListFlavors(t *testing.T) { res, err := BBC_CLIENT.ListFlavors() fmt.Println(res) diff --git a/services/bbc/model.go b/services/bbc/model.go index 21ec6f8..d2e4723 100644 --- a/services/bbc/model.go +++ b/services/bbc/model.go @@ -1047,3 +1047,8 @@ type BbcStock struct { type ListInstanceByInstanceIdArgs struct { InstanceIds []string `json:"instanceIdList"` } + +type ReservedTagsRequest struct { + ReservedInstanceIds []string `json:"reservedInstanceIds"` + ChangeTags []model.TagModel `json:"changeTags"` +} diff --git a/services/bbc/reserved.go b/services/bbc/reserved.go new file mode 100644 index 0000000..b05fa6b --- /dev/null +++ b/services/bbc/reserved.go @@ -0,0 +1,64 @@ +/* + * Copyright 2017 Baidu, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +// instance.go - the instance APIs definition supported by the BCC service + +// Package api defines all APIs supported by the BCC service of BCE. +package bbc + +import ( + "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/http" +) + +func BindReservedInstanceToTags(cli bce.Client, reqBody *bce.Body) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(GetBbcReservedToTagsUri()) + req.SetMethod(http.PUT) + req.SetBody(reqBody) + req.SetParam("bind", "") + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} + +func UnbindReservedInstanceFromTags(cli bce.Client, reqBody *bce.Body) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(GetBbcReservedToTagsUri()) + req.SetMethod(http.PUT) + req.SetBody(reqBody) + req.SetParam("unbind", "") + + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} diff --git a/services/bbc/util.go b/services/bbc/util.go index 593ff1b..67ec450 100644 --- a/services/bbc/util.go +++ b/services/bbc/util.go @@ -27,14 +27,14 @@ const ( URI_PREFIX_V1 = bce.URI_PREFIX + "v1" URI_PREFIX_V2 = bce.URI_PREFIX + "v2" - REQUEST_INSTANCE_URI = "/instance" - REQUEST_INSTANCE_LABEL_URI = "/instanceByLabel" - REQUEST_BATCH_DELETE_URI = "/batchDelete" - REQUEST_RECYCLE_URI = "/recycle" - REQUEST_RECOVERY_URI = "/recovery" - REQUEST_SUBNET_URI = "/vpcSubnet" - REQUEST_VPC_URI = "/vpc" - SECURITY_GROUP_URI = "/securitygroup" + REQUEST_INSTANCE_URI = "/instance" + REQUEST_INSTANCE_LABEL_URI = "/instanceByLabel" + REQUEST_BATCH_DELETE_URI = "/batchDelete" + REQUEST_RECYCLE_URI = "/recycle" + REQUEST_RECOVERY_URI = "/recovery" + REQUEST_SUBNET_URI = "/vpcSubnet" + REQUEST_VPC_URI = "/vpc" + SECURITY_GROUP_URI = "/securitygroup" REQUEST_IMAGE_URI = "/image" REQUEST_BATCHADDIP_URI = "/batchAddIp" @@ -61,12 +61,13 @@ const ( REQUEST_REPAIR_TASK_URI = "/task" REQUEST_REPAIR_CLOSED_TASK_URI = "/closedTask" - REQUEST_RULE_URI = "/rule" - REQUEST_CREATE_URI = "/create" - REQUEST_DELETE_URI = "/delete" - REQUEST_DISABLE_URI = "/disable" - REQUEST_ENABLE_URI = "/enable" - REQUEST_VOLUME_URI = "/volume" + REQUEST_RULE_URI = "/rule" + REQUEST_CREATE_URI = "/create" + REQUEST_DELETE_URI = "/delete" + REQUEST_DISABLE_URI = "/disable" + REQUEST_ENABLE_URI = "/enable" + REQUEST_VOLUME_URI = "/volume" + REQUEST_BBC_RESERVED_TAG_URI = "/bbc/reserved/tag" ) func Aes128EncryptUseSecreteKey(sk string, data string) (string, error) { @@ -92,4 +93,8 @@ func geBbcStockWithDeploySetUri() string { func getListInstancesByIdsUrl() string { return URI_PREFIX_V1 + REQUEST_INSTANCE_URI + "/listByInstanceId" -} \ No newline at end of file +} + +func GetBbcReservedToTagsUri() string { + return URI_PREFIX_V2 + REQUEST_BBC_RESERVED_TAG_URI +} diff --git a/services/bcc/api/model.go b/services/bcc/api/model.go index f3a7f0d..a5c6dd4 100644 --- a/services/bcc/api/model.go +++ b/services/bcc/api/model.go @@ -1788,6 +1788,18 @@ type UnBindTagsRequest struct { ChangeTags []model.TagModel `json:"changeTags"` } +type ReservedTagsRequest struct { + ReservedInstanceIds []string `json:"reservedInstanceIds"` + ChangeTags []model.TagModel `json:"changeTags"` +} + +type TagsOperationRequest struct { + ResourceType string `json:"resourceType"` + ResourceIds []string `json:"resourceIds"` + Tags []model.TagModel `json:"tags"` + IsRelationTag bool `json:"isRelationTag"` +} + type CancelBidOrderRequest struct { OrderId string `json:"orderId"` ClientToken string `json:"-"` diff --git a/services/bcc/api/reserved.go b/services/bcc/api/reserved.go new file mode 100644 index 0000000..2f220a4 --- /dev/null +++ b/services/bcc/api/reserved.go @@ -0,0 +1,64 @@ +/* + * Copyright 2017 Baidu, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +// instance.go - the instance APIs definition supported by the BCC service + +// Package api defines all APIs supported by the BCC service of BCE. +package api + +import ( + "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/http" +) + +func BindReservedInstanceToTags(cli bce.Client, reqBody *bce.Body) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(GetBccReservedToTagsUri()) + req.SetMethod(http.PUT) + req.SetBody(reqBody) + req.SetParam("bind", "") + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} + +func UnbindReservedInstanceFromTags(cli bce.Client, reqBody *bce.Body) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(GetBccReservedToTagsUri()) + req.SetMethod(http.PUT) + req.SetBody(reqBody) + req.SetParam("unbind", "") + + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} diff --git a/services/bcc/api/tags.go b/services/bcc/api/tags.go new file mode 100644 index 0000000..12f2937 --- /dev/null +++ b/services/bcc/api/tags.go @@ -0,0 +1,48 @@ +package api + +import ( + "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/http" +) + +func BindInstanceToTagsByResourceType(cli bce.Client, reqBody *bce.Body) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(GetServiceTypeTagsUri()) + req.SetMethod(http.POST) + req.SetBody(reqBody) + req.SetParam("action", "AttachTags") + + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} + +func UnbindInstanceToTagsByResourceType(cli bce.Client, reqBody *bce.Body) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(GetServiceTypeTagsUri()) + req.SetMethod(http.POST) + req.SetBody(reqBody) + req.SetParam("action", "DetachTags") + + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} diff --git a/services/bcc/api/util.go b/services/bcc/api/util.go index 9ee966f..c688e96 100644 --- a/services/bcc/api/util.go +++ b/services/bcc/api/util.go @@ -40,6 +40,8 @@ const ( REQUEST_IMAGE_SHAREDUSER_URI = "/sharedUsers" REQUEST_IMAGE_OS_URI = "/os" REQUEST_INSTANCE_URI = "/instance" + REQUEST_BCC_RESERVED_TAG_URI = "/bcc/reserved/tag" + REQUEST_ServiceType_TAG_URI = "/bcc/tag" REQUEST_INSTANCE_LABEL_URI = "/instanceByLabel" REQUEST_LIST_URI = "/list" REQUEST_SECURITYGROUP_URI = "/securityGroup" @@ -309,6 +311,14 @@ func getbindInstanceToTagsUri(id string) string { return URI_PREFIXV2 + REQUEST_INSTANCE_URI + "/" + id + REQUEST_TAG_URI } +func GetBccReservedToTagsUri() string { + return URI_PREFIXV2 + REQUEST_BCC_RESERVED_TAG_URI +} + +func GetServiceTypeTagsUri() string { + return URI_PREFIXV3 + REQUEST_ServiceType_TAG_URI +} + func GetInstanceNoChargeListUri() string { return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_NOCHARGE_URI } @@ -442,5 +452,5 @@ func getBatchRefundResourceUri() string { } func getAvailableImagesBySpecUri() string { - return URI_PREFIXV2 +"/image/getAvailableImagesBySpec" + return URI_PREFIXV2 + "/image/getAvailableImagesBySpec" } diff --git a/services/bcc/client.go b/services/bcc/client.go index d1f76f3..eefa69d 100644 --- a/services/bcc/client.go +++ b/services/bcc/client.go @@ -1751,6 +1751,58 @@ func (c *Client) UnBindInstanceToTags(instanceId string, args *api.UnBindTagsReq return api.UnBindInstanceToTags(c, instanceId, body) } +func (c *Client) BindReservedInstanceToTags(args *api.ReservedTagsRequest) error { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + + return api.BindReservedInstanceToTags(c, body) +} + +func (c *Client) UnbindReservedInstanceFromTags(args *api.ReservedTagsRequest) error { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + + return api.UnbindReservedInstanceFromTags(c, body) +} + +func (c *Client) BindInstanceToTagsByResourceType(args *api.TagsOperationRequest) error { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + + return api.BindInstanceToTagsByResourceType(c, body) +} + +func (c *Client) UnbindInstanceToTagsByResourceType(args *api.TagsOperationRequest) error { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + + return api.UnbindInstanceToTagsByResourceType(c, body) +} + // GetInstanceNoChargeList - get instance with nocharge list // // PARAMS: diff --git a/services/bcc/client_test.go b/services/bcc/client_test.go index 4c08f69..194f680 100644 --- a/services/bcc/client_test.go +++ b/services/bcc/client_test.go @@ -1099,6 +1099,74 @@ func TestUnBindInstanceToTags(t *testing.T) { ExpectEqual(t.Errorf, err, nil) } +func TestBindReservedInstanceToTags(t *testing.T) { + args := &api.ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-Qyycx1SX", + }, + } + err := BCC_CLIENT.BindReservedInstanceToTags(args) + ExpectEqual(t.Errorf, err, nil) +} + +func TestUnbindReservedInstanceToTags(t *testing.T) { + args := &api.ReservedTagsRequest{ + ChangeTags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + ReservedInstanceIds: []string{ + "r-Qyycx1SX", + }, + } + err := BCC_CLIENT.UnbindReservedInstanceFromTags(args) + ExpectEqual(t.Errorf, err, nil) +} + +func TestBindInstanceToTagsByResourceType(t *testing.T) { + args := &api.TagsOperationRequest{ + ResourceType: "bccri", + ResourceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + Tags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + IsRelationTag: false, + } + err := BCC_CLIENT.BindInstanceToTagsByResourceType(args) + ExpectEqual(t.Errorf, err, nil) +} + +func TestUnbindInstanceToTagsByResourceType(t *testing.T) { + args := &api.TagsOperationRequest{ + ResourceType: "bccri", + ResourceIds: []string{ + "r-oFpMXKhv", "r-HrztSVk0", + }, + Tags: []model.TagModel{ + { + TagKey: "TagKey-go", + TagValue: "TagValue", + }, + }, + IsRelationTag: false, + } + err := BCC_CLIENT.UnbindInstanceToTagsByResourceType(args) + ExpectEqual(t.Errorf, err, nil) +} + func TestGetInstanceNoChargeList(t *testing.T) { listArgs := &api.ListInstanceArgs{} _, err := BCC_CLIENT.GetInstanceNoChargeList(listArgs) diff --git a/services/cdn/api/domain.go b/services/cdn/api/domain.go index 21d24bf..407e6a5 100644 --- a/services/cdn/api/domain.go +++ b/services/cdn/api/domain.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/model" ) // DomainStatus defined a struct for domain info, @@ -149,14 +150,24 @@ func IsValidDomain(cli bce.Client, domain string) (*DomainValidInfo, error) { // - cli: the client agent which can perform sending request // - domain: the specified domain // - originInit: initialized data for a CDN domain +// - tags: bind with the specified tags // RETURNS: // - *DomainCreatedInfo: the details about created a CDN domain // - error: nil if success otherwise the specific error -func CreateDomain(cli bce.Client, domain string, originInit *OriginInit) (*DomainCreatedInfo, error) { +func CreateDomain(cli bce.Client, domain string, originInit *OriginInit, tags []model.TagModel) (*DomainCreatedInfo, error) { urlPath := fmt.Sprintf("/v2/domain/%s", domain) respObj := &DomainCreatedInfo{} - err := httpRequest(cli, "PUT", urlPath, nil, originInit, respObj) + type Request struct { + *OriginInit + Tags []model.TagModel `json:"tags,omitempty"` + } + + requestObject := &Request{ + OriginInit: originInit, + Tags: tags, + } + err := httpRequest(cli, "PUT", urlPath, nil, requestObject, respObj) if err != nil { return nil, err } diff --git a/services/cdn/api/domain_config.go b/services/cdn/api/domain_config.go index 7f773fb..36cf854 100644 --- a/services/cdn/api/domain_config.go +++ b/services/cdn/api/domain_config.go @@ -7,48 +7,50 @@ import ( "strings" "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/model" ) // DomainConfig defined a struct for a specified domain's configuration type DomainConfig struct { - Domain string `json:"domain"` - Cname string `json:"cname"` - Status string `json:"status"` - CreateTime string `json:"createTime"` - LastModifyTime string `json:"lastModifyTime"` - IsBan string `json:"isBan"` - Origin []OriginPeer `json:"origin"` - OriginProtocol *OriginProtocol `json:"originProtocol,omitempty"` - OriginTimeout *OriginTimeout `json:"originTimeout,omitempty"` - OriginFixedISP bool `json:"originFixedISP,omitempty"` - DefaultHost string `json:"defaultHost,omitempty"` - RequestHostAsOriginHost bool `json:"requestHostAsOriginHost"` - CacheTTL []CacheTTL `json:"cacheTTL"` - LimitRate int `json:"limitRate"` - RequestAuth *RequestAuth `json:"requestAuth,omitempty"` - Https *HTTPSConfig `json:"https,omitempty"` - FollowProtocol bool `json:"followProtocol"` - SeoSwitch *SeoSwitch `json:"seoSwitch"` - Form string `json:"form"` - RangeSwitch string `json:"rangeSwitch"` - OfflineMode bool `json:"offlineMode"` - ClientIp *ClientIp `json:"clientIp"` - OCSP bool `json:"ocsp"` - HttpHeader []HttpHeader `json:"httpHeader"` - MediaDragConf *MediaDragConf `json:"mediaDragConf"` - FileTrim bool `json:"fileTrim"` - QUIC bool `json:"quic"` - RefererACL *RefererACL `json:"refererACL"` - IpACL *IpACL `json:"ipACL"` - UaAcl *UaACL `json:"uaAcl"` - AccessLimit *AccessLimit `json:"accessLimit"` - TrafficLimit *TrafficLimit `json:"trafficLimit"` - ErrorPage []ErrorPage `json:"errorPage"` - CacheShare *CacheShared `json:"cacheShare"` - Compress *Compress `json:"compress,omitempty"` - Cors *CorsCfg `json:"cors,omitempty"` - Ipv6Dispatch *Ipv6Dispatch `json:"ipv6Dispatch,omitempty"` - RetryOrigin *RetryOrigin `json:"retryOrigin,omitempty"` + Domain string `json:"domain"` + Cname string `json:"cname"` + Status string `json:"status"` + CreateTime string `json:"createTime"` + LastModifyTime string `json:"lastModifyTime"` + IsBan string `json:"isBan"` + Origin []OriginPeer `json:"origin"` + OriginProtocol *OriginProtocol `json:"originProtocol,omitempty"` + OriginTimeout *OriginTimeout `json:"originTimeout,omitempty"` + OriginFixedISP bool `json:"originFixedISP,omitempty"` + DefaultHost string `json:"defaultHost,omitempty"` + RequestHostAsOriginHost bool `json:"requestHostAsOriginHost"` + CacheTTL []CacheTTL `json:"cacheTTL"` + LimitRate int `json:"limitRate"` + RequestAuth *RequestAuth `json:"requestAuth,omitempty"` + Https *HTTPSConfig `json:"https,omitempty"` + FollowProtocol bool `json:"followProtocol"` + SeoSwitch *SeoSwitch `json:"seoSwitch"` + Form string `json:"form"` + RangeSwitch string `json:"rangeSwitch"` + OfflineMode bool `json:"offlineMode"` + ClientIp *ClientIp `json:"clientIp"` + OCSP bool `json:"ocsp"` + HttpHeader []HttpHeader `json:"httpHeader"` + MediaDragConf *MediaDragConf `json:"mediaDragConf"` + FileTrim bool `json:"fileTrim"` + QUIC bool `json:"quic"` + RefererACL *RefererACL `json:"refererACL"` + IpACL *IpACL `json:"ipACL"` + UaAcl *UaACL `json:"uaAcl"` + AccessLimit *AccessLimit `json:"accessLimit"` + TrafficLimit *TrafficLimit `json:"trafficLimit"` + ErrorPage []ErrorPage `json:"errorPage"` + CacheShare *CacheShared `json:"cacheShare"` + Compress *Compress `json:"compress,omitempty"` + Cors *CorsCfg `json:"cors,omitempty"` + Ipv6Dispatch *Ipv6Dispatch `json:"ipv6Dispatch,omitempty"` + RetryOrigin *RetryOrigin `json:"retryOrigin,omitempty"` + Tags []model.TagModel `json:"tags"` } // CacheTTL defined a struct for cached rules setting @@ -1878,3 +1880,57 @@ func GetContentEncoding(cli bce.Client, domain string) (string, error) { return contentEncoding, nil } + +// SetTags - bind CDN domain with the specified tags. +// For details, please refer https://cloud.baidu.com/doc/CDN/s/ylub1afy6 +// +// PARAMS: +// - cli: the client agent can execute sending request +// - domain: the specified domain +// - tags: identifying CDN domain as something +// RETURNS: +// - error: nil if success otherwise the specific error +func SetTags(cli bce.Client, domain string, tags []model.TagModel) error { + urlPath := fmt.Sprintf("/v2/domain/%s/config", domain) + params := map[string]string{ + "tags": "", + } + err := httpRequest(cli, "PUT", urlPath, params, &struct { + Tags []model.TagModel `json:"tags"` + }{ + Tags: tags, + }, nil) + if err != nil { + return err + } + + return nil +} + +// GetTags - get tags the CDN domain bind with. +// For details, please refer https://cloud.baidu.com/doc/CDN/s/Plub1mrgx +// +// PARAMS: +// - cli: the client agent which can perform sending request +// - domain: the specified domain +// RETURNS: +// - []Tag: tags the CDN domain bind with +// - error: nil if success otherwise the specific error +func GetTags(cli bce.Client, domain string) ([]model.TagModel, error) { + urlPath := fmt.Sprintf("/v2/domain/%s/config", domain) + params := map[string]string{ + "tags": "", + } + + respObj := struct { + Tags []model.TagModel `json:"tags"` + }{} + + err := httpRequest(cli, "GET", urlPath, params, nil, &respObj) + + if err != nil { + return nil, err + } + + return respObj.Tags, nil +} diff --git a/services/cdn/client.go b/services/cdn/client.go index 957fc07..305435d 100644 --- a/services/cdn/client.go +++ b/services/cdn/client.go @@ -3,6 +3,7 @@ package cdn import ( "github.com/baidubce/bce-sdk-go/auth" "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/model" "github.com/baidubce/bce-sdk-go/services/cdn/api" ) @@ -102,17 +103,86 @@ func (cli *Client) IsValidDomain(domain string) (*api.DomainValidInfo, error) { return api.IsValidDomain(cli, domain) } -// CreateDomain - add a specified domain into CDN service +// CreateDomainOption defined a method for setting optional configurations. +type CreateDomainOption func(interface{}) + +// CreateDomainWithTags defined a method for binding a CDN domain with the specified tags. +func CreateDomainWithTags(tags []model.TagModel) CreateDomainOption { + return func(o interface{}) { + cfg, ok := o.(*createDomainOption) + if ok { + cfg.tags = tags + } + } +} + +// CreateDomainWithOriginDefaultHost configure the request header "Host" to origin server. +// It has lower priority, compare with the OriginPeer[i].Host. +func CreateDomainWithOriginDefaultHost(defaultHost string) CreateDomainOption { + return func(o interface{}) { + cfg, ok := o.(*createDomainOption) + if ok { + cfg.defaultHost = defaultHost + } + } +} + +// CreateDomainWithForm configure the form of the CDN domain. +// The follow list the valid forms: +// - default +// - image +// - download +// - media +// If you not call CreateDomainWithForm, the "default" will be used as the form. +func CreateDomainWithForm(form string) CreateDomainOption { + return func(o interface{}) { + cfg, ok := o.(*createDomainOption) + if ok { + cfg.form = form + } + } +} + +type createDomainOption struct { + tags []model.TagModel + defaultHost string + form string +} + +// CreateDomain - create a BCE CDN domain // For details, please refer https://cloud.baidu.com/doc/CDN/s/gjwvyex4o // // PARAMS: // - domain: the specified domain -// - originInit: initialized data for a CDN domain +// - originInit: origin server for a CDN domain // RETURNS: // - *DomainCreatedInfo: the details about created a CDN domain // - error: nil if success otherwise the specific error func (cli *Client) CreateDomain(domain string, originInit *api.OriginInit) (*api.DomainCreatedInfo, error) { - return api.CreateDomain(cli, domain, originInit) + return api.CreateDomain(cli, domain, originInit, nil) +} + +// CreateDomainWithOptions - create a BCE CDN domain with optional configurations. +// For details, please refer https://cloud.baidu.com/doc/CDN/s/gjwvyex4o +// +// PARAMS: +// - domain: the specified domain +// - origins: the origin servers +// - opts: optional configure for a CDN domain, e.g. bind with BCE tags. +// RETURNS: +// - *DomainCreatedInfo: the details about created a CDN domain +// - error: nil if success otherwise the specific error +func (cli *Client) CreateDomainWithOptions(domain string, origins []api.OriginPeer, opts ...CreateDomainOption) (*api.DomainCreatedInfo, error) { + var cfg createDomainOption + for _, opt := range opts { + opt(&cfg) + } + originInit := &api.OriginInit{ + Origin: origins, + DefaultHost: cfg.defaultHost, + Form: cfg.form, + } + return api.CreateDomain(cli, domain, originInit, cfg.tags) } // EnableDomain - enable a specified domain @@ -904,6 +974,30 @@ func (cli *Client) GetContentEncoding(domain string) (string, error) { return api.GetContentEncoding(cli, domain) } +// SetTags - bind CDN domain with the specified tags. +// For details, please refer https://cloud.baidu.com/doc/CDN/s/ylub1afy6 +// +// PARAMS: +// - domain: the specified domain +// - tags: identifying CDN domain as something +// RETURNS: +// - error: nil if success otherwise the specific error +func (cli *Client) SetTags(domain string, tags []model.TagModel) error { + return api.SetTags(cli, domain, tags) +} + +// GetTags - get tags the CDN domain bind with. +// For details, please refer https://cloud.baidu.com/doc/CDN/s/Plub1mrgx +// +// PARAMS: +// - domain: the specified domain +// RETURNS: +// - []Tag: tags the CDN domain bind with +// - error: nil if success otherwise the specific error +func (cli *Client) GetTags(domain string) ([]model.TagModel, error) { + return api.GetTags(cli, domain) +} + // Purge - tells the CDN system to purge the specified files // For more details, please refer https://cloud.baidu.com/doc/CDN/s/ijwvyeyyj // diff --git a/services/cdn/client_test.go b/services/cdn/client_test.go index d3598e6..bdf50a6 100644 --- a/services/cdn/client_test.go +++ b/services/cdn/client_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/model" "github.com/baidubce/bce-sdk-go/services/cdn/api" "github.com/baidubce/bce-sdk-go/util" ) @@ -143,7 +144,7 @@ func TestCreateDomain(t *testing.T) { Origin: []api.OriginPeer{ { Peer: "1.2.3.4", - Host: "1.2.3.4", + Host: "www.baidu.com", }, }, }) @@ -152,6 +153,27 @@ func TestCreateDomain(t *testing.T) { checkClientErr(t, "CreateDomain", err) } +func TestCreateDomainWithTags(t *testing.T) { + domainCreatedInfo, err := testCli.CreateDomainWithOptions("0307-001.qq.com", []api.OriginPeer{ + { + Peer: "1.2.3.4", + Host: "www.baidu.com", + }, + }, CreateDomainWithTags([]model.TagModel{ + { + TagKey: "service", + TagValue: "web", + }, + { + TagKey: "域名类型", + TagValue: "网站服务", + }, + }), CreateDomainWithForm("image"), CreateDomainWithOriginDefaultHost("origin.baidu.com")) + + t.Logf("domainCreatedInfo: %v", domainCreatedInfo) + checkClientErr(t, "CreateDomain", err) +} + func TestDisableDomain(t *testing.T) { err := testCli.DisableDomain(testAuthorityDomain) checkClientErr(t, "DisableDomain", err) @@ -716,6 +738,22 @@ func TestGetContentEncoding(t *testing.T) { checkClientErr(t, "GetContentEncoding", err) } +func TestSetTags(t *testing.T) { + err := testCli.SetTags(testAuthorityDomain, []model.TagModel{ + { + TagKey: "service", + TagValue: "download", + }, + }) + checkClientErr(t, "SetTags", err) +} + +func TestGetTags(t *testing.T) { + tags, err := testCli.GetTags(testAuthorityDomain) + t.Logf("tags: %+v", tags) + checkClientErr(t, "GetContentEncoding", err) +} + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Test function about purge/prefetch. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////