1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package iam 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/iam/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists the virtual MFA devices defined in the AWS account by assignment status. 16// If you do not specify an assignment status, the operation returns a list of all 17// virtual MFA devices. Assignment status can be Assigned, Unassigned, or Any. You 18// can paginate the results using the MaxItems and Marker parameters. 19func (c *Client) ListVirtualMFADevices(ctx context.Context, params *ListVirtualMFADevicesInput, optFns ...func(*Options)) (*ListVirtualMFADevicesOutput, error) { 20 if params == nil { 21 params = &ListVirtualMFADevicesInput{} 22 } 23 24 result, metadata, err := c.invokeOperation(ctx, "ListVirtualMFADevices", params, optFns, addOperationListVirtualMFADevicesMiddlewares) 25 if err != nil { 26 return nil, err 27 } 28 29 out := result.(*ListVirtualMFADevicesOutput) 30 out.ResultMetadata = metadata 31 return out, nil 32} 33 34type ListVirtualMFADevicesInput struct { 35 36 // The status (Unassigned or Assigned) of the devices to list. If you do not 37 // specify an AssignmentStatus, the operation defaults to Any, which lists both 38 // assigned and unassigned virtual MFA devices., 39 AssignmentStatus types.AssignmentStatusType 40 41 // Use this parameter only when paginating results and only after you receive a 42 // response indicating that the results are truncated. Set it to the value of the 43 // Marker element in the response that you received to indicate where the next call 44 // should start. 45 Marker *string 46 47 // Use this only when paginating results to indicate the maximum number of items 48 // you want in the response. If additional items exist beyond the maximum you 49 // specify, the IsTruncated response element is true. If you do not include this 50 // parameter, the number of items defaults to 100. Note that IAM might return fewer 51 // results, even when there are more results available. In that case, the 52 // IsTruncated response element returns true, and Marker contains a value to 53 // include in the subsequent call that tells the service where to continue from. 54 MaxItems *int32 55} 56 57// Contains the response to a successful ListVirtualMFADevices request. 58type ListVirtualMFADevicesOutput struct { 59 60 // The list of virtual MFA devices in the current account that match the 61 // AssignmentStatus value that was passed in the request. 62 // 63 // This member is required. 64 VirtualMFADevices []types.VirtualMFADevice 65 66 // A flag that indicates whether there are more items to return. If your results 67 // were truncated, you can make a subsequent pagination request using the Marker 68 // request parameter to retrieve more items. Note that IAM might return fewer than 69 // the MaxItems number of results even when there are more results available. We 70 // recommend that you check IsTruncated after every call to ensure that you receive 71 // all your results. 72 IsTruncated bool 73 74 // When IsTruncated is true, this element is present and contains the value to use 75 // for the Marker parameter in a subsequent pagination request. 76 Marker *string 77 78 // Metadata pertaining to the operation's result. 79 ResultMetadata middleware.Metadata 80} 81 82func addOperationListVirtualMFADevicesMiddlewares(stack *middleware.Stack, options Options) (err error) { 83 err = stack.Serialize.Add(&awsAwsquery_serializeOpListVirtualMFADevices{}, middleware.After) 84 if err != nil { 85 return err 86 } 87 err = stack.Deserialize.Add(&awsAwsquery_deserializeOpListVirtualMFADevices{}, middleware.After) 88 if err != nil { 89 return err 90 } 91 if err = addSetLoggerMiddleware(stack, options); err != nil { 92 return err 93 } 94 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 95 return err 96 } 97 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 98 return err 99 } 100 if err = addResolveEndpointMiddleware(stack, options); err != nil { 101 return err 102 } 103 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 104 return err 105 } 106 if err = addRetryMiddlewares(stack, options); err != nil { 107 return err 108 } 109 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 110 return err 111 } 112 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 113 return err 114 } 115 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 116 return err 117 } 118 if err = addClientUserAgent(stack); err != nil { 119 return err 120 } 121 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 122 return err 123 } 124 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 125 return err 126 } 127 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListVirtualMFADevices(options.Region), middleware.Before); 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 return nil 140} 141 142// ListVirtualMFADevicesAPIClient is a client that implements the 143// ListVirtualMFADevices operation. 144type ListVirtualMFADevicesAPIClient interface { 145 ListVirtualMFADevices(context.Context, *ListVirtualMFADevicesInput, ...func(*Options)) (*ListVirtualMFADevicesOutput, error) 146} 147 148var _ ListVirtualMFADevicesAPIClient = (*Client)(nil) 149 150// ListVirtualMFADevicesPaginatorOptions is the paginator options for 151// ListVirtualMFADevices 152type ListVirtualMFADevicesPaginatorOptions struct { 153 // Use this only when paginating results to indicate the maximum number of items 154 // you want in the response. If additional items exist beyond the maximum you 155 // specify, the IsTruncated response element is true. If you do not include this 156 // parameter, the number of items defaults to 100. Note that IAM might return fewer 157 // results, even when there are more results available. In that case, the 158 // IsTruncated response element returns true, and Marker contains a value to 159 // include in the subsequent call that tells the service where to continue from. 160 Limit int32 161 162 // Set to true if pagination should stop if the service returns a pagination token 163 // that matches the most recent token provided to the service. 164 StopOnDuplicateToken bool 165} 166 167// ListVirtualMFADevicesPaginator is a paginator for ListVirtualMFADevices 168type ListVirtualMFADevicesPaginator struct { 169 options ListVirtualMFADevicesPaginatorOptions 170 client ListVirtualMFADevicesAPIClient 171 params *ListVirtualMFADevicesInput 172 nextToken *string 173 firstPage bool 174} 175 176// NewListVirtualMFADevicesPaginator returns a new ListVirtualMFADevicesPaginator 177func NewListVirtualMFADevicesPaginator(client ListVirtualMFADevicesAPIClient, params *ListVirtualMFADevicesInput, optFns ...func(*ListVirtualMFADevicesPaginatorOptions)) *ListVirtualMFADevicesPaginator { 178 options := ListVirtualMFADevicesPaginatorOptions{} 179 if params.MaxItems != nil { 180 options.Limit = *params.MaxItems 181 } 182 183 for _, fn := range optFns { 184 fn(&options) 185 } 186 187 if params == nil { 188 params = &ListVirtualMFADevicesInput{} 189 } 190 191 return &ListVirtualMFADevicesPaginator{ 192 options: options, 193 client: client, 194 params: params, 195 firstPage: true, 196 } 197} 198 199// HasMorePages returns a boolean indicating whether more pages are available 200func (p *ListVirtualMFADevicesPaginator) HasMorePages() bool { 201 return p.firstPage || p.nextToken != nil 202} 203 204// NextPage retrieves the next ListVirtualMFADevices page. 205func (p *ListVirtualMFADevicesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListVirtualMFADevicesOutput, error) { 206 if !p.HasMorePages() { 207 return nil, fmt.Errorf("no more pages available") 208 } 209 210 params := *p.params 211 params.Marker = p.nextToken 212 213 var limit *int32 214 if p.options.Limit > 0 { 215 limit = &p.options.Limit 216 } 217 params.MaxItems = limit 218 219 result, err := p.client.ListVirtualMFADevices(ctx, ¶ms, optFns...) 220 if err != nil { 221 return nil, err 222 } 223 p.firstPage = false 224 225 prevToken := p.nextToken 226 p.nextToken = result.Marker 227 228 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 229 p.nextToken = nil 230 } 231 232 return result, nil 233} 234 235func newServiceMetadataMiddleware_opListVirtualMFADevices(region string) *awsmiddleware.RegisterServiceMetadata { 236 return &awsmiddleware.RegisterServiceMetadata{ 237 Region: region, 238 ServiceID: ServiceID, 239 SigningName: "iam", 240 OperationName: "ListVirtualMFADevices", 241 } 242} 243