1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package secretsmanager
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/smithy-go/middleware"
10	smithyhttp "github.com/aws/smithy-go/transport/http"
11	"time"
12)
13
14// Deletes an entire secret and all of the versions. You can optionally include a
15// recovery window during which you can restore the secret. If you don't specify a
16// recovery window value, the operation defaults to 30 days. Secrets Manager
17// attaches a DeletionDate stamp to the secret that specifies the end of the
18// recovery window. At the end of the recovery window, Secrets Manager deletes the
19// secret permanently. At any time before recovery window ends, you can use
20// RestoreSecret to remove the DeletionDate and cancel the deletion of the secret.
21// You cannot access the encrypted secret information in any secret scheduled for
22// deletion. If you need to access that information, you must cancel the deletion
23// with RestoreSecret and then retrieve the information.
24//
25// * There is no explicit
26// operation to delete a version of a secret. Instead, remove all staging labels
27// from the VersionStage field of a version. That marks the version as deprecated
28// and allows Secrets Manager to delete it as needed. Versions without any staging
29// labels do not show up in ListSecretVersionIds unless you specify
30// IncludeDeprecated.
31//
32// * The permanent secret deletion at the end of the waiting
33// period is performed as a background task with low priority. There is no
34// guarantee of a specific time after the recovery window for the actual delete
35// operation to occur.
36//
37// Minimum permissions To run this command, you must have the
38// following permissions:
39//
40// * secretsmanager:DeleteSecret
41//
42// Related operations
43//
44// * To
45// create a secret, use CreateSecret.
46//
47// * To cancel deletion of a version of a
48// secret before the recovery window has expired, use RestoreSecret.
49func (c *Client) DeleteSecret(ctx context.Context, params *DeleteSecretInput, optFns ...func(*Options)) (*DeleteSecretOutput, error) {
50	if params == nil {
51		params = &DeleteSecretInput{}
52	}
53
54	result, metadata, err := c.invokeOperation(ctx, "DeleteSecret", params, optFns, addOperationDeleteSecretMiddlewares)
55	if err != nil {
56		return nil, err
57	}
58
59	out := result.(*DeleteSecretOutput)
60	out.ResultMetadata = metadata
61	return out, nil
62}
63
64type DeleteSecretInput struct {
65
66	// Specifies the secret to delete. You can specify either the Amazon Resource Name
67	// (ARN) or the friendly name of the secret. If you specify an ARN, we generally
68	// recommend that you specify a complete ARN. You can specify a partial ARN too—for
69	// example, if you don’t include the final hyphen and six random characters that
70	// Secrets Manager adds at the end of the ARN when you created the secret. A
71	// partial ARN match can work as long as it uniquely matches only one secret.
72	// However, if your secret has a name that ends in a hyphen followed by six
73	// characters (before Secrets Manager adds the hyphen and six characters to the
74	// ARN) and you try to use that as a partial ARN, then those characters cause
75	// Secrets Manager to assume that you’re specifying a complete ARN. This confusion
76	// can cause unexpected results. To avoid this situation, we recommend that you
77	// don’t create secret names ending with a hyphen followed by six characters. If
78	// you specify an incomplete ARN without the random suffix, and instead provide the
79	// 'friendly name', you must not include the random suffix. If you do include the
80	// random suffix added by Secrets Manager, you receive either a
81	// ResourceNotFoundException or an AccessDeniedException error, depending on your
82	// permissions.
83	//
84	// This member is required.
85	SecretId *string
86
87	// (Optional) Specifies that the secret is to be deleted without any recovery
88	// window. You can't use both this parameter and the RecoveryWindowInDays parameter
89	// in the same API call. An asynchronous background process performs the actual
90	// deletion, so there can be a short delay before the operation completes. If you
91	// write code to delete and then immediately recreate a secret with the same name,
92	// ensure that your code includes appropriate back off and retry logic. Use this
93	// parameter with caution. This parameter causes the operation to skip the normal
94	// waiting period before the permanent deletion that AWS would normally impose with
95	// the RecoveryWindowInDays parameter. If you delete a secret with the
96	// ForceDeleteWithouRecovery parameter, then you have no opportunity to recover the
97	// secret. You lose the secret permanently. If you use this parameter and include a
98	// previously deleted or nonexistent secret, the operation does not return the
99	// error ResourceNotFoundException in order to correctly handle retries.
100	ForceDeleteWithoutRecovery bool
101
102	// (Optional) Specifies the number of days that Secrets Manager waits before
103	// Secrets Manager can delete the secret. You can't use both this parameter and the
104	// ForceDeleteWithoutRecovery parameter in the same API call. This value can range
105	// from 7 to 30 days with a default value of 30.
106	RecoveryWindowInDays int64
107}
108
109type DeleteSecretOutput struct {
110
111	// The ARN of the secret that is now scheduled for deletion.
112	ARN *string
113
114	// The date and time after which this secret can be deleted by Secrets Manager and
115	// can no longer be restored. This value is the date and time of the delete request
116	// plus the number of days specified in RecoveryWindowInDays.
117	DeletionDate *time.Time
118
119	// The friendly name of the secret currently scheduled for deletion.
120	Name *string
121
122	// Metadata pertaining to the operation's result.
123	ResultMetadata middleware.Metadata
124}
125
126func addOperationDeleteSecretMiddlewares(stack *middleware.Stack, options Options) (err error) {
127	err = stack.Serialize.Add(&awsAwsjson11_serializeOpDeleteSecret{}, middleware.After)
128	if err != nil {
129		return err
130	}
131	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDeleteSecret{}, middleware.After)
132	if err != nil {
133		return err
134	}
135	if err = addSetLoggerMiddleware(stack, options); err != nil {
136		return err
137	}
138	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
139		return err
140	}
141	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
142		return err
143	}
144	if err = addResolveEndpointMiddleware(stack, options); err != nil {
145		return err
146	}
147	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
148		return err
149	}
150	if err = addRetryMiddlewares(stack, options); err != nil {
151		return err
152	}
153	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
154		return err
155	}
156	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
157		return err
158	}
159	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
160		return err
161	}
162	if err = addClientUserAgent(stack); err != nil {
163		return err
164	}
165	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
166		return err
167	}
168	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
169		return err
170	}
171	if err = addOpDeleteSecretValidationMiddleware(stack); err != nil {
172		return err
173	}
174	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDeleteSecret(options.Region), middleware.Before); err != nil {
175		return err
176	}
177	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
178		return err
179	}
180	if err = addResponseErrorMiddleware(stack); err != nil {
181		return err
182	}
183	if err = addRequestResponseLogging(stack, options); err != nil {
184		return err
185	}
186	return nil
187}
188
189func newServiceMetadataMiddleware_opDeleteSecret(region string) *awsmiddleware.RegisterServiceMetadata {
190	return &awsmiddleware.RegisterServiceMetadata{
191		Region:        region,
192		ServiceID:     ServiceID,
193		SigningName:   "secretsmanager",
194		OperationName: "DeleteSecret",
195	}
196}
197