1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package codestarnotifications
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/codestarnotifications/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns a list of the notification rules for an AWS account.
16func (c *Client) ListNotificationRules(ctx context.Context, params *ListNotificationRulesInput, optFns ...func(*Options)) (*ListNotificationRulesOutput, error) {
17	if params == nil {
18		params = &ListNotificationRulesInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListNotificationRules", params, optFns, addOperationListNotificationRulesMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListNotificationRulesOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListNotificationRulesInput struct {
32
33	// The filters to use to return information by service or resource type. For valid
34	// values, see ListNotificationRulesFilter. A filter with the same name can appear
35	// more than once when used with OR statements. Filters with different names should
36	// be applied with AND statements.
37	Filters []types.ListNotificationRulesFilter
38
39	// A non-negative integer used to limit the number of returned results. The maximum
40	// number of results that can be returned is 100.
41	MaxResults int32
42
43	// An enumeration token that, when provided in a request, returns the next batch of
44	// the results.
45	NextToken *string
46}
47
48type ListNotificationRulesOutput struct {
49
50	// An enumeration token that can be used in a request to return the next batch of
51	// the results.
52	NextToken *string
53
54	// The list of notification rules for the AWS account, by Amazon Resource Name
55	// (ARN) and ID.
56	NotificationRules []types.NotificationRuleSummary
57
58	// Metadata pertaining to the operation's result.
59	ResultMetadata middleware.Metadata
60}
61
62func addOperationListNotificationRulesMiddlewares(stack *middleware.Stack, options Options) (err error) {
63	err = stack.Serialize.Add(&awsRestjson1_serializeOpListNotificationRules{}, middleware.After)
64	if err != nil {
65		return err
66	}
67	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListNotificationRules{}, middleware.After)
68	if err != nil {
69		return err
70	}
71	if err = addSetLoggerMiddleware(stack, options); err != nil {
72		return err
73	}
74	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
75		return err
76	}
77	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
78		return err
79	}
80	if err = addResolveEndpointMiddleware(stack, options); err != nil {
81		return err
82	}
83	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
84		return err
85	}
86	if err = addRetryMiddlewares(stack, options); err != nil {
87		return err
88	}
89	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
93		return err
94	}
95	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
96		return err
97	}
98	if err = addClientUserAgent(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
102		return err
103	}
104	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
105		return err
106	}
107	if err = addOpListNotificationRulesValidationMiddleware(stack); err != nil {
108		return err
109	}
110	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListNotificationRules(options.Region), middleware.Before); err != nil {
111		return err
112	}
113	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
114		return err
115	}
116	if err = addResponseErrorMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addRequestResponseLogging(stack, options); err != nil {
120		return err
121	}
122	return nil
123}
124
125// ListNotificationRulesAPIClient is a client that implements the
126// ListNotificationRules operation.
127type ListNotificationRulesAPIClient interface {
128	ListNotificationRules(context.Context, *ListNotificationRulesInput, ...func(*Options)) (*ListNotificationRulesOutput, error)
129}
130
131var _ ListNotificationRulesAPIClient = (*Client)(nil)
132
133// ListNotificationRulesPaginatorOptions is the paginator options for
134// ListNotificationRules
135type ListNotificationRulesPaginatorOptions struct {
136	// A non-negative integer used to limit the number of returned results. The maximum
137	// number of results that can be returned is 100.
138	Limit int32
139
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// ListNotificationRulesPaginator is a paginator for ListNotificationRules
146type ListNotificationRulesPaginator struct {
147	options   ListNotificationRulesPaginatorOptions
148	client    ListNotificationRulesAPIClient
149	params    *ListNotificationRulesInput
150	nextToken *string
151	firstPage bool
152}
153
154// NewListNotificationRulesPaginator returns a new ListNotificationRulesPaginator
155func NewListNotificationRulesPaginator(client ListNotificationRulesAPIClient, params *ListNotificationRulesInput, optFns ...func(*ListNotificationRulesPaginatorOptions)) *ListNotificationRulesPaginator {
156	if params == nil {
157		params = &ListNotificationRulesInput{}
158	}
159
160	options := ListNotificationRulesPaginatorOptions{}
161	if params.MaxResults != 0 {
162		options.Limit = params.MaxResults
163	}
164
165	for _, fn := range optFns {
166		fn(&options)
167	}
168
169	return &ListNotificationRulesPaginator{
170		options:   options,
171		client:    client,
172		params:    params,
173		firstPage: true,
174	}
175}
176
177// HasMorePages returns a boolean indicating whether more pages are available
178func (p *ListNotificationRulesPaginator) HasMorePages() bool {
179	return p.firstPage || p.nextToken != nil
180}
181
182// NextPage retrieves the next ListNotificationRules page.
183func (p *ListNotificationRulesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListNotificationRulesOutput, error) {
184	if !p.HasMorePages() {
185		return nil, fmt.Errorf("no more pages available")
186	}
187
188	params := *p.params
189	params.NextToken = p.nextToken
190
191	params.MaxResults = p.options.Limit
192
193	result, err := p.client.ListNotificationRules(ctx, &params, optFns...)
194	if err != nil {
195		return nil, err
196	}
197	p.firstPage = false
198
199	prevToken := p.nextToken
200	p.nextToken = result.NextToken
201
202	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
203		p.nextToken = nil
204	}
205
206	return result, nil
207}
208
209func newServiceMetadataMiddleware_opListNotificationRules(region string) *awsmiddleware.RegisterServiceMetadata {
210	return &awsmiddleware.RegisterServiceMetadata{
211		Region:        region,
212		ServiceID:     ServiceID,
213		SigningName:   "codestar-notifications",
214		OperationName: "ListNotificationRules",
215	}
216}
217