1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package sagemaker
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/sagemaker/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists apps.
16func (c *Client) ListApps(ctx context.Context, params *ListAppsInput, optFns ...func(*Options)) (*ListAppsOutput, error) {
17	if params == nil {
18		params = &ListAppsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListApps", params, optFns, addOperationListAppsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListAppsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListAppsInput struct {
32
33	// A parameter to search for the domain ID.
34	DomainIdEquals *string
35
36	// Returns a list up to a specified limit.
37	MaxResults *int32
38
39	// If the previous response was truncated, you will receive this token. Use it in
40	// your next request to receive the next set of results.
41	NextToken *string
42
43	// The parameter by which to sort the results. The default is CreationTime.
44	SortBy types.AppSortKey
45
46	// The sort order for the results. The default is Ascending.
47	SortOrder types.SortOrder
48
49	// A parameter to search by user profile name.
50	UserProfileNameEquals *string
51}
52
53type ListAppsOutput struct {
54
55	// The list of apps.
56	Apps []types.AppDetails
57
58	// If the previous response was truncated, you will receive this token. Use it in
59	// your next request to receive the next set of results.
60	NextToken *string
61
62	// Metadata pertaining to the operation's result.
63	ResultMetadata middleware.Metadata
64}
65
66func addOperationListAppsMiddlewares(stack *middleware.Stack, options Options) (err error) {
67	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListApps{}, middleware.After)
68	if err != nil {
69		return err
70	}
71	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListApps{}, middleware.After)
72	if err != nil {
73		return err
74	}
75	if err = addSetLoggerMiddleware(stack, options); err != nil {
76		return err
77	}
78	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
79		return err
80	}
81	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
82		return err
83	}
84	if err = addResolveEndpointMiddleware(stack, options); err != nil {
85		return err
86	}
87	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
88		return err
89	}
90	if err = addRetryMiddlewares(stack, options); err != nil {
91		return err
92	}
93	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
94		return err
95	}
96	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
97		return err
98	}
99	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
100		return err
101	}
102	if err = addClientUserAgent(stack); err != nil {
103		return err
104	}
105	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
106		return err
107	}
108	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
109		return err
110	}
111	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListApps(options.Region), middleware.Before); err != nil {
112		return err
113	}
114	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
115		return err
116	}
117	if err = addResponseErrorMiddleware(stack); err != nil {
118		return err
119	}
120	if err = addRequestResponseLogging(stack, options); err != nil {
121		return err
122	}
123	return nil
124}
125
126// ListAppsAPIClient is a client that implements the ListApps operation.
127type ListAppsAPIClient interface {
128	ListApps(context.Context, *ListAppsInput, ...func(*Options)) (*ListAppsOutput, error)
129}
130
131var _ ListAppsAPIClient = (*Client)(nil)
132
133// ListAppsPaginatorOptions is the paginator options for ListApps
134type ListAppsPaginatorOptions struct {
135	// Returns a list up to a specified limit.
136	Limit int32
137
138	// Set to true if pagination should stop if the service returns a pagination token
139	// that matches the most recent token provided to the service.
140	StopOnDuplicateToken bool
141}
142
143// ListAppsPaginator is a paginator for ListApps
144type ListAppsPaginator struct {
145	options   ListAppsPaginatorOptions
146	client    ListAppsAPIClient
147	params    *ListAppsInput
148	nextToken *string
149	firstPage bool
150}
151
152// NewListAppsPaginator returns a new ListAppsPaginator
153func NewListAppsPaginator(client ListAppsAPIClient, params *ListAppsInput, optFns ...func(*ListAppsPaginatorOptions)) *ListAppsPaginator {
154	options := ListAppsPaginatorOptions{}
155	if params.MaxResults != nil {
156		options.Limit = *params.MaxResults
157	}
158
159	for _, fn := range optFns {
160		fn(&options)
161	}
162
163	if params == nil {
164		params = &ListAppsInput{}
165	}
166
167	return &ListAppsPaginator{
168		options:   options,
169		client:    client,
170		params:    params,
171		firstPage: true,
172	}
173}
174
175// HasMorePages returns a boolean indicating whether more pages are available
176func (p *ListAppsPaginator) HasMorePages() bool {
177	return p.firstPage || p.nextToken != nil
178}
179
180// NextPage retrieves the next ListApps page.
181func (p *ListAppsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAppsOutput, error) {
182	if !p.HasMorePages() {
183		return nil, fmt.Errorf("no more pages available")
184	}
185
186	params := *p.params
187	params.NextToken = p.nextToken
188
189	var limit *int32
190	if p.options.Limit > 0 {
191		limit = &p.options.Limit
192	}
193	params.MaxResults = limit
194
195	result, err := p.client.ListApps(ctx, &params, optFns...)
196	if err != nil {
197		return nil, err
198	}
199	p.firstPage = false
200
201	prevToken := p.nextToken
202	p.nextToken = result.NextToken
203
204	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
205		p.nextToken = nil
206	}
207
208	return result, nil
209}
210
211func newServiceMetadataMiddleware_opListApps(region string) *awsmiddleware.RegisterServiceMetadata {
212	return &awsmiddleware.RegisterServiceMetadata{
213		Region:        region,
214		ServiceID:     ServiceID,
215		SigningName:   "sagemaker",
216		OperationName: "ListApps",
217	}
218}
219