src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

api_op_ListAccounts.go (6884B)


      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 (https://docs.aws.amazon.com/singlesignon/latest/userguide/useraccess.html#assignusers)
     16 // in the IAM Identity Center User Guide. This operation returns a paginated
     17 // response.
     18 func (c *Client) ListAccounts(ctx context.Context, params *ListAccountsInput, optFns ...func(*Options)) (*ListAccountsOutput, error) {
     19 	if params == nil {
     20 		params = &ListAccountsInput{}
     21 	}
     22 
     23 	result, metadata, err := c.invokeOperation(ctx, "ListAccounts", params, optFns, c.addOperationListAccountsMiddlewares)
     24 	if err != nil {
     25 		return nil, err
     26 	}
     27 
     28 	out := result.(*ListAccountsOutput)
     29 	out.ResultMetadata = metadata
     30 	return out, nil
     31 }
     32 
     33 type ListAccountsInput struct {
     34 
     35 	// The token issued by the CreateToken API call. For more information, see
     36 	// CreateToken (https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateToken.html)
     37 	// in the IAM Identity Center OIDC API Reference Guide.
     38 	//
     39 	// This member is required.
     40 	AccessToken *string
     41 
     42 	// This is the number of items clients can request per page.
     43 	MaxResults *int32
     44 
     45 	// (Optional) When requesting subsequent pages, this is the page token from the
     46 	// previous response output.
     47 	NextToken *string
     48 
     49 	noSmithyDocumentSerde
     50 }
     51 
     52 type ListAccountsOutput struct {
     53 
     54 	// A paginated response with the list of account information and the next token if
     55 	// more results are available.
     56 	AccountList []types.AccountInfo
     57 
     58 	// The page token client that is used to retrieve the list of accounts.
     59 	NextToken *string
     60 
     61 	// Metadata pertaining to the operation's result.
     62 	ResultMetadata middleware.Metadata
     63 
     64 	noSmithyDocumentSerde
     65 }
     66 
     67 func (c *Client) addOperationListAccountsMiddlewares(stack *middleware.Stack, options Options) (err error) {
     68 	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
     69 		return err
     70 	}
     71 	err = stack.Serialize.Add(&awsRestjson1_serializeOpListAccounts{}, middleware.After)
     72 	if err != nil {
     73 		return err
     74 	}
     75 	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListAccounts{}, middleware.After)
     76 	if err != nil {
     77 		return err
     78 	}
     79 	if err := addProtocolFinalizerMiddlewares(stack, options, "ListAccounts"); err != nil {
     80 		return fmt.Errorf("add protocol finalizers: %v", err)
     81 	}
     82 
     83 	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
     84 		return err
     85 	}
     86 	if err = addSetLoggerMiddleware(stack, options); err != nil {
     87 		return err
     88 	}
     89 	if err = addClientRequestID(stack); err != nil {
     90 		return err
     91 	}
     92 	if err = addComputeContentLength(stack); err != nil {
     93 		return err
     94 	}
     95 	if err = addResolveEndpointMiddleware(stack, options); err != nil {
     96 		return err
     97 	}
     98 	if err = addRetry(stack, options); err != nil {
     99 		return err
    100 	}
    101 	if err = addRawResponseToMetadata(stack); err != nil {
    102 		return err
    103 	}
    104 	if err = addRecordResponseTiming(stack); err != nil {
    105 		return err
    106 	}
    107 	if err = addClientUserAgent(stack, options); err != nil {
    108 		return err
    109 	}
    110 	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
    111 		return err
    112 	}
    113 	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
    114 		return err
    115 	}
    116 	if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
    117 		return err
    118 	}
    119 	if err = addOpListAccountsValidationMiddleware(stack); err != nil {
    120 		return err
    121 	}
    122 	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAccounts(options.Region), middleware.Before); err != nil {
    123 		return err
    124 	}
    125 	if err = addRecursionDetection(stack); err != nil {
    126 		return err
    127 	}
    128 	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
    129 		return err
    130 	}
    131 	if err = addResponseErrorMiddleware(stack); err != nil {
    132 		return err
    133 	}
    134 	if err = addRequestResponseLogging(stack, options); err != nil {
    135 		return err
    136 	}
    137 	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
    138 		return err
    139 	}
    140 	return nil
    141 }
    142 
    143 // ListAccountsAPIClient is a client that implements the ListAccounts operation.
    144 type ListAccountsAPIClient interface {
    145 	ListAccounts(context.Context, *ListAccountsInput, ...func(*Options)) (*ListAccountsOutput, error)
    146 }
    147 
    148 var _ ListAccountsAPIClient = (*Client)(nil)
    149 
    150 // ListAccountsPaginatorOptions is the paginator options for ListAccounts
    151 type ListAccountsPaginatorOptions struct {
    152 	// This is the number of items clients can request per page.
    153 	Limit int32
    154 
    155 	// Set to true if pagination should stop if the service returns a pagination token
    156 	// that matches the most recent token provided to the service.
    157 	StopOnDuplicateToken bool
    158 }
    159 
    160 // ListAccountsPaginator is a paginator for ListAccounts
    161 type ListAccountsPaginator struct {
    162 	options   ListAccountsPaginatorOptions
    163 	client    ListAccountsAPIClient
    164 	params    *ListAccountsInput
    165 	nextToken *string
    166 	firstPage bool
    167 }
    168 
    169 // NewListAccountsPaginator returns a new ListAccountsPaginator
    170 func NewListAccountsPaginator(client ListAccountsAPIClient, params *ListAccountsInput, optFns ...func(*ListAccountsPaginatorOptions)) *ListAccountsPaginator {
    171 	if params == nil {
    172 		params = &ListAccountsInput{}
    173 	}
    174 
    175 	options := ListAccountsPaginatorOptions{}
    176 	if params.MaxResults != nil {
    177 		options.Limit = *params.MaxResults
    178 	}
    179 
    180 	for _, fn := range optFns {
    181 		fn(&options)
    182 	}
    183 
    184 	return &ListAccountsPaginator{
    185 		options:   options,
    186 		client:    client,
    187 		params:    params,
    188 		firstPage: true,
    189 		nextToken: params.NextToken,
    190 	}
    191 }
    192 
    193 // HasMorePages returns a boolean indicating whether more pages are available
    194 func (p *ListAccountsPaginator) HasMorePages() bool {
    195 	return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
    196 }
    197 
    198 // NextPage retrieves the next ListAccounts page.
    199 func (p *ListAccountsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAccountsOutput, error) {
    200 	if !p.HasMorePages() {
    201 		return nil, fmt.Errorf("no more pages available")
    202 	}
    203 
    204 	params := *p.params
    205 	params.NextToken = p.nextToken
    206 
    207 	var limit *int32
    208 	if p.options.Limit > 0 {
    209 		limit = &p.options.Limit
    210 	}
    211 	params.MaxResults = limit
    212 
    213 	result, err := p.client.ListAccounts(ctx, &params, optFns...)
    214 	if err != nil {
    215 		return nil, err
    216 	}
    217 	p.firstPage = false
    218 
    219 	prevToken := p.nextToken
    220 	p.nextToken = result.NextToken
    221 
    222 	if p.options.StopOnDuplicateToken &&
    223 		prevToken != nil &&
    224 		p.nextToken != nil &&
    225 		*prevToken == *p.nextToken {
    226 		p.nextToken = nil
    227 	}
    228 
    229 	return result, nil
    230 }
    231 
    232 func newServiceMetadataMiddleware_opListAccounts(region string) *awsmiddleware.RegisterServiceMetadata {
    233 	return &awsmiddleware.RegisterServiceMetadata{
    234 		Region:        region,
    235 		ServiceID:     ServiceID,
    236 		OperationName: "ListAccounts",
    237 	}
    238 }