1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package kms 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/kms/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12) 13 14// Adds or edits tags on a customer managed CMK 15// (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk). 16// Each tag consists of a tag key and a tag value, both of which are case-sensitive 17// strings. The tag value can be an empty (null) string. To add a tag, specify a 18// new tag key and a tag value. To edit a tag, specify an existing tag key and a 19// new tag value. You can use this operation to tag a customer managed CMK 20// (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk), 21// but you cannot tag an AWS managed CMK 22// (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-managed-cmk), 23// an AWS owned CMK 24// (https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-owned-cmk), 25// or an alias. For general information about tags, including the format and 26// syntax, see Tagging AWS resources 27// (https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html) in the Amazon 28// Web Services General Reference. For information about using tags in AWS KMS, see 29// Tagging keys 30// (https://docs.aws.amazon.com/kms/latest/developerguide/tagging-keys.html). The 31// CMK that you use for this operation must be in a compatible key state. For 32// details, see How Key State Affects Use of a Customer Master Key 33// (https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html) in the 34// AWS Key Management Service Developer Guide. Cross-account use: No. You cannot 35// perform this operation on a CMK in a different AWS account. Required 36// permissions: kms:TagResource 37// (https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html) 38// (key policy) Related operations 39// 40// * UntagResource 41// 42// * ListResourceTags 43func (c *Client) TagResource(ctx context.Context, params *TagResourceInput, optFns ...func(*Options)) (*TagResourceOutput, error) { 44 if params == nil { 45 params = &TagResourceInput{} 46 } 47 48 result, metadata, err := c.invokeOperation(ctx, "TagResource", params, optFns, addOperationTagResourceMiddlewares) 49 if err != nil { 50 return nil, err 51 } 52 53 out := result.(*TagResourceOutput) 54 out.ResultMetadata = metadata 55 return out, nil 56} 57 58type TagResourceInput struct { 59 60 // Identifies a customer managed CMK in the account and Region. Specify the key ID 61 // or the Amazon Resource Name (ARN) of the CMK. For example: 62 // 63 // * Key ID: 64 // 1234abcd-12ab-34cd-56ef-1234567890ab 65 // 66 // * Key ARN: 67 // arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab 68 // 69 // To 70 // get the key ID and key ARN for a CMK, use ListKeys or DescribeKey. 71 // 72 // This member is required. 73 KeyId *string 74 75 // One or more tags. Each tag consists of a tag key and a tag value. The tag value 76 // can be an empty (null) string. You cannot have more than one tag on a CMK with 77 // the same tag key. If you specify an existing tag key with a different tag value, 78 // AWS KMS replaces the current tag value with the specified one. 79 // 80 // This member is required. 81 Tags []types.Tag 82} 83 84type TagResourceOutput struct { 85 // Metadata pertaining to the operation's result. 86 ResultMetadata middleware.Metadata 87} 88 89func addOperationTagResourceMiddlewares(stack *middleware.Stack, options Options) (err error) { 90 err = stack.Serialize.Add(&awsAwsjson11_serializeOpTagResource{}, middleware.After) 91 if err != nil { 92 return err 93 } 94 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpTagResource{}, middleware.After) 95 if err != nil { 96 return err 97 } 98 if err = addSetLoggerMiddleware(stack, options); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 102 return err 103 } 104 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 105 return err 106 } 107 if err = addResolveEndpointMiddleware(stack, options); err != nil { 108 return err 109 } 110 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 111 return err 112 } 113 if err = addRetryMiddlewares(stack, options); err != nil { 114 return err 115 } 116 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 117 return err 118 } 119 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 120 return err 121 } 122 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 123 return err 124 } 125 if err = addClientUserAgent(stack); err != nil { 126 return err 127 } 128 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 129 return err 130 } 131 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 132 return err 133 } 134 if err = addOpTagResourceValidationMiddleware(stack); err != nil { 135 return err 136 } 137 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opTagResource(options.Region), middleware.Before); err != nil { 138 return err 139 } 140 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 141 return err 142 } 143 if err = addResponseErrorMiddleware(stack); err != nil { 144 return err 145 } 146 if err = addRequestResponseLogging(stack, options); err != nil { 147 return err 148 } 149 return nil 150} 151 152func newServiceMetadataMiddleware_opTagResource(region string) *awsmiddleware.RegisterServiceMetadata { 153 return &awsmiddleware.RegisterServiceMetadata{ 154 Region: region, 155 ServiceID: ServiceID, 156 SigningName: "kms", 157 OperationName: "TagResource", 158 } 159} 160