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 "time" 14) 15 16// Gets a list of the projects in an AWS account. 17func (c *Client) ListProjects(ctx context.Context, params *ListProjectsInput, optFns ...func(*Options)) (*ListProjectsOutput, error) { 18 if params == nil { 19 params = &ListProjectsInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListProjects", params, optFns, addOperationListProjectsMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListProjectsOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListProjectsInput struct { 33 34 // A filter that returns the projects that were created after a specified time. 35 CreationTimeAfter *time.Time 36 37 // A filter that returns the projects that were created before a specified time. 38 CreationTimeBefore *time.Time 39 40 // The maximum number of projects to return in the response. 41 MaxResults *int32 42 43 // A filter that returns the projects whose name contains a specified string. 44 NameContains *string 45 46 // If the result of the previous ListProjects request was truncated, the response 47 // includes a NextToken. To retrieve the next set of projects, use the token in the 48 // next request. 49 NextToken *string 50 51 // The field by which to sort results. The default is CreationTime. 52 SortBy types.ProjectSortBy 53 54 // The sort order for results. The default is Ascending. 55 SortOrder types.ProjectSortOrder 56} 57 58type ListProjectsOutput struct { 59 60 // A list of summaries of projects. 61 // 62 // This member is required. 63 ProjectSummaryList []types.ProjectSummary 64 65 // If the result of the previous ListCompilationJobs request was truncated, the 66 // response includes a NextToken. To retrieve the next set of model compilation 67 // jobs, use the token in the next request. 68 NextToken *string 69 70 // Metadata pertaining to the operation's result. 71 ResultMetadata middleware.Metadata 72} 73 74func addOperationListProjectsMiddlewares(stack *middleware.Stack, options Options) (err error) { 75 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListProjects{}, middleware.After) 76 if err != nil { 77 return err 78 } 79 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListProjects{}, middleware.After) 80 if err != nil { 81 return err 82 } 83 if err = addSetLoggerMiddleware(stack, options); err != nil { 84 return err 85 } 86 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 87 return err 88 } 89 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 90 return err 91 } 92 if err = addResolveEndpointMiddleware(stack, options); err != nil { 93 return err 94 } 95 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 96 return err 97 } 98 if err = addRetryMiddlewares(stack, options); err != nil { 99 return err 100 } 101 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 102 return err 103 } 104 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 105 return err 106 } 107 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 108 return err 109 } 110 if err = addClientUserAgent(stack); err != nil { 111 return err 112 } 113 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 114 return err 115 } 116 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 117 return err 118 } 119 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListProjects(options.Region), middleware.Before); err != nil { 120 return err 121 } 122 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addResponseErrorMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addRequestResponseLogging(stack, options); err != nil { 129 return err 130 } 131 return nil 132} 133 134// ListProjectsAPIClient is a client that implements the ListProjects operation. 135type ListProjectsAPIClient interface { 136 ListProjects(context.Context, *ListProjectsInput, ...func(*Options)) (*ListProjectsOutput, error) 137} 138 139var _ ListProjectsAPIClient = (*Client)(nil) 140 141// ListProjectsPaginatorOptions is the paginator options for ListProjects 142type ListProjectsPaginatorOptions struct { 143 // The maximum number of projects to return in the response. 144 Limit int32 145 146 // Set to true if pagination should stop if the service returns a pagination token 147 // that matches the most recent token provided to the service. 148 StopOnDuplicateToken bool 149} 150 151// ListProjectsPaginator is a paginator for ListProjects 152type ListProjectsPaginator struct { 153 options ListProjectsPaginatorOptions 154 client ListProjectsAPIClient 155 params *ListProjectsInput 156 nextToken *string 157 firstPage bool 158} 159 160// NewListProjectsPaginator returns a new ListProjectsPaginator 161func NewListProjectsPaginator(client ListProjectsAPIClient, params *ListProjectsInput, optFns ...func(*ListProjectsPaginatorOptions)) *ListProjectsPaginator { 162 options := ListProjectsPaginatorOptions{} 163 if params.MaxResults != nil { 164 options.Limit = *params.MaxResults 165 } 166 167 for _, fn := range optFns { 168 fn(&options) 169 } 170 171 if params == nil { 172 params = &ListProjectsInput{} 173 } 174 175 return &ListProjectsPaginator{ 176 options: options, 177 client: client, 178 params: params, 179 firstPage: true, 180 } 181} 182 183// HasMorePages returns a boolean indicating whether more pages are available 184func (p *ListProjectsPaginator) HasMorePages() bool { 185 return p.firstPage || p.nextToken != nil 186} 187 188// NextPage retrieves the next ListProjects page. 189func (p *ListProjectsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListProjectsOutput, error) { 190 if !p.HasMorePages() { 191 return nil, fmt.Errorf("no more pages available") 192 } 193 194 params := *p.params 195 params.NextToken = p.nextToken 196 197 var limit *int32 198 if p.options.Limit > 0 { 199 limit = &p.options.Limit 200 } 201 params.MaxResults = limit 202 203 result, err := p.client.ListProjects(ctx, ¶ms, optFns...) 204 if err != nil { 205 return nil, err 206 } 207 p.firstPage = false 208 209 prevToken := p.nextToken 210 p.nextToken = result.NextToken 211 212 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 213 p.nextToken = nil 214 } 215 216 return result, nil 217} 218 219func newServiceMetadataMiddleware_opListProjects(region string) *awsmiddleware.RegisterServiceMetadata { 220 return &awsmiddleware.RegisterServiceMetadata{ 221 Region: region, 222 ServiceID: ServiceID, 223 SigningName: "sagemaker", 224 OperationName: "ListProjects", 225 } 226} 227