diff --git a/bce/config.go b/bce/config.go index 90cbb873..aac4a9d5 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.206" + SDK_VERSION = "0.9.207" URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path DEFAULT_DOMAIN = "baidubce.com" DEFAULT_PROTOCOL = "http" diff --git a/doc/RES_MANAGER.md b/doc/RES_MANAGER.md index 128ece61..aea8f664 100644 --- a/doc/RES_MANAGER.md +++ b/doc/RES_MANAGER.md @@ -224,6 +224,7 @@ ExpireSeconds | int | 签名字符串的有效期 - 变更资源绑定的资源分组 - 查询资源分组列表 - 资源ID查询资源资源分组 +- 创建资源分组 ### 资源加入资源分组 @@ -370,6 +371,29 @@ if err != nil { > 2. 仅能查询当前账号资源,也就是根据AK, SK签名解析的账号下的资源。 > 3. 接口详细描述请参考资源管理[API文档](https://cloud.baidu.com/doc/ResManagement/s/ilth0vmb9)。 +### 创建资源分组 + +使用以下代码创建资源分组 +```go +args := &CreateResourceGroupArgs{ + // 资源组名称 + Name: "资源组名称", + // 资源组的备注 + Extra: "备注", +} + +result, err := client.CreateResourceGroup(args) +if err != nil { + fmt.Println("CreateResourceGroup failed:", err) +} else { + fmt.Println("CreateResourceGroup success: ", result) +} +``` + +> **提示:** +> 1. 接口详细描述请参考资源管理[API文档](https://cloud.baidu.com/doc/ResManagement/s/ilth0vmb9)。 +> 2. 资源组的名称,同一用户下不能重复,支持中英文及常见符号-_ /.,1~20个字符,必填。 +> 3. 资源组的备注,可以为空。最多存储 256 个字符的文本。 # 错误处理 @@ -409,4 +433,7 @@ if err != nil { 首次发布: - 资源加入资源分组、资源从资源分组移除、变更资源绑定的资源分组、查询资源分组列表 -- 资源ID查询资源资源分组 \ No newline at end of file +- 资源ID查询资源资源分组 + +## v0.9.207 [2024-12-16] +- 创建资源分组 \ No newline at end of file diff --git a/services/resmanager/client.go b/services/resmanager/client.go index fca3c287..d6b60d7a 100644 --- a/services/resmanager/client.go +++ b/services/resmanager/client.go @@ -43,6 +43,10 @@ func NewClient(ak, sk, endPoint string) (*Client, error) { return &Client{client}, nil } +func getCreateGroupUri() string { + return URI_PREFIX + REQUEST_QUERY_GROUP +} + func getChangeGroupUri() string { return URI_PREFIX + REQUEST_CHANGE_GROUP } diff --git a/services/resmanager/client_test.go b/services/resmanager/client_test.go index cf692e6f..5e2ced5f 100644 --- a/services/resmanager/client_test.go +++ b/services/resmanager/client_test.go @@ -159,6 +159,17 @@ func TestBindResourceToGroup(t *testing.T) { t.Logf(string(jsonRes)) } +func TestCreateResourceGroup(t *testing.T) { + args := &CreateResourceGroupArgs{ + // 资源组名称 + Name: "资源组名称", + // 资源组的备注 + Extra: "备注", + } + err := resClient.CreateResourceGroup(args) + ExpectEqual(t.Errorf, err, nil) +} + func TestChangeResourceGroup(t *testing.T) { args := &ChangeResourceGroupArgs{ MoveResModels: []MoveResModel{ diff --git a/services/resmanager/model.go b/services/resmanager/model.go index 82c6223a..3c0b5687 100644 --- a/services/resmanager/model.go +++ b/services/resmanager/model.go @@ -94,6 +94,11 @@ type BindResourceResult struct { ResGroups []ResGroup `json:"resGroups"` } +type CreateResourceGroupArgs struct { + Name string `json:"name"` + Extra string `json:"extra"` +} + type ChangeResourceGroupArgs struct { MoveResModels []MoveResModel `json:"moveResModels"` } diff --git a/services/resmanager/resmanager.go b/services/resmanager/resmanager.go index 50595525..1710c680 100644 --- a/services/resmanager/resmanager.go +++ b/services/resmanager/resmanager.go @@ -45,6 +45,25 @@ func (c *Client) BindResourceToGroup(args *BindResourceToGroupArgs) (*BindResour return result, err } +func (c *Client) CreateResourceGroup(args *CreateResourceGroupArgs) error { + if args == nil { + return fmt.Errorf("unset args") + } + + if len(args.Name) == 0 { + return fmt.Errorf("unset name") + } + + err := bce.NewRequestBuilder(c). + WithMethod(http.POST). + WithURL(getCreateGroupUri()). + WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE). + WithBody(args). + Do() + + return err +} + func (c *Client) ChangeResourceGroup(args *ChangeResourceGroupArgs) (*BindResourceResult, error) { if args == nil { return nil, fmt.Errorf("unset args")