1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package ec2 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/ec2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Describes one or more transit gateways. By default, all transit gateways are 16// described. Alternatively, you can filter the results. 17func (c *Client) DescribeTransitGateways(ctx context.Context, params *DescribeTransitGatewaysInput, optFns ...func(*Options)) (*DescribeTransitGatewaysOutput, error) { 18 if params == nil { 19 params = &DescribeTransitGatewaysInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "DescribeTransitGateways", params, optFns, addOperationDescribeTransitGatewaysMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*DescribeTransitGatewaysOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type DescribeTransitGatewaysInput struct { 33 34 // Checks whether you have the required permissions for the action, without 35 // actually making the request, and provides an error response. If you have the 36 // required permissions, the error response is DryRunOperation. Otherwise, it is 37 // UnauthorizedOperation. 38 DryRun bool 39 40 // One or more filters. The possible values are: 41 // 42 // * 43 // options.propagation-default-route-table-id - The ID of the default propagation 44 // route table. 45 // 46 // * options.amazon-side-asn - The private ASN for the Amazon side of 47 // a BGP session. 48 // 49 // * options.association-default-route-table-id - The ID of the 50 // default association route table. 51 // 52 // * options.auto-accept-shared-attachments - 53 // Indicates whether there is automatic acceptance of attachment requests (enable | 54 // disable). 55 // 56 // * options.default-route-table-association - Indicates whether 57 // resource attachments are automatically associated with the default association 58 // route table (enable | disable). 59 // 60 // * options.default-route-table-propagation - 61 // Indicates whether resource attachments automatically propagate routes to the 62 // default propagation route table (enable | disable). 63 // 64 // * options.dns-support - 65 // Indicates whether DNS support is enabled (enable | disable). 66 // 67 // * 68 // options.vpn-ecmp-support - Indicates whether Equal Cost Multipath Protocol 69 // support is enabled (enable | disable). 70 // 71 // * owner-id - The ID of the AWS account 72 // that owns the transit gateway. 73 // 74 // * state - The state of the transit gateway 75 // (available | deleted | deleting | modifying | pending). 76 // 77 // * transit-gateway-id - 78 // The ID of the transit gateway. 79 Filters []types.Filter 80 81 // The maximum number of results to return with a single call. To retrieve the 82 // remaining results, make another call with the returned nextToken value. 83 MaxResults int32 84 85 // The token for the next page of results. 86 NextToken *string 87 88 // The IDs of the transit gateways. 89 TransitGatewayIds []string 90} 91 92type DescribeTransitGatewaysOutput struct { 93 94 // The token to use to retrieve the next page of results. This value is null when 95 // there are no more results to return. 96 NextToken *string 97 98 // Information about the transit gateways. 99 TransitGateways []types.TransitGateway 100 101 // Metadata pertaining to the operation's result. 102 ResultMetadata middleware.Metadata 103} 104 105func addOperationDescribeTransitGatewaysMiddlewares(stack *middleware.Stack, options Options) (err error) { 106 err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeTransitGateways{}, middleware.After) 107 if err != nil { 108 return err 109 } 110 err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeTransitGateways{}, middleware.After) 111 if err != nil { 112 return err 113 } 114 if err = addSetLoggerMiddleware(stack, options); err != nil { 115 return err 116 } 117 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 118 return err 119 } 120 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addResolveEndpointMiddleware(stack, options); err != nil { 124 return err 125 } 126 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 127 return err 128 } 129 if err = addRetryMiddlewares(stack, options); err != nil { 130 return err 131 } 132 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 133 return err 134 } 135 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 136 return err 137 } 138 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 139 return err 140 } 141 if err = addClientUserAgent(stack); err != nil { 142 return err 143 } 144 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 145 return err 146 } 147 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 148 return err 149 } 150 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeTransitGateways(options.Region), middleware.Before); err != nil { 151 return err 152 } 153 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 154 return err 155 } 156 if err = addResponseErrorMiddleware(stack); err != nil { 157 return err 158 } 159 if err = addRequestResponseLogging(stack, options); err != nil { 160 return err 161 } 162 return nil 163} 164 165// DescribeTransitGatewaysAPIClient is a client that implements the 166// DescribeTransitGateways operation. 167type DescribeTransitGatewaysAPIClient interface { 168 DescribeTransitGateways(context.Context, *DescribeTransitGatewaysInput, ...func(*Options)) (*DescribeTransitGatewaysOutput, error) 169} 170 171var _ DescribeTransitGatewaysAPIClient = (*Client)(nil) 172 173// DescribeTransitGatewaysPaginatorOptions is the paginator options for 174// DescribeTransitGateways 175type DescribeTransitGatewaysPaginatorOptions struct { 176 // The maximum number of results to return with a single call. To retrieve the 177 // remaining results, make another call with the returned nextToken value. 178 Limit int32 179 180 // Set to true if pagination should stop if the service returns a pagination token 181 // that matches the most recent token provided to the service. 182 StopOnDuplicateToken bool 183} 184 185// DescribeTransitGatewaysPaginator is a paginator for DescribeTransitGateways 186type DescribeTransitGatewaysPaginator struct { 187 options DescribeTransitGatewaysPaginatorOptions 188 client DescribeTransitGatewaysAPIClient 189 params *DescribeTransitGatewaysInput 190 nextToken *string 191 firstPage bool 192} 193 194// NewDescribeTransitGatewaysPaginator returns a new 195// DescribeTransitGatewaysPaginator 196func NewDescribeTransitGatewaysPaginator(client DescribeTransitGatewaysAPIClient, params *DescribeTransitGatewaysInput, optFns ...func(*DescribeTransitGatewaysPaginatorOptions)) *DescribeTransitGatewaysPaginator { 197 options := DescribeTransitGatewaysPaginatorOptions{} 198 if params.MaxResults != 0 { 199 options.Limit = params.MaxResults 200 } 201 202 for _, fn := range optFns { 203 fn(&options) 204 } 205 206 if params == nil { 207 params = &DescribeTransitGatewaysInput{} 208 } 209 210 return &DescribeTransitGatewaysPaginator{ 211 options: options, 212 client: client, 213 params: params, 214 firstPage: true, 215 } 216} 217 218// HasMorePages returns a boolean indicating whether more pages are available 219func (p *DescribeTransitGatewaysPaginator) HasMorePages() bool { 220 return p.firstPage || p.nextToken != nil 221} 222 223// NextPage retrieves the next DescribeTransitGateways page. 224func (p *DescribeTransitGatewaysPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeTransitGatewaysOutput, error) { 225 if !p.HasMorePages() { 226 return nil, fmt.Errorf("no more pages available") 227 } 228 229 params := *p.params 230 params.NextToken = p.nextToken 231 232 params.MaxResults = p.options.Limit 233 234 result, err := p.client.DescribeTransitGateways(ctx, ¶ms, optFns...) 235 if err != nil { 236 return nil, err 237 } 238 p.firstPage = false 239 240 prevToken := p.nextToken 241 p.nextToken = result.NextToken 242 243 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 244 p.nextToken = nil 245 } 246 247 return result, nil 248} 249 250func newServiceMetadataMiddleware_opDescribeTransitGateways(region string) *awsmiddleware.RegisterServiceMetadata { 251 return &awsmiddleware.RegisterServiceMetadata{ 252 Region: region, 253 ServiceID: ServiceID, 254 SigningName: "ec2", 255 OperationName: "DescribeTransitGateways", 256 } 257} 258