1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package cloudformation
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns all stack related events for a specified stack in reverse chronological
16// order. For more information about a stack's event history, go to Stacks
17// (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/concept-stack.html)
18// in the AWS CloudFormation User Guide. You can list events for stacks that have
19// failed to create or have been deleted by specifying the unique stack identifier
20// (stack ID).
21func (c *Client) DescribeStackEvents(ctx context.Context, params *DescribeStackEventsInput, optFns ...func(*Options)) (*DescribeStackEventsOutput, error) {
22	if params == nil {
23		params = &DescribeStackEventsInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "DescribeStackEvents", params, optFns, addOperationDescribeStackEventsMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*DescribeStackEventsOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36// The input for DescribeStackEvents action.
37type DescribeStackEventsInput struct {
38
39	// A string that identifies the next page of events that you want to retrieve.
40	NextToken *string
41
42	// The name or the unique stack ID that is associated with the stack, which are not
43	// always interchangeable:
44	//
45	// * Running stacks: You can specify either the stack's
46	// name or its unique stack ID.
47	//
48	// * Deleted stacks: You must specify the unique
49	// stack ID.
50	//
51	// Default: There is no default value.
52	StackName *string
53}
54
55// The output for a DescribeStackEvents action.
56type DescribeStackEventsOutput struct {
57
58	// If the output exceeds 1 MB in size, a string that identifies the next page of
59	// events. If no additional page exists, this value is null.
60	NextToken *string
61
62	// A list of StackEvents structures.
63	StackEvents []types.StackEvent
64
65	// Metadata pertaining to the operation's result.
66	ResultMetadata middleware.Metadata
67}
68
69func addOperationDescribeStackEventsMiddlewares(stack *middleware.Stack, options Options) (err error) {
70	err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeStackEvents{}, middleware.After)
71	if err != nil {
72		return err
73	}
74	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeStackEvents{}, middleware.After)
75	if err != nil {
76		return err
77	}
78	if err = addSetLoggerMiddleware(stack, options); err != nil {
79		return err
80	}
81	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
82		return err
83	}
84	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
85		return err
86	}
87	if err = addResolveEndpointMiddleware(stack, options); err != nil {
88		return err
89	}
90	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
91		return err
92	}
93	if err = addRetryMiddlewares(stack, options); err != nil {
94		return err
95	}
96	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
97		return err
98	}
99	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
100		return err
101	}
102	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
103		return err
104	}
105	if err = addClientUserAgent(stack); err != nil {
106		return err
107	}
108	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
112		return err
113	}
114	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeStackEvents(options.Region), middleware.Before); err != nil {
115		return err
116	}
117	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
118		return err
119	}
120	if err = addResponseErrorMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addRequestResponseLogging(stack, options); err != nil {
124		return err
125	}
126	return nil
127}
128
129// DescribeStackEventsAPIClient is a client that implements the DescribeStackEvents
130// operation.
131type DescribeStackEventsAPIClient interface {
132	DescribeStackEvents(context.Context, *DescribeStackEventsInput, ...func(*Options)) (*DescribeStackEventsOutput, error)
133}
134
135var _ DescribeStackEventsAPIClient = (*Client)(nil)
136
137// DescribeStackEventsPaginatorOptions is the paginator options for
138// DescribeStackEvents
139type DescribeStackEventsPaginatorOptions struct {
140	// Set to true if pagination should stop if the service returns a pagination token
141	// that matches the most recent token provided to the service.
142	StopOnDuplicateToken bool
143}
144
145// DescribeStackEventsPaginator is a paginator for DescribeStackEvents
146type DescribeStackEventsPaginator struct {
147	options   DescribeStackEventsPaginatorOptions
148	client    DescribeStackEventsAPIClient
149	params    *DescribeStackEventsInput
150	nextToken *string
151	firstPage bool
152}
153
154// NewDescribeStackEventsPaginator returns a new DescribeStackEventsPaginator
155func NewDescribeStackEventsPaginator(client DescribeStackEventsAPIClient, params *DescribeStackEventsInput, optFns ...func(*DescribeStackEventsPaginatorOptions)) *DescribeStackEventsPaginator {
156	options := DescribeStackEventsPaginatorOptions{}
157
158	for _, fn := range optFns {
159		fn(&options)
160	}
161
162	if params == nil {
163		params = &DescribeStackEventsInput{}
164	}
165
166	return &DescribeStackEventsPaginator{
167		options:   options,
168		client:    client,
169		params:    params,
170		firstPage: true,
171	}
172}
173
174// HasMorePages returns a boolean indicating whether more pages are available
175func (p *DescribeStackEventsPaginator) HasMorePages() bool {
176	return p.firstPage || p.nextToken != nil
177}
178
179// NextPage retrieves the next DescribeStackEvents page.
180func (p *DescribeStackEventsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeStackEventsOutput, error) {
181	if !p.HasMorePages() {
182		return nil, fmt.Errorf("no more pages available")
183	}
184
185	params := *p.params
186	params.NextToken = p.nextToken
187
188	result, err := p.client.DescribeStackEvents(ctx, &params, optFns...)
189	if err != nil {
190		return nil, err
191	}
192	p.firstPage = false
193
194	prevToken := p.nextToken
195	p.nextToken = result.NextToken
196
197	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
198		p.nextToken = nil
199	}
200
201	return result, nil
202}
203
204func newServiceMetadataMiddleware_opDescribeStackEvents(region string) *awsmiddleware.RegisterServiceMetadata {
205	return &awsmiddleware.RegisterServiceMetadata{
206		Region:        region,
207		ServiceID:     ServiceID,
208		SigningName:   "cloudformation",
209		OperationName: "DescribeStackEvents",
210	}
211}
212