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