1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package transfer 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/transfer/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists the users for a file transfer protocol-enabled server that you specify by 16// passing the ServerId parameter. 17func (c *Client) ListUsers(ctx context.Context, params *ListUsersInput, optFns ...func(*Options)) (*ListUsersOutput, error) { 18 if params == nil { 19 params = &ListUsersInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListUsers", params, optFns, addOperationListUsersMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListUsersOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListUsersInput struct { 33 34 // A system-assigned unique identifier for a server that has users assigned to it. 35 // 36 // This member is required. 37 ServerId *string 38 39 // Specifies the number of users to return as a response to the ListUsers request. 40 MaxResults *int32 41 42 // When you can get additional results from the ListUsers call, a NextToken 43 // parameter is returned in the output. You can then pass in a subsequent command 44 // to the NextToken parameter to continue listing additional users. 45 NextToken *string 46} 47 48type ListUsersOutput struct { 49 50 // A system-assigned unique identifier for a server that the users are assigned to. 51 // 52 // This member is required. 53 ServerId *string 54 55 // Returns the user accounts and their properties for the ServerId value that you 56 // specify. 57 // 58 // This member is required. 59 Users []types.ListedUser 60 61 // When you can get additional results from the ListUsers call, a NextToken 62 // parameter is returned in the output. You can then pass in a subsequent command 63 // to the NextToken parameter to continue listing additional users. 64 NextToken *string 65 66 // Metadata pertaining to the operation's result. 67 ResultMetadata middleware.Metadata 68} 69 70func addOperationListUsersMiddlewares(stack *middleware.Stack, options Options) (err error) { 71 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListUsers{}, middleware.After) 72 if err != nil { 73 return err 74 } 75 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListUsers{}, middleware.After) 76 if err != nil { 77 return err 78 } 79 if err = addSetLoggerMiddleware(stack, options); err != nil { 80 return err 81 } 82 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 83 return err 84 } 85 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 86 return err 87 } 88 if err = addResolveEndpointMiddleware(stack, options); err != nil { 89 return err 90 } 91 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 92 return err 93 } 94 if err = addRetryMiddlewares(stack, options); err != nil { 95 return err 96 } 97 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 98 return err 99 } 100 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 101 return err 102 } 103 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 104 return err 105 } 106 if err = addClientUserAgent(stack); err != nil { 107 return err 108 } 109 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 110 return err 111 } 112 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 113 return err 114 } 115 if err = addOpListUsersValidationMiddleware(stack); err != nil { 116 return err 117 } 118 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListUsers(options.Region), middleware.Before); err != nil { 119 return err 120 } 121 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 122 return err 123 } 124 if err = addResponseErrorMiddleware(stack); err != nil { 125 return err 126 } 127 if err = addRequestResponseLogging(stack, options); err != nil { 128 return err 129 } 130 return nil 131} 132 133// ListUsersAPIClient is a client that implements the ListUsers operation. 134type ListUsersAPIClient interface { 135 ListUsers(context.Context, *ListUsersInput, ...func(*Options)) (*ListUsersOutput, error) 136} 137 138var _ ListUsersAPIClient = (*Client)(nil) 139 140// ListUsersPaginatorOptions is the paginator options for ListUsers 141type ListUsersPaginatorOptions struct { 142 // Specifies the number of users to return as a response to the ListUsers request. 143 Limit int32 144 145 // Set to true if pagination should stop if the service returns a pagination token 146 // that matches the most recent token provided to the service. 147 StopOnDuplicateToken bool 148} 149 150// ListUsersPaginator is a paginator for ListUsers 151type ListUsersPaginator struct { 152 options ListUsersPaginatorOptions 153 client ListUsersAPIClient 154 params *ListUsersInput 155 nextToken *string 156 firstPage bool 157} 158 159// NewListUsersPaginator returns a new ListUsersPaginator 160func NewListUsersPaginator(client ListUsersAPIClient, params *ListUsersInput, optFns ...func(*ListUsersPaginatorOptions)) *ListUsersPaginator { 161 if params == nil { 162 params = &ListUsersInput{} 163 } 164 165 options := ListUsersPaginatorOptions{} 166 if params.MaxResults != nil { 167 options.Limit = *params.MaxResults 168 } 169 170 for _, fn := range optFns { 171 fn(&options) 172 } 173 174 return &ListUsersPaginator{ 175 options: options, 176 client: client, 177 params: params, 178 firstPage: true, 179 } 180} 181 182// HasMorePages returns a boolean indicating whether more pages are available 183func (p *ListUsersPaginator) HasMorePages() bool { 184 return p.firstPage || p.nextToken != nil 185} 186 187// NextPage retrieves the next ListUsers page. 188func (p *ListUsersPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListUsersOutput, error) { 189 if !p.HasMorePages() { 190 return nil, fmt.Errorf("no more pages available") 191 } 192 193 params := *p.params 194 params.NextToken = p.nextToken 195 196 var limit *int32 197 if p.options.Limit > 0 { 198 limit = &p.options.Limit 199 } 200 params.MaxResults = limit 201 202 result, err := p.client.ListUsers(ctx, ¶ms, optFns...) 203 if err != nil { 204 return nil, err 205 } 206 p.firstPage = false 207 208 prevToken := p.nextToken 209 p.nextToken = result.NextToken 210 211 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 212 p.nextToken = nil 213 } 214 215 return result, nil 216} 217 218func newServiceMetadataMiddleware_opListUsers(region string) *awsmiddleware.RegisterServiceMetadata { 219 return &awsmiddleware.RegisterServiceMetadata{ 220 Region: region, 221 ServiceID: ServiceID, 222 SigningName: "transfer", 223 OperationName: "ListUsers", 224 } 225} 226