Skip to content

Commit b29140a

Browse files
authored
feat: add GetProjectCrossRegion method and update LogProject struct with new endpoint fields (#375)
1 parent 1f69f19 commit b29140a

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

client.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,31 @@ func (c *Client) GetProject(name string) (*LogProject, error) {
292292
return proj, err
293293
}
294294

295+
// GetProjectCrossRegion gets project information with cross-region lookup enabled.
296+
// This API is available only in some regions.
297+
func (c *Client) GetProjectCrossRegion(name string) (*LogProject, error) {
298+
h := map[string]string{
299+
"x-log-bodyrawsize": "0",
300+
}
301+
302+
uri := "/?crossRegion=true"
303+
proj := convert(c, name)
304+
resp, err := request(proj, "GET", uri, h, nil)
305+
if err != nil {
306+
return nil, NewClientError(err)
307+
}
308+
defer resp.Body.Close()
309+
buf, err := ioutil.ReadAll(resp.Body)
310+
if err != nil {
311+
return nil, readResponseError(err)
312+
}
313+
if resp.StatusCode != http.StatusOK {
314+
return nil, httpStatusNotOkError(buf, resp.Header, resp.StatusCode)
315+
}
316+
err = json.Unmarshal(buf, proj)
317+
return proj, err
318+
}
319+
295320
// ListProject list all projects in specific region
296321
// the region is related with the client's endpoint
297322
func (c *Client) ListProject() (projectNames []string, err error) {

client_interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ type ClientInterface interface {
102102
// CreateProject create a new loghub project, with dataRedundancyType option.
103103
CreateProjectV2(name, description, dataRedundancyType string) (*LogProject, error)
104104
GetProject(name string) (*LogProject, error)
105+
// GetProjectCrossRegion is available only in some regions.
106+
GetProjectCrossRegion(name string) (*LogProject, error)
105107
// UpdateProject create a new loghub project.
106108
UpdateProject(name, description string) (*LogProject, error)
107109
// ListProject list all projects in specific region

log_project.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ type LogProject struct {
4646
LastModifyTime string `json:"lastModifyTime"` // unix time seconds, eg 1524539357
4747
DataRedundancyType string `json:"dataRedundancyType,omitempty"` // data redundancy type, valid values: ['LRS', 'ZRS']
4848
Location string `json:"location,omitempty"` // location, eg. cn-beijing-b
49+
InternetEndpoint string `json:"internetEndpoint,omitempty"` // public endpoint
50+
InternalEndpoint string `json:"internalEndpoint,omitempty"` // internal endpoint
51+
ShareEndpoint string `json:"shareEndpoint,omitempty"` // share endpoint
4952

5053
Endpoint string // Deprecated: will be made private in the next version
5154
AccessKeyID string // Deprecated: will be made private in the next version

token_auto_update_client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ func (c *TokenAutoUpdateClient) GetProject(name string) (prj *LogProject, err er
211211
return
212212
}
213213

214+
// GetProjectCrossRegion gets project information with cross-region lookup enabled.
215+
// This API is available only in some regions.
216+
func (c *TokenAutoUpdateClient) GetProjectCrossRegion(name string) (prj *LogProject, err error) {
217+
for i := 0; i < c.maxTryTimes; i++ {
218+
prj, err = c.logClient.GetProjectCrossRegion(name)
219+
if !c.processError(err) {
220+
return
221+
}
222+
}
223+
return
224+
}
225+
214226
func (c *TokenAutoUpdateClient) ListProject() (projectNames []string, err error) {
215227
for i := 0; i < c.maxTryTimes; i++ {
216228
projectNames, err = c.logClient.ListProject()

0 commit comments

Comments
 (0)