1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package cloudwatchlogs 4 5import ( 6 "context" 7 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 8 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12) 13 14// Creates or updates a resource policy allowing other Amazon Web Services services 15// to put log events to this account, such as Amazon Route 53. An account can have 16// up to 10 resource policies per Amazon Web Services Region. 17func (c *Client) PutResourcePolicy(ctx context.Context, params *PutResourcePolicyInput, optFns ...func(*Options)) (*PutResourcePolicyOutput, error) { 18 if params == nil { 19 params = &PutResourcePolicyInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "PutResourcePolicy", params, optFns, c.addOperationPutResourcePolicyMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*PutResourcePolicyOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type PutResourcePolicyInput struct { 33 34 // Details of the new policy, including the identity of the principal that is 35 // enabled to put logs to this account. This is formatted as a JSON string. This 36 // parameter is required. The following example creates a resource policy enabling 37 // the Route 53 service to put DNS query logs in to the specified log group. 38 // Replace "logArn" with the ARN of your CloudWatch Logs resource, such as a log 39 // group or log stream. CloudWatch Logs also supports aws:SourceArn 40 // (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn) 41 // and aws:SourceAccount 42 // (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceaccount) 43 // condition context keys. In the example resource policy, you would replace the 44 // value of SourceArn with the resource making the call from Route 53 to CloudWatch 45 // Logs and replace the value of SourceAccount with the Amazon Web Services account 46 // ID making that call. { "Version": "2012-10-17", "Statement": [ { "Sid": 47 // "Route53LogsToCloudWatchLogs", "Effect": "Allow", "Principal": { "Service": [ 48 // "route53.amazonaws.com" ] }, "Action": "logs:PutLogEvents", "Resource": 49 // "logArn", "Condition": { "ArnLike": { "aws:SourceArn": "myRoute53ResourceArn" }, 50 // "StringEquals": { "aws:SourceAccount": "myAwsAccountId" } } } ] } 51 PolicyDocument *string 52 53 // Name of the new policy. This parameter is required. 54 PolicyName *string 55 56 noSmithyDocumentSerde 57} 58 59type PutResourcePolicyOutput struct { 60 61 // The new policy. 62 ResourcePolicy *types.ResourcePolicy 63 64 // Metadata pertaining to the operation's result. 65 ResultMetadata middleware.Metadata 66 67 noSmithyDocumentSerde 68} 69 70func (c *Client) addOperationPutResourcePolicyMiddlewares(stack *middleware.Stack, options Options) (err error) { 71 err = stack.Serialize.Add(&awsAwsjson11_serializeOpPutResourcePolicy{}, middleware.After) 72 if err != nil { 73 return err 74 } 75 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpPutResourcePolicy{}, middleware.After) 76 if err != nil { 77 return err 78 } 79 if err = addSetLoggerMiddleware(stack, options); err != nil { 80 return err 81 } 82 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 83 return err 84 } 85 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 86 return err 87 } 88 if err = addResolveEndpointMiddleware(stack, options); err != nil { 89 return err 90 } 91 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 92 return err 93 } 94 if err = addRetryMiddlewares(stack, options); err != nil { 95 return err 96 } 97 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 98 return err 99 } 100 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 101 return err 102 } 103 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 104 return err 105 } 106 if err = addClientUserAgent(stack); err != nil { 107 return err 108 } 109 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 110 return err 111 } 112 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 113 return err 114 } 115 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutResourcePolicy(options.Region), middleware.Before); err != nil { 116 return err 117 } 118 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 119 return err 120 } 121 if err = addResponseErrorMiddleware(stack); err != nil { 122 return err 123 } 124 if err = addRequestResponseLogging(stack, options); err != nil { 125 return err 126 } 127 return nil 128} 129 130func newServiceMetadataMiddleware_opPutResourcePolicy(region string) *awsmiddleware.RegisterServiceMetadata { 131 return &awsmiddleware.RegisterServiceMetadata{ 132 Region: region, 133 ServiceID: ServiceID, 134 SigningName: "logs", 135 OperationName: "PutResourcePolicy", 136 } 137} 138