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 the Device Defender security profiles you have created. You can use
16// filters to list only those security profiles associated with a thing group or
17// only those associated with your account.
18func (c *Client) ListSecurityProfiles(ctx context.Context, params *ListSecurityProfilesInput, optFns ...func(*Options)) (*ListSecurityProfilesOutput, error) {
19	if params == nil {
20		params = &ListSecurityProfilesInput{}
21	}
22
23	result, metadata, err := c.invokeOperation(ctx, "ListSecurityProfiles", params, optFns, addOperationListSecurityProfilesMiddlewares)
24	if err != nil {
25		return nil, err
26	}
27
28	out := result.(*ListSecurityProfilesOutput)
29	out.ResultMetadata = metadata
30	return out, nil
31}
32
33type ListSecurityProfilesInput struct {
34
35	// A filter to limit results to the security profiles that use the defined
36	// dimension.
37	DimensionName *string
38
39	// The maximum number of results to return at one time.
40	MaxResults *int32
41
42	// The token for the next set of results.
43	NextToken *string
44}
45
46type ListSecurityProfilesOutput struct {
47
48	// A token that can be used to retrieve the next set of results, or null if there
49	// are no additional results.
50	NextToken *string
51
52	// A list of security profile identifiers (names and ARNs).
53	SecurityProfileIdentifiers []types.SecurityProfileIdentifier
54
55	// Metadata pertaining to the operation's result.
56	ResultMetadata middleware.Metadata
57}
58
59func addOperationListSecurityProfilesMiddlewares(stack *middleware.Stack, options Options) (err error) {
60	err = stack.Serialize.Add(&awsRestjson1_serializeOpListSecurityProfiles{}, middleware.After)
61	if err != nil {
62		return err
63	}
64	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListSecurityProfiles{}, middleware.After)
65	if err != nil {
66		return err
67	}
68	if err = addSetLoggerMiddleware(stack, options); err != nil {
69		return err
70	}
71	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
72		return err
73	}
74	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
75		return err
76	}
77	if err = addResolveEndpointMiddleware(stack, options); err != nil {
78		return err
79	}
80	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
81		return err
82	}
83	if err = addRetryMiddlewares(stack, options); err != nil {
84		return err
85	}
86	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
87		return err
88	}
89	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
93		return err
94	}
95	if err = addClientUserAgent(stack); err != nil {
96		return err
97	}
98	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
102		return err
103	}
104	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListSecurityProfiles(options.Region), middleware.Before); err != nil {
105		return err
106	}
107	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
108		return err
109	}
110	if err = addResponseErrorMiddleware(stack); err != nil {
111		return err
112	}
113	if err = addRequestResponseLogging(stack, options); err != nil {
114		return err
115	}
116	return nil
117}
118
119// ListSecurityProfilesAPIClient is a client that implements the
120// ListSecurityProfiles operation.
121type ListSecurityProfilesAPIClient interface {
122	ListSecurityProfiles(context.Context, *ListSecurityProfilesInput, ...func(*Options)) (*ListSecurityProfilesOutput, error)
123}
124
125var _ ListSecurityProfilesAPIClient = (*Client)(nil)
126
127// ListSecurityProfilesPaginatorOptions is the paginator options for
128// ListSecurityProfiles
129type ListSecurityProfilesPaginatorOptions struct {
130	// The maximum number of results to return at one time.
131	Limit int32
132
133	// Set to true if pagination should stop if the service returns a pagination token
134	// that matches the most recent token provided to the service.
135	StopOnDuplicateToken bool
136}
137
138// ListSecurityProfilesPaginator is a paginator for ListSecurityProfiles
139type ListSecurityProfilesPaginator struct {
140	options   ListSecurityProfilesPaginatorOptions
141	client    ListSecurityProfilesAPIClient
142	params    *ListSecurityProfilesInput
143	nextToken *string
144	firstPage bool
145}
146
147// NewListSecurityProfilesPaginator returns a new ListSecurityProfilesPaginator
148func NewListSecurityProfilesPaginator(client ListSecurityProfilesAPIClient, params *ListSecurityProfilesInput, optFns ...func(*ListSecurityProfilesPaginatorOptions)) *ListSecurityProfilesPaginator {
149	options := ListSecurityProfilesPaginatorOptions{}
150	if params.MaxResults != nil {
151		options.Limit = *params.MaxResults
152	}
153
154	for _, fn := range optFns {
155		fn(&options)
156	}
157
158	if params == nil {
159		params = &ListSecurityProfilesInput{}
160	}
161
162	return &ListSecurityProfilesPaginator{
163		options:   options,
164		client:    client,
165		params:    params,
166		firstPage: true,
167	}
168}
169
170// HasMorePages returns a boolean indicating whether more pages are available
171func (p *ListSecurityProfilesPaginator) HasMorePages() bool {
172	return p.firstPage || p.nextToken != nil
173}
174
175// NextPage retrieves the next ListSecurityProfiles page.
176func (p *ListSecurityProfilesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListSecurityProfilesOutput, error) {
177	if !p.HasMorePages() {
178		return nil, fmt.Errorf("no more pages available")
179	}
180
181	params := *p.params
182	params.NextToken = p.nextToken
183
184	var limit *int32
185	if p.options.Limit > 0 {
186		limit = &p.options.Limit
187	}
188	params.MaxResults = limit
189
190	result, err := p.client.ListSecurityProfiles(ctx, &params, optFns...)
191	if err != nil {
192		return nil, err
193	}
194	p.firstPage = false
195
196	prevToken := p.nextToken
197	p.nextToken = result.NextToken
198
199	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
200		p.nextToken = nil
201	}
202
203	return result, nil
204}
205
206func newServiceMetadataMiddleware_opListSecurityProfiles(region string) *awsmiddleware.RegisterServiceMetadata {
207	return &awsmiddleware.RegisterServiceMetadata{
208		Region:        region,
209		ServiceID:     ServiceID,
210		SigningName:   "execute-api",
211		OperationName: "ListSecurityProfiles",
212	}
213}
214