Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project add field DataRedundancyType #218

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions client_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 15 additions & 7 deletions log_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 10 additions & 0 deletions token_auto_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down
Loading