[v9.3.x] CloudWatch: Cross-account querying support (#59389)
* add cross-account querying support * fix tests
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const defaultLogGroupLimit = int64(50)
|
||||
|
||||
type LogGroupsRequest struct {
|
||||
ResourceRequest
|
||||
Limit int64
|
||||
LogGroupNamePrefix, LogGroupNamePattern *string
|
||||
}
|
||||
|
||||
func (r LogGroupsRequest) IsTargetingAllAccounts() bool {
|
||||
return *r.AccountId == "all"
|
||||
}
|
||||
|
||||
func ParseLogGroupsRequest(parameters url.Values) (LogGroupsRequest, error) {
|
||||
logGroupNamePrefix := setIfNotEmptyString(parameters.Get("logGroupNamePrefix"))
|
||||
logGroupPattern := setIfNotEmptyString(parameters.Get("logGroupPattern"))
|
||||
if logGroupNamePrefix != nil && logGroupPattern != nil {
|
||||
return LogGroupsRequest{}, fmt.Errorf("cannot set both log group name prefix and pattern")
|
||||
}
|
||||
|
||||
return LogGroupsRequest{
|
||||
Limit: getLimit(parameters.Get("limit")),
|
||||
ResourceRequest: ResourceRequest{
|
||||
Region: parameters.Get("region"),
|
||||
AccountId: setIfNotEmptyString(parameters.Get("accountId")),
|
||||
},
|
||||
LogGroupNamePrefix: logGroupNamePrefix,
|
||||
LogGroupNamePattern: logGroupPattern,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func setIfNotEmptyString(paramValue string) *string {
|
||||
if paramValue == "" {
|
||||
return nil
|
||||
}
|
||||
return ¶mValue
|
||||
}
|
||||
|
||||
func getLimit(limit string) int64 {
|
||||
logGroupLimit := defaultLogGroupLimit
|
||||
intLimit, err := strconv.ParseInt(limit, 10, 64)
|
||||
if err == nil && intLimit > 0 {
|
||||
logGroupLimit = intLimit
|
||||
}
|
||||
return logGroupLimit
|
||||
}
|
||||
Reference in New Issue
Block a user