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