1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package workdocs
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/workdocs/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Describes the specified users. You can describe all users or filter the results
16// (for example, by status or organization). By default, Amazon WorkDocs returns
17// the first 24 active or pending users. If there are more results, the response
18// includes a marker that you can use to request the next set of results.
19func (c *Client) DescribeUsers(ctx context.Context, params *DescribeUsersInput, optFns ...func(*Options)) (*DescribeUsersOutput, error) {
20	if params == nil {
21		params = &DescribeUsersInput{}
22	}
23
24	result, metadata, err := c.invokeOperation(ctx, "DescribeUsers", params, optFns, addOperationDescribeUsersMiddlewares)
25	if err != nil {
26		return nil, err
27	}
28
29	out := result.(*DescribeUsersOutput)
30	out.ResultMetadata = metadata
31	return out, nil
32}
33
34type DescribeUsersInput struct {
35
36	// Amazon WorkDocs authentication token. Not required when using AWS administrator
37	// credentials to access the API.
38	AuthenticationToken *string
39
40	// A comma-separated list of values. Specify "STORAGE_METADATA" to include the user
41	// storage quota and utilization information.
42	Fields *string
43
44	// The state of the users. Specify "ALL" to include inactive users.
45	Include types.UserFilterType
46
47	// The maximum number of items to return.
48	Limit *int32
49
50	// The marker for the next set of results. (You received this marker from a
51	// previous call.)
52	Marker *string
53
54	// The order for the results.
55	Order types.OrderType
56
57	// The ID of the organization.
58	OrganizationId *string
59
60	// A query to filter users by user name.
61	Query *string
62
63	// The sorting criteria.
64	Sort types.UserSortType
65
66	// The IDs of the users.
67	UserIds *string
68}
69
70type DescribeUsersOutput struct {
71
72	// The marker to use when requesting the next set of results. If there are no
73	// additional results, the string is empty.
74	Marker *string
75
76	// The total number of users included in the results.
77	//
78	// Deprecated: This member has been deprecated.
79	TotalNumberOfUsers *int64
80
81	// The users.
82	Users []types.User
83
84	// Metadata pertaining to the operation's result.
85	ResultMetadata middleware.Metadata
86}
87
88func addOperationDescribeUsersMiddlewares(stack *middleware.Stack, options Options) (err error) {
89	err = stack.Serialize.Add(&awsRestjson1_serializeOpDescribeUsers{}, middleware.After)
90	if err != nil {
91		return err
92	}
93	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpDescribeUsers{}, middleware.After)
94	if err != nil {
95		return err
96	}
97	if err = addSetLoggerMiddleware(stack, options); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
101		return err
102	}
103	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
104		return err
105	}
106	if err = addResolveEndpointMiddleware(stack, options); err != nil {
107		return err
108	}
109	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
110		return err
111	}
112	if err = addRetryMiddlewares(stack, options); err != nil {
113		return err
114	}
115	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
116		return err
117	}
118	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
119		return err
120	}
121	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
122		return err
123	}
124	if err = addClientUserAgent(stack); err != nil {
125		return err
126	}
127	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
128		return err
129	}
130	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
131		return err
132	}
133	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeUsers(options.Region), middleware.Before); err != nil {
134		return err
135	}
136	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
137		return err
138	}
139	if err = addResponseErrorMiddleware(stack); err != nil {
140		return err
141	}
142	if err = addRequestResponseLogging(stack, options); err != nil {
143		return err
144	}
145	return nil
146}
147
148// DescribeUsersAPIClient is a client that implements the DescribeUsers operation.
149type DescribeUsersAPIClient interface {
150	DescribeUsers(context.Context, *DescribeUsersInput, ...func(*Options)) (*DescribeUsersOutput, error)
151}
152
153var _ DescribeUsersAPIClient = (*Client)(nil)
154
155// DescribeUsersPaginatorOptions is the paginator options for DescribeUsers
156type DescribeUsersPaginatorOptions struct {
157	// The maximum number of items to return.
158	Limit int32
159
160	// Set to true if pagination should stop if the service returns a pagination token
161	// that matches the most recent token provided to the service.
162	StopOnDuplicateToken bool
163}
164
165// DescribeUsersPaginator is a paginator for DescribeUsers
166type DescribeUsersPaginator struct {
167	options   DescribeUsersPaginatorOptions
168	client    DescribeUsersAPIClient
169	params    *DescribeUsersInput
170	nextToken *string
171	firstPage bool
172}
173
174// NewDescribeUsersPaginator returns a new DescribeUsersPaginator
175func NewDescribeUsersPaginator(client DescribeUsersAPIClient, params *DescribeUsersInput, optFns ...func(*DescribeUsersPaginatorOptions)) *DescribeUsersPaginator {
176	if params == nil {
177		params = &DescribeUsersInput{}
178	}
179
180	options := DescribeUsersPaginatorOptions{}
181	if params.Limit != nil {
182		options.Limit = *params.Limit
183	}
184
185	for _, fn := range optFns {
186		fn(&options)
187	}
188
189	return &DescribeUsersPaginator{
190		options:   options,
191		client:    client,
192		params:    params,
193		firstPage: true,
194	}
195}
196
197// HasMorePages returns a boolean indicating whether more pages are available
198func (p *DescribeUsersPaginator) HasMorePages() bool {
199	return p.firstPage || p.nextToken != nil
200}
201
202// NextPage retrieves the next DescribeUsers page.
203func (p *DescribeUsersPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeUsersOutput, error) {
204	if !p.HasMorePages() {
205		return nil, fmt.Errorf("no more pages available")
206	}
207
208	params := *p.params
209	params.Marker = p.nextToken
210
211	var limit *int32
212	if p.options.Limit > 0 {
213		limit = &p.options.Limit
214	}
215	params.Limit = limit
216
217	result, err := p.client.DescribeUsers(ctx, &params, optFns...)
218	if err != nil {
219		return nil, err
220	}
221	p.firstPage = false
222
223	prevToken := p.nextToken
224	p.nextToken = result.Marker
225
226	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
227		p.nextToken = nil
228	}
229
230	return result, nil
231}
232
233func newServiceMetadataMiddleware_opDescribeUsers(region string) *awsmiddleware.RegisterServiceMetadata {
234	return &awsmiddleware.RegisterServiceMetadata{
235		Region:        region,
236		ServiceID:     ServiceID,
237		SigningName:   "workdocs",
238		OperationName: "DescribeUsers",
239	}
240}
241