diff --git a/client.go b/client.go index 5479c231..f5426ab6 100644 --- a/client.go +++ b/client.go @@ -169,13 +169,20 @@ func (c *Client) ResetAccessKeyToken(accessKeyID, accessKeySecret, securityToken // CreateProject create a new loghub project. func (c *Client) CreateProject(name, description string) (*LogProject, error) { + return c.CreateProjectV2(name, description, "") +} + +// CreateProjectV2 create a new loghub project, with dataRedundancyType option. +func (c *Client) CreateProjectV2(name, description, dataRedundancyType string) (*LogProject, error) { type Body struct { - ProjectName string `json:"projectName"` - Description string `json:"description"` + ProjectName string `json:"projectName"` + Description string `json:"description"` + DataRedundancyType string `json:"dataRedundancyType,omitempty"` } body, err := json.Marshal(Body{ - ProjectName: name, - Description: description, + ProjectName: name, + Description: description, + DataRedundancyType: dataRedundancyType, }) if err != nil { return nil, err diff --git a/client_interface.go b/client_interface.go index 1ba9b85f..8f33b881 100644 --- a/client_interface.go +++ b/client_interface.go @@ -58,6 +58,8 @@ type ClientInterface interface { // #################### Project Operations ##################### // CreateProject create a new loghub project. CreateProject(name, description string) (*LogProject, error) + // CreateProject create a new loghub project, with dataRedundancyType option. + CreateProjectV2(name, description, dataRedundancyType string) (*LogProject, error) GetProject(name string) (*LogProject, error) // UpdateProject create a new loghub project. UpdateProject(name, description string) (*LogProject, error) diff --git a/log_project.go b/log_project.go index b945cc48..25a16e37 100644 --- a/log_project.go +++ b/log_project.go @@ -27,15 +27,23 @@ var ( // this file is deprecated and no maintenance // see client_project.go +// DataRedundancyType +const ( + PROJECT_DATA_REDUNDANCY_TYPE_UNKNOWN = "Unknown" + PROJECT_DATA_REDUNDANCY_TYPE_LRS = "LRS" + PROJECT_DATA_REDUNDANCY_TYPE_ZRS = "ZRS" +) + // LogProject defines log project type LogProject struct { - Name string `json:"projectName"` // Project name - Description string `json:"description"` // Project description - Status string `json:"status"` // Normal - Owner string `json:"owner"` // empty - Region string `json:"region"` // region id, eg cn-shanghai - CreateTime string `json:"createTime"` // unix time seconds, eg 1524539357 - LastModifyTime string `json:"lastModifyTime"` // unix time seconds, eg 1524539357 + Name string `json:"projectName"` // Project name + Description string `json:"description"` // Project description + Status string `json:"status"` // Normal + Owner string `json:"owner"` // empty + Region string `json:"region"` // region id, eg cn-shanghai + CreateTime string `json:"createTime"` // unix time seconds, eg 1524539357 + LastModifyTime string `json:"lastModifyTime"` // unix time seconds, eg 1524539357 + DataRedundancyType string `json:"dataRedundancyType,omitempty"` // data redundancy type, valid values: ['LRS', 'ZRS'] Endpoint string // IP or hostname of SLS endpoint AccessKeyID string diff --git a/project_test.go b/project_test.go index 2bb328c8..960f5d6c 100644 --- a/project_test.go +++ b/project_test.go @@ -97,3 +97,17 @@ func (s *ProjectTestSuite) TestUpdateProject() { _, err := s.client.UpdateProject(s.projectName, "aliyun log go sdk test.") s.Nil(err) } + +func (s *ProjectTestSuite) TestCreateProjectV2() { + + _, _ = s.client.GetProject(s.projectName) + v2 := s.projectName + "v2" + _, err := s.client.CreateProjectV2(v2, "test-project-v2", PROJECT_DATA_REDUNDANCY_TYPE_ZRS) + s.NoError(err) + proj, err := s.client.GetProject(v2) + s.NoError(err) + fmt.Println(proj.Name) + s.Equal(proj.DataRedundancyType, PROJECT_DATA_REDUNDANCY_TYPE_ZRS) + err = s.client.DeleteProject(v2) + s.NoError(err) +} diff --git a/token_auto_update_client.go b/token_auto_update_client.go index 25d6504c..c68d3677 100644 --- a/token_auto_update_client.go +++ b/token_auto_update_client.go @@ -175,6 +175,16 @@ func (c *TokenAutoUpdateClient) CreateProject(name, description string) (prj *Lo return } +func (c *TokenAutoUpdateClient) CreateProjectV2(name, description, dataRedundancyType string) (prj *LogProject, err error) { + for i := 0; i < c.maxTryTimes; i++ { + prj, err = c.logClient.CreateProjectV2(name, description, dataRedundancyType) + if !c.processError(err) { + return + } + } + return +} + // UpdateProject create a new loghub project. func (c *TokenAutoUpdateClient) UpdateProject(name, description string) (prj *LogProject, err error) { for i := 0; i < c.maxTryTimes; i++ {