1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package codestarconnections 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/codestarconnections/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists the connections associated with your account. 16func (c *Client) ListConnections(ctx context.Context, params *ListConnectionsInput, optFns ...func(*Options)) (*ListConnectionsOutput, error) { 17 if params == nil { 18 params = &ListConnectionsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListConnections", params, optFns, addOperationListConnectionsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListConnectionsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListConnectionsInput struct { 32 33 // Filters the list of connections to those associated with a specified host. 34 HostArnFilter *string 35 36 // The maximum number of results to return in a single call. To retrieve the 37 // remaining results, make another call with the returned nextToken value. 38 MaxResults int32 39 40 // The token that was returned from the previous ListConnections call, which can be 41 // used to return the next set of connections in the list. 42 NextToken *string 43 44 // Filters the list of connections to those associated with a specified provider, 45 // such as Bitbucket. 46 ProviderTypeFilter types.ProviderType 47} 48 49type ListConnectionsOutput struct { 50 51 // A list of connections and the details for each connection, such as status, 52 // owner, and provider type. 53 Connections []types.Connection 54 55 // A token that can be used in the next ListConnections call. To view all items in 56 // the list, continue to call this operation with each subsequent token until no 57 // more nextToken values are returned. 58 NextToken *string 59 60 // Metadata pertaining to the operation's result. 61 ResultMetadata middleware.Metadata 62} 63 64func addOperationListConnectionsMiddlewares(stack *middleware.Stack, options Options) (err error) { 65 err = stack.Serialize.Add(&awsAwsjson10_serializeOpListConnections{}, middleware.After) 66 if err != nil { 67 return err 68 } 69 err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpListConnections{}, middleware.After) 70 if err != nil { 71 return err 72 } 73 if err = addSetLoggerMiddleware(stack, options); err != nil { 74 return err 75 } 76 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 77 return err 78 } 79 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 80 return err 81 } 82 if err = addResolveEndpointMiddleware(stack, options); err != nil { 83 return err 84 } 85 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 86 return err 87 } 88 if err = addRetryMiddlewares(stack, options); err != nil { 89 return err 90 } 91 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 92 return err 93 } 94 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 95 return err 96 } 97 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 98 return err 99 } 100 if err = addClientUserAgent(stack); err != nil { 101 return err 102 } 103 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 104 return err 105 } 106 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 107 return err 108 } 109 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListConnections(options.Region), middleware.Before); err != nil { 110 return err 111 } 112 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 113 return err 114 } 115 if err = addResponseErrorMiddleware(stack); err != nil { 116 return err 117 } 118 if err = addRequestResponseLogging(stack, options); err != nil { 119 return err 120 } 121 return nil 122} 123 124// ListConnectionsAPIClient is a client that implements the ListConnections 125// operation. 126type ListConnectionsAPIClient interface { 127 ListConnections(context.Context, *ListConnectionsInput, ...func(*Options)) (*ListConnectionsOutput, error) 128} 129 130var _ ListConnectionsAPIClient = (*Client)(nil) 131 132// ListConnectionsPaginatorOptions is the paginator options for ListConnections 133type ListConnectionsPaginatorOptions struct { 134 // The maximum number of results to return in a single call. To retrieve the 135 // remaining results, make another call with the returned nextToken value. 136 Limit int32 137 138 // Set to true if pagination should stop if the service returns a pagination token 139 // that matches the most recent token provided to the service. 140 StopOnDuplicateToken bool 141} 142 143// ListConnectionsPaginator is a paginator for ListConnections 144type ListConnectionsPaginator struct { 145 options ListConnectionsPaginatorOptions 146 client ListConnectionsAPIClient 147 params *ListConnectionsInput 148 nextToken *string 149 firstPage bool 150} 151 152// NewListConnectionsPaginator returns a new ListConnectionsPaginator 153func NewListConnectionsPaginator(client ListConnectionsAPIClient, params *ListConnectionsInput, optFns ...func(*ListConnectionsPaginatorOptions)) *ListConnectionsPaginator { 154 options := ListConnectionsPaginatorOptions{} 155 if params.MaxResults != 0 { 156 options.Limit = params.MaxResults 157 } 158 159 for _, fn := range optFns { 160 fn(&options) 161 } 162 163 if params == nil { 164 params = &ListConnectionsInput{} 165 } 166 167 return &ListConnectionsPaginator{ 168 options: options, 169 client: client, 170 params: params, 171 firstPage: true, 172 } 173} 174 175// HasMorePages returns a boolean indicating whether more pages are available 176func (p *ListConnectionsPaginator) HasMorePages() bool { 177 return p.firstPage || p.nextToken != nil 178} 179 180// NextPage retrieves the next ListConnections page. 181func (p *ListConnectionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListConnectionsOutput, error) { 182 if !p.HasMorePages() { 183 return nil, fmt.Errorf("no more pages available") 184 } 185 186 params := *p.params 187 params.NextToken = p.nextToken 188 189 params.MaxResults = p.options.Limit 190 191 result, err := p.client.ListConnections(ctx, ¶ms, optFns...) 192 if err != nil { 193 return nil, err 194 } 195 p.firstPage = false 196 197 prevToken := p.nextToken 198 p.nextToken = result.NextToken 199 200 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 201 p.nextToken = nil 202 } 203 204 return result, nil 205} 206 207func newServiceMetadataMiddleware_opListConnections(region string) *awsmiddleware.RegisterServiceMetadata { 208 return &awsmiddleware.RegisterServiceMetadata{ 209 Region: region, 210 ServiceID: ServiceID, 211 SigningName: "codestar-connections", 212 OperationName: "ListConnections", 213 } 214} 215