code.dwrz.net

Go monorepo.
Log | Files | Refs

api_op_ListAccountRoles.go (6373B)


      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 roles that are assigned to the user for a given AWS account.
     15 func (c *Client) ListAccountRoles(ctx context.Context, params *ListAccountRolesInput, optFns ...func(*Options)) (*ListAccountRolesOutput, error) {
     16 	if params == nil {
     17 		params = &ListAccountRolesInput{}
     18 	}
     19 
     20 	result, metadata, err := c.invokeOperation(ctx, "ListAccountRoles", params, optFns, c.addOperationListAccountRolesMiddlewares)
     21 	if err != nil {
     22 		return nil, err
     23 	}
     24 
     25 	out := result.(*ListAccountRolesOutput)
     26 	out.ResultMetadata = metadata
     27 	return out, nil
     28 }
     29 
     30 type ListAccountRolesInput struct {
     31 
     32 	// The token issued by the CreateToken API call. For more information, see
     33 	// CreateToken
     34 	// (https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateToken.html)
     35 	// in the IAM Identity Center OIDC API Reference Guide.
     36 	//
     37 	// This member is required.
     38 	AccessToken *string
     39 
     40 	// The identifier for the AWS account that is assigned to the user.
     41 	//
     42 	// This member is required.
     43 	AccountId *string
     44 
     45 	// The number of items that clients can request per page.
     46 	MaxResults *int32
     47 
     48 	// The page token from the previous response output when you request subsequent
     49 	// pages.
     50 	NextToken *string
     51 
     52 	noSmithyDocumentSerde
     53 }
     54 
     55 type ListAccountRolesOutput struct {
     56 
     57 	// The page token client that is used to retrieve the list of accounts.
     58 	NextToken *string
     59 
     60 	// A paginated response with the list of roles and the next token if more results
     61 	// are available.
     62 	RoleList []types.RoleInfo
     63 
     64 	// Metadata pertaining to the operation's result.
     65 	ResultMetadata middleware.Metadata
     66 
     67 	noSmithyDocumentSerde
     68 }
     69 
     70 func (c *Client) addOperationListAccountRolesMiddlewares(stack *middleware.Stack, options Options) (err error) {
     71 	err = stack.Serialize.Add(&awsRestjson1_serializeOpListAccountRoles{}, middleware.After)
     72 	if err != nil {
     73 		return err
     74 	}
     75 	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListAccountRoles{}, 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 = addRetryMiddlewares(stack, options); err != nil {
     92 		return err
     93 	}
     94 	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
     95 		return err
     96 	}
     97 	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
     98 		return err
     99 	}
    100 	if err = addClientUserAgent(stack); err != nil {
    101 		return err
    102 	}
    103 	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
    104 		return err
    105 	}
    106 	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
    107 		return err
    108 	}
    109 	if err = addOpListAccountRolesValidationMiddleware(stack); err != nil {
    110 		return err
    111 	}
    112 	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListAccountRoles(options.Region), middleware.Before); err != nil {
    113 		return err
    114 	}
    115 	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
    116 		return err
    117 	}
    118 	if err = addResponseErrorMiddleware(stack); err != nil {
    119 		return err
    120 	}
    121 	if err = addRequestResponseLogging(stack, options); err != nil {
    122 		return err
    123 	}
    124 	return nil
    125 }
    126 
    127 // ListAccountRolesAPIClient is a client that implements the ListAccountRoles
    128 // operation.
    129 type ListAccountRolesAPIClient interface {
    130 	ListAccountRoles(context.Context, *ListAccountRolesInput, ...func(*Options)) (*ListAccountRolesOutput, error)
    131 }
    132 
    133 var _ ListAccountRolesAPIClient = (*Client)(nil)
    134 
    135 // ListAccountRolesPaginatorOptions is the paginator options for ListAccountRoles
    136 type ListAccountRolesPaginatorOptions struct {
    137 	// The number of items that clients can request per page.
    138 	Limit int32
    139 
    140 	// Set to true if pagination should stop if the service returns a pagination token
    141 	// that matches the most recent token provided to the service.
    142 	StopOnDuplicateToken bool
    143 }
    144 
    145 // ListAccountRolesPaginator is a paginator for ListAccountRoles
    146 type ListAccountRolesPaginator struct {
    147 	options   ListAccountRolesPaginatorOptions
    148 	client    ListAccountRolesAPIClient
    149 	params    *ListAccountRolesInput
    150 	nextToken *string
    151 	firstPage bool
    152 }
    153 
    154 // NewListAccountRolesPaginator returns a new ListAccountRolesPaginator
    155 func NewListAccountRolesPaginator(client ListAccountRolesAPIClient, params *ListAccountRolesInput, optFns ...func(*ListAccountRolesPaginatorOptions)) *ListAccountRolesPaginator {
    156 	if params == nil {
    157 		params = &ListAccountRolesInput{}
    158 	}
    159 
    160 	options := ListAccountRolesPaginatorOptions{}
    161 	if params.MaxResults != nil {
    162 		options.Limit = *params.MaxResults
    163 	}
    164 
    165 	for _, fn := range optFns {
    166 		fn(&options)
    167 	}
    168 
    169 	return &ListAccountRolesPaginator{
    170 		options:   options,
    171 		client:    client,
    172 		params:    params,
    173 		firstPage: true,
    174 		nextToken: params.NextToken,
    175 	}
    176 }
    177 
    178 // HasMorePages returns a boolean indicating whether more pages are available
    179 func (p *ListAccountRolesPaginator) HasMorePages() bool {
    180 	return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
    181 }
    182 
    183 // NextPage retrieves the next ListAccountRoles page.
    184 func (p *ListAccountRolesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListAccountRolesOutput, error) {
    185 	if !p.HasMorePages() {
    186 		return nil, fmt.Errorf("no more pages available")
    187 	}
    188 
    189 	params := *p.params
    190 	params.NextToken = p.nextToken
    191 
    192 	var limit *int32
    193 	if p.options.Limit > 0 {
    194 		limit = &p.options.Limit
    195 	}
    196 	params.MaxResults = limit
    197 
    198 	result, err := p.client.ListAccountRoles(ctx, &params, optFns...)
    199 	if err != nil {
    200 		return nil, err
    201 	}
    202 	p.firstPage = false
    203 
    204 	prevToken := p.nextToken
    205 	p.nextToken = result.NextToken
    206 
    207 	if p.options.StopOnDuplicateToken &&
    208 		prevToken != nil &&
    209 		p.nextToken != nil &&
    210 		*prevToken == *p.nextToken {
    211 		p.nextToken = nil
    212 	}
    213 
    214 	return result, nil
    215 }
    216 
    217 func newServiceMetadataMiddleware_opListAccountRoles(region string) *awsmiddleware.RegisterServiceMetadata {
    218 	return &awsmiddleware.RegisterServiceMetadata{
    219 		Region:        region,
    220 		ServiceID:     ServiceID,
    221 		OperationName: "ListAccountRoles",
    222 	}
    223 }