api_op_ListAccounts.go (6377B)
1 // Code generated by smithy-go-codegen DO NOT EDIT. 2 3 package sso 4 5 import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/service/sso/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12 ) 13 14 // Lists all AWS accounts assigned to the user. These AWS accounts are assigned by 15 // the administrator of the account. For more information, see Assign User Access 16 // (https://docs.aws.amazon.com/singlesignon/latest/userguide/useraccess.html#assignusers) 17 // in the IAM Identity Center User Guide. This operation returns a paginated 18 // response. 19 func (c *Client) ListAccounts(ctx context.Context, params *ListAccountsInput, optFns ...func(*Options)) (*ListAccountsOutput, error) { 20 if params == nil { 21 params = &ListAccountsInput{} 22 } 23 24 result, metadata, err := c.invokeOperation(ctx, "ListAccounts", params, optFns, c.addOperationListAccountsMiddlewares) 25 if err != nil { 26 return nil, err 27 } 28 29 out := result.(*ListAccountsOutput) 30 out.ResultMetadata = metadata 31 return out, nil 32 } 33 34 type ListAccountsInput struct { 35 36 // The token issued by the CreateToken API call. For more information, see 37 // CreateToken 38 // (https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateToken.html) 39 // in the IAM Identity Center OIDC API Reference Guide. 40 // 41 // This member is required. 42 AccessToken *string 43 44 // This is the number of items clients can request per page. 45 MaxResults *int32 46 47 // (Optional) When requesting subsequent pages, this is the page token from the 48 // previous response output. 49 NextToken *string 50 51 noSmithyDocumentSerde 52 } 53 54 type ListAccountsOutput struct { 55 56 // A paginated response with the list of account information and the next token if 57 // more results are available. 58 AccountList []types.AccountInfo 59 60 // The page token client that is used to retrieve the list of accounts. 61 NextToken *string 62 63 // Metadata pertaining to the operation's result. 64 ResultMetadata middleware.Metadata 65 66 noSmithyDocumentSerde 67 } 68 69 func (c *Client) addOperationListAccountsMiddlewares(stack *middleware.Stack, options Options) (err error) { 70 err = stack.Serialize.Add(&awsRestjson1_serializeOpListAccounts{}, middleware.After) 71 if err != nil { 72 return err 73 } 74 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListAccounts{}, middleware.After) 75 if err != nil { 76 return err 77 } 78 if err = addSetLoggerMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 82 return err 83 } 84 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 85 return err 86 } 87 if err = addResolveEndpointMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = addRetryMiddlewares(stack, options); err != nil { 91 return err 92 } 93 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 94 return err 95 } 96 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 97 return err 98 } 99 if err = addClientUserAgent(stack); err != nil { 100 return err 101 } 102 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 103 return err 104 } 105 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 106 return err 107 } 108 if err = addOpListAccountsValidationMiddleware(stack); err != nil { 109 return err 110 } 111 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAccounts(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 // ListAccountsAPIClient is a client that implements the ListAccounts operation. 127 type ListAccountsAPIClient interface { 128 ListAccounts(context.Context, *ListAccountsInput, ...func(*Options)) (*ListAccountsOutput, error) 129 } 130 131 var _ ListAccountsAPIClient = (*Client)(nil) 132 133 // ListAccountsPaginatorOptions is the paginator options for ListAccounts 134 type ListAccountsPaginatorOptions struct { 135 // This is the number of items clients can request per page. 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 // ListAccountsPaginator is a paginator for ListAccounts 144 type ListAccountsPaginator struct { 145 options ListAccountsPaginatorOptions 146 client ListAccountsAPIClient 147 params *ListAccountsInput 148 nextToken *string 149 firstPage bool 150 } 151 152 // NewListAccountsPaginator returns a new ListAccountsPaginator 153 func NewListAccountsPaginator(client ListAccountsAPIClient, params *ListAccountsInput, optFns ...func(*ListAccountsPaginatorOptions)) *ListAccountsPaginator { 154 if params == nil { 155 params = &ListAccountsInput{} 156 } 157 158 options := ListAccountsPaginatorOptions{} 159 if params.MaxResults != nil { 160 options.Limit = *params.MaxResults 161 } 162 163 for _, fn := range optFns { 164 fn(&options) 165 } 166 167 return &ListAccountsPaginator{ 168 options: options, 169 client: client, 170 params: params, 171 firstPage: true, 172 nextToken: params.NextToken, 173 } 174 } 175 176 // HasMorePages returns a boolean indicating whether more pages are available 177 func (p *ListAccountsPaginator) HasMorePages() bool { 178 return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0) 179 } 180 181 // NextPage retrieves the next ListAccounts page. 182 func (p *ListAccountsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAccountsOutput, error) { 183 if !p.HasMorePages() { 184 return nil, fmt.Errorf("no more pages available") 185 } 186 187 params := *p.params 188 params.NextToken = p.nextToken 189 190 var limit *int32 191 if p.options.Limit > 0 { 192 limit = &p.options.Limit 193 } 194 params.MaxResults = limit 195 196 result, err := p.client.ListAccounts(ctx, ¶ms, optFns...) 197 if err != nil { 198 return nil, err 199 } 200 p.firstPage = false 201 202 prevToken := p.nextToken 203 p.nextToken = result.NextToken 204 205 if p.options.StopOnDuplicateToken && 206 prevToken != nil && 207 p.nextToken != nil && 208 *prevToken == *p.nextToken { 209 p.nextToken = nil 210 } 211 212 return result, nil 213 } 214 215 func newServiceMetadataMiddleware_opListAccounts(region string) *awsmiddleware.RegisterServiceMetadata { 216 return &awsmiddleware.RegisterServiceMetadata{ 217 Region: region, 218 ServiceID: ServiceID, 219 OperationName: "ListAccounts", 220 } 221 }