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