1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iot
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/iot/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists logging levels.
16func (c *Client) ListV2LoggingLevels(ctx context.Context, params *ListV2LoggingLevelsInput, optFns ...func(*Options)) (*ListV2LoggingLevelsOutput, error) {
17	if params == nil {
18		params = &ListV2LoggingLevelsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListV2LoggingLevels", params, optFns, addOperationListV2LoggingLevelsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListV2LoggingLevelsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListV2LoggingLevelsInput struct {
32
33	// The maximum number of results to return at one time.
34	MaxResults *int32
35
36	// To retrieve the next set of results, the nextToken value from a previous
37	// response; otherwise null to receive the first set of results.
38	NextToken *string
39
40	// The type of resource for which you are configuring logging. Must be THING_Group.
41	TargetType types.LogTargetType
42}
43
44type ListV2LoggingLevelsOutput struct {
45
46	// The logging configuration for a target.
47	LogTargetConfigurations []types.LogTargetConfiguration
48
49	// The token to use to get the next set of results, or null if there are no
50	// additional results.
51	NextToken *string
52
53	// Metadata pertaining to the operation's result.
54	ResultMetadata middleware.Metadata
55}
56
57func addOperationListV2LoggingLevelsMiddlewares(stack *middleware.Stack, options Options) (err error) {
58	err = stack.Serialize.Add(&awsRestjson1_serializeOpListV2LoggingLevels{}, middleware.After)
59	if err != nil {
60		return err
61	}
62	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListV2LoggingLevels{}, middleware.After)
63	if err != nil {
64		return err
65	}
66	if err = addSetLoggerMiddleware(stack, options); err != nil {
67		return err
68	}
69	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
70		return err
71	}
72	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
73		return err
74	}
75	if err = addResolveEndpointMiddleware(stack, options); err != nil {
76		return err
77	}
78	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
79		return err
80	}
81	if err = addRetryMiddlewares(stack, options); err != nil {
82		return err
83	}
84	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
85		return err
86	}
87	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
91		return err
92	}
93	if err = addClientUserAgent(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
97		return err
98	}
99	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
100		return err
101	}
102	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListV2LoggingLevels(options.Region), middleware.Before); err != nil {
103		return err
104	}
105	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
106		return err
107	}
108	if err = addResponseErrorMiddleware(stack); err != nil {
109		return err
110	}
111	if err = addRequestResponseLogging(stack, options); err != nil {
112		return err
113	}
114	return nil
115}
116
117// ListV2LoggingLevelsAPIClient is a client that implements the ListV2LoggingLevels
118// operation.
119type ListV2LoggingLevelsAPIClient interface {
120	ListV2LoggingLevels(context.Context, *ListV2LoggingLevelsInput, ...func(*Options)) (*ListV2LoggingLevelsOutput, error)
121}
122
123var _ ListV2LoggingLevelsAPIClient = (*Client)(nil)
124
125// ListV2LoggingLevelsPaginatorOptions is the paginator options for
126// ListV2LoggingLevels
127type ListV2LoggingLevelsPaginatorOptions struct {
128	// The maximum number of results to return at one time.
129	Limit int32
130
131	// Set to true if pagination should stop if the service returns a pagination token
132	// that matches the most recent token provided to the service.
133	StopOnDuplicateToken bool
134}
135
136// ListV2LoggingLevelsPaginator is a paginator for ListV2LoggingLevels
137type ListV2LoggingLevelsPaginator struct {
138	options   ListV2LoggingLevelsPaginatorOptions
139	client    ListV2LoggingLevelsAPIClient
140	params    *ListV2LoggingLevelsInput
141	nextToken *string
142	firstPage bool
143}
144
145// NewListV2LoggingLevelsPaginator returns a new ListV2LoggingLevelsPaginator
146func NewListV2LoggingLevelsPaginator(client ListV2LoggingLevelsAPIClient, params *ListV2LoggingLevelsInput, optFns ...func(*ListV2LoggingLevelsPaginatorOptions)) *ListV2LoggingLevelsPaginator {
147	options := ListV2LoggingLevelsPaginatorOptions{}
148	if params.MaxResults != nil {
149		options.Limit = *params.MaxResults
150	}
151
152	for _, fn := range optFns {
153		fn(&options)
154	}
155
156	if params == nil {
157		params = &ListV2LoggingLevelsInput{}
158	}
159
160	return &ListV2LoggingLevelsPaginator{
161		options:   options,
162		client:    client,
163		params:    params,
164		firstPage: true,
165	}
166}
167
168// HasMorePages returns a boolean indicating whether more pages are available
169func (p *ListV2LoggingLevelsPaginator) HasMorePages() bool {
170	return p.firstPage || p.nextToken != nil
171}
172
173// NextPage retrieves the next ListV2LoggingLevels page.
174func (p *ListV2LoggingLevelsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListV2LoggingLevelsOutput, error) {
175	if !p.HasMorePages() {
176		return nil, fmt.Errorf("no more pages available")
177	}
178
179	params := *p.params
180	params.NextToken = p.nextToken
181
182	var limit *int32
183	if p.options.Limit > 0 {
184		limit = &p.options.Limit
185	}
186	params.MaxResults = limit
187
188	result, err := p.client.ListV2LoggingLevels(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_opListV2LoggingLevels(region string) *awsmiddleware.RegisterServiceMetadata {
205	return &awsmiddleware.RegisterServiceMetadata{
206		Region:        region,
207		ServiceID:     ServiceID,
208		SigningName:   "execute-api",
209		OperationName: "ListV2LoggingLevels",
210	}
211}
212