fix(cloudevent): add aws cloudevent

This commit is contained in:
Qu Xuan
2021-01-11 11:25:28 +08:00
parent f6f975709a
commit e91b5dbc32
13 changed files with 8666 additions and 8 deletions
+2 -2
View File
@@ -141,11 +141,11 @@ require (
k8s.io/apimachinery v0.19.3
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
yunion.io/x/executor v0.0.0-20201201131200-44fa553abd9e
yunion.io/x/executor v0.0.0-20201231064744-df32f32165a9
yunion.io/x/jsonutils v0.0.0-20201110084044-3e4e1cb49769
yunion.io/x/log v0.0.0-20201210064738-43181789dc74
yunion.io/x/ovsdb v0.0.0-20200526071744-27bf0940cbc7
yunion.io/x/pkg v0.0.0-20201123083159-ca3aea986ff2
yunion.io/x/pkg v0.0.0-20210109071527-7e72daf56747
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v0.0.0-20201219153152-2d901261898c
yunion.io/x/structarg v0.0.0-20200720093445-9f850fa222ce
+4 -4
View File
@@ -918,8 +918,8 @@ sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/executor v0.0.0-20201201131200-44fa553abd9e h1:NRtqiegW4NME0v10rpChORZnJnuAUbpv31R5DsqqczQ=
yunion.io/x/executor v0.0.0-20201201131200-44fa553abd9e/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/executor v0.0.0-20201231064744-df32f32165a9 h1:TyKy58HHgjkTJYrZgD0haz4bItoC+QwcOQ+GtMuGTjw=
yunion.io/x/executor v0.0.0-20201231064744-df32f32165a9/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
yunion.io/x/jsonutils v0.0.0-20201110084044-3e4e1cb49769 h1:LIQ4hhLGQuQK+XxlV+8JrKBuL37WUT+5ZTVxBwHOTD4=
yunion.io/x/jsonutils v0.0.0-20201110084044-3e4e1cb49769/go.mod h1:p0nyMqGA/apTxxyLIU/o1k4V7Vujl2O6ey30L594sYE=
@@ -933,8 +933,8 @@ yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZV
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6 h1:UarEDTBGkgcgc+nc+PZ75uo9M9+jiOGd5P2B90TxDNw=
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20201123083159-ca3aea986ff2 h1:NeCr2J8HjcIuJvEhP0rwWA1UKP8ReOv6HVf5k9YPtyA=
yunion.io/x/pkg v0.0.0-20201123083159-ca3aea986ff2/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20210109071527-7e72daf56747 h1:sTr6mjWW8aAMKkrnnU2SG8EqhLRl/D3rGnBhaP2ksTI=
yunion.io/x/pkg v0.0.0-20210109071527-7e72daf56747/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v0.0.0-20201219153152-2d901261898c h1:71nVDQq1oUjvZknEUNfetdiOB1jZMEfmoQlMUaoPIJs=
+9
View File
@@ -249,6 +249,15 @@ func (client *SAwsClient) getAwsRoute53Session() (*session.Session, error) {
return session, nil
}
func (client *SAwsClient) getAwsCloudtrailSession() (*session.Session, error) {
session, err := client.getDefaultSession()
if err != nil {
return nil, errors.Wrap(err, "client.getDefaultSession()")
}
session.ClientConfig(CLOUD_TRAIL_SERVICE_NAME)
return session, nil
}
func (self *SAwsClient) invalidateIBuckets() {
self.iBuckets = nil
}
+173
View File
@@ -0,0 +1,173 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package aws
import (
"fmt"
"strings"
"time"
"github.com/aws/aws-sdk-go/service/cloudtrail"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/cloudprovider"
)
type SEventResource struct {
// The name of the resource referenced by the event returned. These are user-created
// names whose values will depend on the environment. For example, the resource
// name might be "auto-scaling-test-group" for an Auto Scaling Group or "i-1234567"
// for an EC2 Instance.
ResourceName string `type:"string"`
// The type of a resource referenced by the event returned. When the resource
// type cannot be determined, null is returned. Some examples of resource types
// are: Instance for EC2, Trail for CloudTrail, DBInstance for RDS, and AccessKey
// for IAM. To learn more about how to look up and filter events by the resource
// types supported for a service, see Filtering CloudTrail Events (https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events-console.html#filtering-cloudtrail-events).
ResourceType string `type:"string"`
}
type SEvent struct {
// The AWS access key ID that was used to sign the request. If the request was
// made with temporary security credentials, this is the access key ID of the
// temporary credentials.
AccessKeyId string `type:"string"`
// A JSON string that contains a representation of the event returned.
CloudTrailEvent string `type:"string"`
// The CloudTrail ID of the event returned.
EventId string `type:"string"`
// The name of the event returned.
EventName string `type:"string"`
// The AWS service that the request was made to.
EventSource string `type:"string"`
// The date and time of the event returned.
EventTime time.Time `type:"timestamp"`
// Information about whether the event is a write event or a read event.
ReadOnly string `type:"string"`
// A list of resources referenced by the event returned.
Resources []SEventResource `type:"list"`
// A user name or role name of the requester that called the API in the event
// returned.
Username string `type:"string"`
}
func (self *SEvent) GetName() string {
return self.EventName
}
func (self *SEvent) GetService() string {
return self.EventSource
}
func (self *SEvent) GetAction() string {
return self.EventName
}
func (self *SEvent) GetResourceType() string {
return self.EventSource
}
func (self *SEvent) GetRequestId() string {
return self.EventId
}
func (self *SEvent) GetRequest() jsonutils.JSONObject {
obj, _ := jsonutils.Parse([]byte(self.CloudTrailEvent))
return obj
}
func (self *SEvent) GetAccount() string {
return fmt.Sprintf("%s(%s)", self.AccessKeyId, self.Username)
}
func (self *SEvent) IsSuccess() bool {
return !strings.Contains(self.CloudTrailEvent, "errorMessage")
}
func (self *SEvent) GetCreatedAt() time.Time {
return self.EventTime
}
func (self *SAwsClient) LookupEvents(start, end time.Time) ([]SEvent, error) {
s, err := self.getAwsCloudtrailSession()
if err != nil {
return nil, errors.Wrapf(err, "getAwsCloudtrailSession")
}
client := cloudtrail.New(s)
input := &cloudtrail.LookupEventsInput{}
if !start.IsZero() {
input.SetStartTime(start)
}
if !end.IsZero() {
input.SetEndTime(end)
}
events := []SEvent{}
nextToken := ""
for {
if len(nextToken) > 0 {
input.SetNextToken(nextToken)
}
output, err := client.LookupEvents(input)
if err != nil {
return nil, errors.Wrapf(err, "LookupEvents")
}
for i := range output.Events {
err := FillZero(output.Events[i])
if err != nil {
return nil, errors.Wrapf(err, "FillZero")
}
event := SEvent{}
err = jsonutils.Update(&event, jsonutils.Marshal(output.Events[i]))
if err != nil {
return nil, errors.Wrapf(err, "jsonutils.Update")
}
events = append(events, event)
}
nextToken = ""
if output.NextToken != nil {
nextToken = *output.NextToken
}
if len(nextToken) == 0 {
break
}
}
return events, nil
}
func (self *SRegion) GetICloudEvents(start time.Time, end time.Time, withReadEvent bool) ([]cloudprovider.ICloudEvent, error) {
events, err := self.client.LookupEvents(start, end)
if err != nil {
return nil, errors.Wrapf(err, "LookupEvents(%s, %s)", start, end)
}
ret := []cloudprovider.ICloudEvent{}
for i := range events {
if !withReadEvent && events[i].ReadOnly == "true" {
continue
}
ret = append(ret, &events[i])
}
return ret, nil
}
+12
View File
@@ -39,6 +39,18 @@ func (self *SAwsProviderFactory) GetName() string {
return aws.CLOUD_PROVIDER_AWS_CN
}
func (self *SAwsProviderFactory) IsCloudeventRegional() bool {
return true
}
func (self *SAwsProviderFactory) GetMaxCloudEventSyncDays() int {
return 1
}
func (self *SAwsProviderFactory) GetMaxCloudEventKeepDays() int {
return 90
}
func (self *SAwsProviderFactory) IsSupportPrepaidResources() bool {
return false
}
+3
View File
@@ -116,6 +116,9 @@ const (
CLOUDWATCH_SERVICE_NAME = "monitoring"
CLOUDWATCH_SERVICE_ID = "CloudWatch"
CLOUD_TRAIL_SERVICE_NAME = "CloudTrail"
CLOUD_TRAIL_SERVICE_ID = "cloudtrail"
ROUTE53_SERVICE_NAME = "route53"
)
+37
View File
@@ -0,0 +1,37 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shell
import (
"time"
"yunion.io/x/onecloud/pkg/multicloud/aws"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
func init() {
type EventListOptions struct {
Start time.Time
End time.Time
}
shellutils.R(&EventListOptions{}, "event-list", "List events", func(cli *aws.SRegion, args *EventListOptions) error {
events, err := cli.GetClient().LookupEvents(args.Start, args.End)
if err != nil {
return err
}
printList(events, 0, 0, 0, []string{})
return nil
})
}
File diff suppressed because it is too large Load Diff
+48
View File
@@ -0,0 +1,48 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// Package cloudtrail provides the client and types for making API
// requests to AWS CloudTrail.
//
// This is the CloudTrail API Reference. It provides descriptions of actions,
// data types, common parameters, and common errors for CloudTrail.
//
// CloudTrail is a web service that records AWS API calls for your AWS account
// and delivers log files to an Amazon S3 bucket. The recorded information includes
// the identity of the user, the start time of the AWS API call, the source
// IP address, the request parameters, and the response elements returned by
// the service.
//
// As an alternative to the API, you can use one of the AWS SDKs, which consist
// of libraries and sample code for various programming languages and platforms
// (Java, Ruby, .NET, iOS, Android, etc.). The SDKs provide a convenient way
// to create programmatic access to AWSCloudTrail. For example, the SDKs take
// care of cryptographically signing requests, managing errors, and retrying
// requests automatically. For information about the AWS SDKs, including how
// to download and install them, see the Tools for Amazon Web Services page
// (http://aws.amazon.com/tools/).
//
// See the AWS CloudTrail User Guide (https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html)
// for information about the data that is included with each AWS API call listed
// in the log files.
//
// See https://docs.aws.amazon.com/goto/WebAPI/cloudtrail-2013-11-01 for more information on this service.
//
// See cloudtrail package documentation for more information.
// https://docs.aws.amazon.com/sdk-for-go/api/service/cloudtrail/
//
// Using the Client
//
// To contact AWS CloudTrail with the SDK use the New function to create
// a new service client. With that client you can make API requests to the service.
// These clients are safe to use concurrently.
//
// See the SDK's documentation for more information on how to use the SDK.
// https://docs.aws.amazon.com/sdk-for-go/api/
//
// See aws.Config documentation for more information on configuring SDK clients.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
//
// See the AWS CloudTrail client CloudTrail for more
// information on creating client for this service.
// https://docs.aws.amazon.com/sdk-for-go/api/service/cloudtrail/#New
package cloudtrail
+369
View File
@@ -0,0 +1,369 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package cloudtrail
import (
"github.com/aws/aws-sdk-go/private/protocol"
)
const (
// ErrCodeARNInvalidException for service response error code
// "CloudTrailARNInvalidException".
//
// This exception is thrown when an operation is called with an invalid trail
// ARN. The format of a trail ARN is:
//
// arn:aws:cloudtrail:us-east-2:123456789012:trail/MyTrail
ErrCodeARNInvalidException = "CloudTrailARNInvalidException"
// ErrCodeAccessNotEnabledException for service response error code
// "CloudTrailAccessNotEnabledException".
//
// This exception is thrown when trusted access has not been enabled between
// AWS CloudTrail and AWS Organizations. For more information, see Enabling
// Trusted Access with Other AWS Services (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_integrate_services.html)
// and Prepare For Creating a Trail For Your Organization (https://docs.aws.amazon.com/awscloudtrail/latest/userguide/creating-an-organizational-trail-prepare.html).
ErrCodeAccessNotEnabledException = "CloudTrailAccessNotEnabledException"
// ErrCodeCloudWatchLogsDeliveryUnavailableException for service response error code
// "CloudWatchLogsDeliveryUnavailableException".
//
// Cannot set a CloudWatch Logs delivery for this region.
ErrCodeCloudWatchLogsDeliveryUnavailableException = "CloudWatchLogsDeliveryUnavailableException"
// ErrCodeInsightNotEnabledException for service response error code
// "InsightNotEnabledException".
//
// If you run GetInsightSelectors on a trail that does not have Insights events
// enabled, the operation throws the exception InsightNotEnabledException.
ErrCodeInsightNotEnabledException = "InsightNotEnabledException"
// ErrCodeInsufficientDependencyServiceAccessPermissionException for service response error code
// "InsufficientDependencyServiceAccessPermissionException".
//
// This exception is thrown when the IAM user or role that is used to create
// the organization trail is lacking one or more required permissions for creating
// an organization trail in a required service. For more information, see Prepare
// For Creating a Trail For Your Organization (https://docs.aws.amazon.com/awscloudtrail/latest/userguide/creating-an-organizational-trail-prepare.html).
ErrCodeInsufficientDependencyServiceAccessPermissionException = "InsufficientDependencyServiceAccessPermissionException"
// ErrCodeInsufficientEncryptionPolicyException for service response error code
// "InsufficientEncryptionPolicyException".
//
// This exception is thrown when the policy on the S3 bucket or KMS key is not
// sufficient.
ErrCodeInsufficientEncryptionPolicyException = "InsufficientEncryptionPolicyException"
// ErrCodeInsufficientS3BucketPolicyException for service response error code
// "InsufficientS3BucketPolicyException".
//
// This exception is thrown when the policy on the S3 bucket is not sufficient.
ErrCodeInsufficientS3BucketPolicyException = "InsufficientS3BucketPolicyException"
// ErrCodeInsufficientSnsTopicPolicyException for service response error code
// "InsufficientSnsTopicPolicyException".
//
// This exception is thrown when the policy on the SNS topic is not sufficient.
ErrCodeInsufficientSnsTopicPolicyException = "InsufficientSnsTopicPolicyException"
// ErrCodeInvalidCloudWatchLogsLogGroupArnException for service response error code
// "InvalidCloudWatchLogsLogGroupArnException".
//
// This exception is thrown when the provided CloudWatch log group is not valid.
ErrCodeInvalidCloudWatchLogsLogGroupArnException = "InvalidCloudWatchLogsLogGroupArnException"
// ErrCodeInvalidCloudWatchLogsRoleArnException for service response error code
// "InvalidCloudWatchLogsRoleArnException".
//
// This exception is thrown when the provided role is not valid.
ErrCodeInvalidCloudWatchLogsRoleArnException = "InvalidCloudWatchLogsRoleArnException"
// ErrCodeInvalidEventCategoryException for service response error code
// "InvalidEventCategoryException".
//
// Occurs if an event category that is not valid is specified as a value of
// EventCategory.
ErrCodeInvalidEventCategoryException = "InvalidEventCategoryException"
// ErrCodeInvalidEventSelectorsException for service response error code
// "InvalidEventSelectorsException".
//
// This exception is thrown when the PutEventSelectors operation is called with
// a number of event selectors or data resources that is not valid. The combination
// of event selectors and data resources is not valid. A trail can have up to
// 5 event selectors. A trail is limited to 250 data resources. These data resources
// can be distributed across event selectors, but the overall total cannot exceed
// 250.
//
// You can:
//
// * Specify a valid number of event selectors (1 to 5) for a trail.
//
// * Specify a valid number of data resources (1 to 250) for an event selector.
// The limit of number of resources on an individual event selector is configurable
// up to 250. However, this upper limit is allowed only if the total number
// of data resources does not exceed 250 across all event selectors for a
// trail.
//
// * Specify a valid value for a parameter. For example, specifying the ReadWriteType
// parameter with a value of read-only is invalid.
ErrCodeInvalidEventSelectorsException = "InvalidEventSelectorsException"
// ErrCodeInvalidHomeRegionException for service response error code
// "InvalidHomeRegionException".
//
// This exception is thrown when an operation is called on a trail from a region
// other than the region in which the trail was created.
ErrCodeInvalidHomeRegionException = "InvalidHomeRegionException"
// ErrCodeInvalidInsightSelectorsException for service response error code
// "InvalidInsightSelectorsException".
//
// The formatting or syntax of the InsightSelectors JSON statement in your PutInsightSelectors
// or GetInsightSelectors request is not valid, or the specified insight type
// in the InsightSelectors statement is not a valid insight type.
ErrCodeInvalidInsightSelectorsException = "InvalidInsightSelectorsException"
// ErrCodeInvalidKmsKeyIdException for service response error code
// "InvalidKmsKeyIdException".
//
// This exception is thrown when the KMS key ARN is invalid.
ErrCodeInvalidKmsKeyIdException = "InvalidKmsKeyIdException"
// ErrCodeInvalidLookupAttributesException for service response error code
// "InvalidLookupAttributesException".
//
// Occurs when an invalid lookup attribute is specified.
ErrCodeInvalidLookupAttributesException = "InvalidLookupAttributesException"
// ErrCodeInvalidMaxResultsException for service response error code
// "InvalidMaxResultsException".
//
// This exception is thrown if the limit specified is invalid.
ErrCodeInvalidMaxResultsException = "InvalidMaxResultsException"
// ErrCodeInvalidNextTokenException for service response error code
// "InvalidNextTokenException".
//
// Invalid token or token that was previously used in a request with different
// parameters. This exception is thrown if the token is invalid.
ErrCodeInvalidNextTokenException = "InvalidNextTokenException"
// ErrCodeInvalidParameterCombinationException for service response error code
// "InvalidParameterCombinationException".
//
// This exception is thrown when the combination of parameters provided is not
// valid.
ErrCodeInvalidParameterCombinationException = "InvalidParameterCombinationException"
// ErrCodeInvalidS3BucketNameException for service response error code
// "InvalidS3BucketNameException".
//
// This exception is thrown when the provided S3 bucket name is not valid.
ErrCodeInvalidS3BucketNameException = "InvalidS3BucketNameException"
// ErrCodeInvalidS3PrefixException for service response error code
// "InvalidS3PrefixException".
//
// This exception is thrown when the provided S3 prefix is not valid.
ErrCodeInvalidS3PrefixException = "InvalidS3PrefixException"
// ErrCodeInvalidSnsTopicNameException for service response error code
// "InvalidSnsTopicNameException".
//
// This exception is thrown when the provided SNS topic name is not valid.
ErrCodeInvalidSnsTopicNameException = "InvalidSnsTopicNameException"
// ErrCodeInvalidTagParameterException for service response error code
// "InvalidTagParameterException".
//
// This exception is thrown when the specified tag key or values are not valid.
// It can also occur if there are duplicate tags or too many tags on the resource.
ErrCodeInvalidTagParameterException = "InvalidTagParameterException"
// ErrCodeInvalidTimeRangeException for service response error code
// "InvalidTimeRangeException".
//
// Occurs if the timestamp values are invalid. Either the start time occurs
// after the end time or the time range is outside the range of possible values.
ErrCodeInvalidTimeRangeException = "InvalidTimeRangeException"
// ErrCodeInvalidTokenException for service response error code
// "InvalidTokenException".
//
// Reserved for future use.
ErrCodeInvalidTokenException = "InvalidTokenException"
// ErrCodeInvalidTrailNameException for service response error code
// "InvalidTrailNameException".
//
// This exception is thrown when the provided trail name is not valid. Trail
// names must meet the following requirements:
//
// * Contain only ASCII letters (a-z, A-Z), numbers (0-9), periods (.), underscores
// (_), or dashes (-)
//
// * Start with a letter or number, and end with a letter or number
//
// * Be between 3 and 128 characters
//
// * Have no adjacent periods, underscores or dashes. Names like my-_namespace
// and my--namespace are invalid.
//
// * Not be in IP address format (for example, 192.168.5.4)
ErrCodeInvalidTrailNameException = "InvalidTrailNameException"
// ErrCodeKmsException for service response error code
// "KmsException".
//
// This exception is thrown when there is an issue with the specified KMS key
// and the trail cant be updated.
ErrCodeKmsException = "KmsException"
// ErrCodeKmsKeyDisabledException for service response error code
// "KmsKeyDisabledException".
//
// This exception is no longer in use.
ErrCodeKmsKeyDisabledException = "KmsKeyDisabledException"
// ErrCodeKmsKeyNotFoundException for service response error code
// "KmsKeyNotFoundException".
//
// This exception is thrown when the KMS key does not exist, or when the S3
// bucket and the KMS key are not in the same region.
ErrCodeKmsKeyNotFoundException = "KmsKeyNotFoundException"
// ErrCodeMaximumNumberOfTrailsExceededException for service response error code
// "MaximumNumberOfTrailsExceededException".
//
// This exception is thrown when the maximum number of trails is reached.
ErrCodeMaximumNumberOfTrailsExceededException = "MaximumNumberOfTrailsExceededException"
// ErrCodeNotOrganizationMasterAccountException for service response error code
// "NotOrganizationMasterAccountException".
//
// This exception is thrown when the AWS account making the request to create
// or update an organization trail is not the master account for an organization
// in AWS Organizations. For more information, see Prepare For Creating a Trail
// For Your Organization (https://docs.aws.amazon.com/awscloudtrail/latest/userguide/creating-an-organizational-trail-prepare.html).
ErrCodeNotOrganizationMasterAccountException = "NotOrganizationMasterAccountException"
// ErrCodeOperationNotPermittedException for service response error code
// "OperationNotPermittedException".
//
// This exception is thrown when the requested operation is not permitted.
ErrCodeOperationNotPermittedException = "OperationNotPermittedException"
// ErrCodeOrganizationNotInAllFeaturesModeException for service response error code
// "OrganizationNotInAllFeaturesModeException".
//
// This exception is thrown when AWS Organizations is not configured to support
// all features. All features must be enabled in AWS Organization to support
// creating an organization trail. For more information, see Prepare For Creating
// a Trail For Your Organization (https://docs.aws.amazon.com/awscloudtrail/latest/userguide/creating-an-organizational-trail-prepare.html).
ErrCodeOrganizationNotInAllFeaturesModeException = "OrganizationNotInAllFeaturesModeException"
// ErrCodeOrganizationsNotInUseException for service response error code
// "OrganizationsNotInUseException".
//
// This exception is thrown when the request is made from an AWS account that
// is not a member of an organization. To make this request, sign in using the
// credentials of an account that belongs to an organization.
ErrCodeOrganizationsNotInUseException = "OrganizationsNotInUseException"
// ErrCodeResourceNotFoundException for service response error code
// "ResourceNotFoundException".
//
// This exception is thrown when the specified resource is not found.
ErrCodeResourceNotFoundException = "ResourceNotFoundException"
// ErrCodeResourceTypeNotSupportedException for service response error code
// "ResourceTypeNotSupportedException".
//
// This exception is thrown when the specified resource type is not supported
// by CloudTrail.
ErrCodeResourceTypeNotSupportedException = "ResourceTypeNotSupportedException"
// ErrCodeS3BucketDoesNotExistException for service response error code
// "S3BucketDoesNotExistException".
//
// This exception is thrown when the specified S3 bucket does not exist.
ErrCodeS3BucketDoesNotExistException = "S3BucketDoesNotExistException"
// ErrCodeTagsLimitExceededException for service response error code
// "TagsLimitExceededException".
//
// The number of tags per trail has exceeded the permitted amount. Currently,
// the limit is 50.
ErrCodeTagsLimitExceededException = "TagsLimitExceededException"
// ErrCodeTrailAlreadyExistsException for service response error code
// "TrailAlreadyExistsException".
//
// This exception is thrown when the specified trail already exists.
ErrCodeTrailAlreadyExistsException = "TrailAlreadyExistsException"
// ErrCodeTrailNotFoundException for service response error code
// "TrailNotFoundException".
//
// This exception is thrown when the trail with the given name is not found.
ErrCodeTrailNotFoundException = "TrailNotFoundException"
// ErrCodeTrailNotProvidedException for service response error code
// "TrailNotProvidedException".
//
// This exception is no longer in use.
ErrCodeTrailNotProvidedException = "TrailNotProvidedException"
// ErrCodeUnsupportedOperationException for service response error code
// "UnsupportedOperationException".
//
// This exception is thrown when the requested operation is not supported.
ErrCodeUnsupportedOperationException = "UnsupportedOperationException"
)
var exceptionFromCode = map[string]func(protocol.ResponseMetadata) error{
"CloudTrailARNInvalidException": newErrorARNInvalidException,
"CloudTrailAccessNotEnabledException": newErrorAccessNotEnabledException,
"CloudWatchLogsDeliveryUnavailableException": newErrorCloudWatchLogsDeliveryUnavailableException,
"InsightNotEnabledException": newErrorInsightNotEnabledException,
"InsufficientDependencyServiceAccessPermissionException": newErrorInsufficientDependencyServiceAccessPermissionException,
"InsufficientEncryptionPolicyException": newErrorInsufficientEncryptionPolicyException,
"InsufficientS3BucketPolicyException": newErrorInsufficientS3BucketPolicyException,
"InsufficientSnsTopicPolicyException": newErrorInsufficientSnsTopicPolicyException,
"InvalidCloudWatchLogsLogGroupArnException": newErrorInvalidCloudWatchLogsLogGroupArnException,
"InvalidCloudWatchLogsRoleArnException": newErrorInvalidCloudWatchLogsRoleArnException,
"InvalidEventCategoryException": newErrorInvalidEventCategoryException,
"InvalidEventSelectorsException": newErrorInvalidEventSelectorsException,
"InvalidHomeRegionException": newErrorInvalidHomeRegionException,
"InvalidInsightSelectorsException": newErrorInvalidInsightSelectorsException,
"InvalidKmsKeyIdException": newErrorInvalidKmsKeyIdException,
"InvalidLookupAttributesException": newErrorInvalidLookupAttributesException,
"InvalidMaxResultsException": newErrorInvalidMaxResultsException,
"InvalidNextTokenException": newErrorInvalidNextTokenException,
"InvalidParameterCombinationException": newErrorInvalidParameterCombinationException,
"InvalidS3BucketNameException": newErrorInvalidS3BucketNameException,
"InvalidS3PrefixException": newErrorInvalidS3PrefixException,
"InvalidSnsTopicNameException": newErrorInvalidSnsTopicNameException,
"InvalidTagParameterException": newErrorInvalidTagParameterException,
"InvalidTimeRangeException": newErrorInvalidTimeRangeException,
"InvalidTokenException": newErrorInvalidTokenException,
"InvalidTrailNameException": newErrorInvalidTrailNameException,
"KmsException": newErrorKmsException,
"KmsKeyDisabledException": newErrorKmsKeyDisabledException,
"KmsKeyNotFoundException": newErrorKmsKeyNotFoundException,
"MaximumNumberOfTrailsExceededException": newErrorMaximumNumberOfTrailsExceededException,
"NotOrganizationMasterAccountException": newErrorNotOrganizationMasterAccountException,
"OperationNotPermittedException": newErrorOperationNotPermittedException,
"OrganizationNotInAllFeaturesModeException": newErrorOrganizationNotInAllFeaturesModeException,
"OrganizationsNotInUseException": newErrorOrganizationsNotInUseException,
"ResourceNotFoundException": newErrorResourceNotFoundException,
"ResourceTypeNotSupportedException": newErrorResourceTypeNotSupportedException,
"S3BucketDoesNotExistException": newErrorS3BucketDoesNotExistException,
"TagsLimitExceededException": newErrorTagsLimitExceededException,
"TrailAlreadyExistsException": newErrorTrailAlreadyExistsException,
"TrailNotFoundException": newErrorTrailNotFoundException,
"TrailNotProvidedException": newErrorTrailNotProvidedException,
"UnsupportedOperationException": newErrorUnsupportedOperationException,
}
+103
View File
@@ -0,0 +1,103 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package cloudtrail
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/client/metadata"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/signer/v4"
"github.com/aws/aws-sdk-go/private/protocol"
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
)
// CloudTrail provides the API operation methods for making requests to
// AWS CloudTrail. See this package's package overview docs
// for details on the service.
//
// CloudTrail methods are safe to use concurrently. It is not safe to
// modify mutate any of the struct's properties though.
type CloudTrail struct {
*client.Client
}
// Used for custom client initialization logic
var initClient func(*client.Client)
// Used for custom request initialization logic
var initRequest func(*request.Request)
// Service information constants
const (
ServiceName = "cloudtrail" // Name of service.
EndpointsID = ServiceName // ID to lookup a service endpoint with.
ServiceID = "CloudTrail" // ServiceID is a unique identifier of a specific service.
)
// New creates a new instance of the CloudTrail client with a session.
// If additional configuration is needed for the client instance use the optional
// aws.Config parameter to add your extra config.
//
// Example:
// mySession := session.Must(session.NewSession())
//
// // Create a CloudTrail client from just a session.
// svc := cloudtrail.New(mySession)
//
// // Create a CloudTrail client with additional configuration
// svc := cloudtrail.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
func New(p client.ConfigProvider, cfgs ...*aws.Config) *CloudTrail {
c := p.ClientConfig(EndpointsID, cfgs...)
return newClient(*c.Config, c.Handlers, c.PartitionID, c.Endpoint, c.SigningRegion, c.SigningName)
}
// newClient creates, initializes and returns a new service client instance.
func newClient(cfg aws.Config, handlers request.Handlers, partitionID, endpoint, signingRegion, signingName string) *CloudTrail {
svc := &CloudTrail{
Client: client.New(
cfg,
metadata.ClientInfo{
ServiceName: ServiceName,
ServiceID: ServiceID,
SigningName: signingName,
SigningRegion: signingRegion,
PartitionID: partitionID,
Endpoint: endpoint,
APIVersion: "2013-11-01",
JSONVersion: "1.1",
TargetPrefix: "com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101",
},
handlers,
),
}
// Handlers
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
svc.Handlers.Build.PushBackNamed(jsonrpc.BuildHandler)
svc.Handlers.Unmarshal.PushBackNamed(jsonrpc.UnmarshalHandler)
svc.Handlers.UnmarshalMeta.PushBackNamed(jsonrpc.UnmarshalMetaHandler)
svc.Handlers.UnmarshalError.PushBackNamed(
protocol.NewUnmarshalErrorHandler(jsonrpc.NewUnmarshalTypedError(exceptionFromCode)).NamedHandler(),
)
// Run custom client initialization if present
if initClient != nil {
initClient(svc.Client)
}
return svc
}
// newRequest creates a new request for a CloudTrail operation and runs any
// custom request initialization.
func (c *CloudTrail) newRequest(op *request.Operation, params, data interface{}) *request.Request {
req := c.NewRequest(op, params, data)
// Run custom request initialization if present
if initRequest != nil {
initRequest(req)
}
return req
}
+3 -2
View File
@@ -162,6 +162,7 @@ github.com/aws/aws-sdk-go/private/protocol/rest
github.com/aws/aws-sdk-go/private/protocol/restxml
github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil
github.com/aws/aws-sdk-go/service/acm
github.com/aws/aws-sdk-go/service/cloudtrail
github.com/aws/aws-sdk-go/service/cloudwatch
github.com/aws/aws-sdk-go/service/ec2
github.com/aws/aws-sdk-go/service/elbv2
@@ -1105,7 +1106,7 @@ k8s.io/utils/integer
sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
sigs.k8s.io/yaml
# yunion.io/x/executor v0.0.0-20201201131200-44fa553abd9e
# yunion.io/x/executor v0.0.0-20201231064744-df32f32165a9
yunion.io/x/executor/apis
yunion.io/x/executor/client
yunion.io/x/executor/server
@@ -1118,7 +1119,7 @@ yunion.io/x/log/hooks
yunion.io/x/ovsdb/cli_util
yunion.io/x/ovsdb/schema/ovn_nb
yunion.io/x/ovsdb/types
# yunion.io/x/pkg v0.0.0-20201123083159-ca3aea986ff2
# yunion.io/x/pkg v0.0.0-20210109071527-7e72daf56747
yunion.io/x/pkg/errors
yunion.io/x/pkg/gotypes
yunion.io/x/pkg/prettytable
+15
View File
@@ -19,6 +19,8 @@ import (
"reflect"
"sort"
"strings"
"yunion.io/x/pkg/errors"
)
type valueElement struct {
@@ -79,6 +81,19 @@ func CompareSets(dbSet interface{}, extSet interface{}, removed interface{}, com
sort.Sort(valueSet(dbSetArray))
sort.Sort(valueSet(extSetArray))
dupCheck := map[string][]reflect.Value{}
for i := range extSetArray {
_, ok := dupCheck[extSetArray[i].key]
if !ok {
dupCheck[extSetArray[i].key] = []reflect.Value{}
}
dupCheck[extSetArray[i].key] = append(dupCheck[extSetArray[i].key], extSetArray[i].value)
if len(dupCheck[extSetArray[i].key]) > 1 {
return errors.Wrapf(errors.ErrDuplicateId, "duplicated id: %s", extSetArray[i].key)
}
}
removedValue := reflect.Indirect(reflect.ValueOf(removed))
commonDBValue := reflect.Indirect(reflect.ValueOf(commonDB))
commonExtValue := reflect.Indirect(reflect.ValueOf(commonExt))