// Code generated by smithy-go-codegen DO NOT EDIT.

package cloudwatch

import (
	"context"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

// Removes the customer managed Amazon Web Services Key Management Service (Amazon
// Web Services KMS) key association from the specified dataset. After this
// operation completes, data that you publish to the dataset is encrypted at rest
// using an Amazon Web Services owned key managed by Amazon CloudWatch.
//
// Only the default dataset is supported. To call this operation, the dataset must
// currently have a customer managed KMS key associated with it. If the dataset has
// no associated KMS key, the operation fails with ResourceNotFoundException .
//
// Amazon CloudWatch performs a dry-run kms:Decrypt call on the key as part of
// this operation. This verifies that the caller is authorized to use the currently
// associated key. The caller must have kms:Decrypt permission on the currently
// associated key, and the key must be enabled and accessible. If the key has been
// disabled or scheduled for deletion, you must first re-enable or restore it
// before you can disassociate it from the dataset.
//
// Disassociating a KMS key from a dataset does not immediately remove the
// kms:Decrypt requirement on data plane operations. For up to three hours after
// disassociation, callers must continue to have kms:Decrypt permission on the
// previously associated key. Some data may still be encrypted with that key during
// this window. After this enforcement window elapses, the kms:Decrypt requirement
// is lifted.
//
// For more information about using customer managed keys with Amazon CloudWatch,
// see [Encryption at rest with customer managed keys]in the Amazon CloudWatch User Guide.
//
// [Encryption at rest with customer managed keys]: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cmk-encryption.html
func (c *Client) DisassociateDatasetKmsKey(ctx context.Context, params *DisassociateDatasetKmsKeyInput, optFns ...func(*Options)) (*DisassociateDatasetKmsKeyOutput, error) {
	if params == nil {
		params = &DisassociateDatasetKmsKeyInput{}
	}

	result, metadata, err := c.invokeOperation(ctx, "DisassociateDatasetKmsKey", params, optFns, c.addOperationDisassociateDatasetKmsKeyMiddlewares)
	if err != nil {
		return nil, err
	}

	out := result.(*DisassociateDatasetKmsKeyOutput)
	out.ResultMetadata = metadata
	return out, nil
}

type DisassociateDatasetKmsKeyInput struct {

	// Specifies the identifier of the dataset from which to remove the KMS key
	// association. For the default dataset, you can specify either default or the
	// full dataset Amazon Resource Name (ARN) in the format
	// arn:aws:cloudwatch:Region:account-id:dataset/default .
	//
	// This member is required.
	DatasetIdentifier *string

	noSmithyDocumentSerde
}

type DisassociateDatasetKmsKeyOutput struct {
	// Metadata pertaining to the operation's result.
	ResultMetadata middleware.Metadata

	noSmithyDocumentSerde
}

func (c *Client) addOperationDisassociateDatasetKmsKeyMiddlewares(stack *middleware.Stack, options Options) (err error) {
	err = stack.Serialize.Add(&smithyRpcv2cbor_serializeOpDisassociateDatasetKmsKey{}, middleware.After)
	if err != nil {
		return err
	}
	err = stack.Deserialize.Add(&smithyRpcv2cbor_deserializeOpDisassociateDatasetKmsKey{}, middleware.After)
	if err != nil {
		return err
	}

	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
		return err
	}
	if err = addComputeContentLength(stack); err != nil {
		return err
	}
	if err = addResolveEndpointMiddleware(stack, options); err != nil {
		return err
	}
	if err = addComputePayloadSHA256(stack); err != nil {
		return err
	}
	if err = addRecordResponseTiming(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
		return err
	}
	if err = addUserAgentFeatureProtocolRPCV2CBOR(stack, options); err != nil {
		return err
	}
	if err = addCredentialSource(stack, options); err != nil {
		return err
	}
	if err = addOpDisassociateDatasetKmsKeyValidationMiddleware(stack); err != nil {
		return err
	}
	if err = stack.Initialize.Add(newServiceMetadataMiddleware(options.Region, "DisassociateDatasetKmsKey"), middleware.Before); err != nil {
		return err
	}
	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
		return err
	}
	if err = addResponseErrorMiddleware(stack); err != nil {
		return err
	}
	if err = addRequestResponseLogging(stack, options); err != nil {
		return err
	}
	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
		return err
	}
	if err = addInterceptors(stack, options); err != nil {
		return err
	}
	return nil
}
