mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9967 from ioito/automated-cherry-pick-of-#9966-upstream-release-3.7
Automated cherry pick of #9966: fix(cloudevent): update aliyun lookupevent api
This commit is contained in:
@@ -50,7 +50,7 @@ const (
|
||||
ALIYUN_API_VERSION_LB = "2014-05-15"
|
||||
ALIYUN_API_VERSION_KVS = "2015-01-01"
|
||||
|
||||
ALIYUN_API_VERSION_TRIAL = "2017-12-04"
|
||||
ALIYUN_API_VERSION_TRIAL = "2020-07-06"
|
||||
|
||||
ALIYUN_BSS_API_VERSION = "2017-12-14"
|
||||
|
||||
@@ -269,14 +269,6 @@ func (self *SAliyunClient) ecsRequest(apiName string, params map[string]string)
|
||||
return jsonRequest(cli, "ecs.aliyuncs.com", ALIYUN_API_VERSION, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) trialRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
cli, err := self.getDefaultClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return jsonRequest(cli, "actiontrail.cn-hangzhou.aliyuncs.com", ALIYUN_API_VERSION_TRIAL, apiName, params, self.debug)
|
||||
}
|
||||
|
||||
func (self *SAliyunClient) pvtzRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
cli, err := self.getDefaultClient()
|
||||
if err != nil {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
@@ -64,6 +65,7 @@ type SEvent struct {
|
||||
UserAgent string
|
||||
UserIdentity SUserIdentity
|
||||
ResponseElements map[string]string
|
||||
IsGlobal bool
|
||||
}
|
||||
|
||||
func (event *SEvent) GetCreatedAt() time.Time {
|
||||
@@ -120,7 +122,7 @@ func (region *SRegion) GetICloudEvents(start time.Time, end time.Time, withReadE
|
||||
|
||||
eventRW = "Write"
|
||||
if withReadEvent {
|
||||
eventRW = "All"
|
||||
eventRW = ""
|
||||
}
|
||||
|
||||
for {
|
||||
@@ -135,10 +137,11 @@ func (region *SRegion) GetICloudEvents(start time.Time, end time.Time, withReadE
|
||||
}
|
||||
|
||||
for i := range events {
|
||||
if !withReadEvent {
|
||||
if strings.HasPrefix(events[i].EventName, "Query") {
|
||||
continue
|
||||
}
|
||||
if events[i].IsGlobal && region.RegionId != ALIYUN_DEFAULT_REGION {
|
||||
continue
|
||||
}
|
||||
if !withReadEvent && strings.HasPrefix(events[i].EventName, "Query") { // QueryInstanceBill QueryBill
|
||||
continue
|
||||
}
|
||||
iEvents = append(iEvents, &events[i])
|
||||
}
|
||||
@@ -146,10 +149,6 @@ func (region *SRegion) GetICloudEvents(start time.Time, end time.Time, withReadE
|
||||
}
|
||||
|
||||
func (region *SRegion) GetEvents(start time.Time, end time.Time, token string, eventRW string, requestId string) ([]SEvent, string, error) {
|
||||
if region.RegionId != EVENT_REGION_HANGZHOU {
|
||||
return []SEvent{}, "", nil
|
||||
}
|
||||
|
||||
params := map[string]string{
|
||||
"RegionId": region.RegionId,
|
||||
}
|
||||
@@ -159,8 +158,9 @@ func (region *SRegion) GetEvents(start time.Time, end time.Time, token string, e
|
||||
if !end.IsZero() {
|
||||
params["EndTime"] = end.Format("2006-01-02T15:04:05Z")
|
||||
}
|
||||
if len(eventRW) > 0 {
|
||||
params["EventRW"] = eventRW
|
||||
if utils.IsInStringArray(eventRW, []string{"Read", "Write"}) {
|
||||
params["LookupAttribute.1.Key"] = "EventRW"
|
||||
params["LookupAttribute.1.Value"] = eventRW
|
||||
}
|
||||
if len(token) > 0 {
|
||||
params["NextToken"] = token
|
||||
@@ -168,8 +168,11 @@ func (region *SRegion) GetEvents(start time.Time, end time.Time, token string, e
|
||||
if len(requestId) > 0 {
|
||||
params["Request"] = requestId
|
||||
}
|
||||
resp, err := region.client.trialRequest("LookupEvents", params)
|
||||
resp, err := region.trialRequest("LookupEvents", params)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no such host") { // cn-wulanchabu not support
|
||||
return []SEvent{}, "", nil
|
||||
}
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -1167,3 +1167,12 @@ func (self *SRegion) GetIElasticcaches() ([]cloudprovider.ICloudElasticcache, er
|
||||
func (region *SRegion) GetCapabilities() []string {
|
||||
return region.client.GetCapabilities()
|
||||
}
|
||||
|
||||
func (self *SRegion) trialRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
client, err := self.getSdkClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
domain := fmt.Sprintf("actiontrail.%s.aliyuncs.com", self.RegionId)
|
||||
return jsonRequest(client, domain, ALIYUN_API_VERSION_TRIAL, apiName, params, self.client.debug)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user