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// Returns information about the SSH public keys associated with the specified IAM
16// user. If none exists, the operation returns an empty list. The SSH public keys
17// returned by this operation are used only for authenticating the IAM user to an
18// AWS CodeCommit repository. For more information about using SSH keys to
19// authenticate to an AWS CodeCommit repository, see Set up AWS CodeCommit for SSH
20// connections
21// (https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-credentials-ssh.html)
22// in the AWS CodeCommit User Guide. Although each user is limited to a small
23// number of keys, you can still paginate the results using the MaxItems and Marker
24// parameters.
25func (c *Client) ListSSHPublicKeys(ctx context.Context, params *ListSSHPublicKeysInput, optFns ...func(*Options)) (*ListSSHPublicKeysOutput, error) {
26	if params == nil {
27		params = &ListSSHPublicKeysInput{}
28	}
29
30	result, metadata, err := c.invokeOperation(ctx, "ListSSHPublicKeys", params, optFns, addOperationListSSHPublicKeysMiddlewares)
31	if err != nil {
32		return nil, err
33	}
34
35	out := result.(*ListSSHPublicKeysOutput)
36	out.ResultMetadata = metadata
37	return out, nil
38}
39
40type ListSSHPublicKeysInput struct {
41
42	// Use this parameter only when paginating results and only after you receive a
43	// response indicating that the results are truncated. Set it to the value of the
44	// Marker element in the response that you received to indicate where the next call
45	// should start.
46	Marker *string
47
48	// Use this only when paginating results to indicate the maximum number of items
49	// you want in the response. If additional items exist beyond the maximum you
50	// specify, the IsTruncated response element is true. If you do not include this
51	// parameter, the number of items defaults to 100. Note that IAM might return fewer
52	// results, even when there are more results available. In that case, the
53	// IsTruncated response element returns true, and Marker contains a value to
54	// include in the subsequent call that tells the service where to continue from.
55	MaxItems *int32
56
57	// The name of the IAM user to list SSH public keys for. If none is specified, the
58	// UserName field is determined implicitly based on the AWS access key used to sign
59	// the request. This parameter allows (through its regex pattern
60	// (http://wikipedia.org/wiki/regex)) a string of characters consisting of upper
61	// and lowercase alphanumeric characters with no spaces. You can also include any
62	// of the following characters: _+=,.@-
63	UserName *string
64}
65
66// Contains the response to a successful ListSSHPublicKeys request.
67type ListSSHPublicKeysOutput struct {
68
69	// A flag that indicates whether there are more items to return. If your results
70	// were truncated, you can make a subsequent pagination request using the Marker
71	// request parameter to retrieve more items. Note that IAM might return fewer than
72	// the MaxItems number of results even when there are more results available. We
73	// recommend that you check IsTruncated after every call to ensure that you receive
74	// all your results.
75	IsTruncated bool
76
77	// When IsTruncated is true, this element is present and contains the value to use
78	// for the Marker parameter in a subsequent pagination request.
79	Marker *string
80
81	// A list of the SSH public keys assigned to IAM user.
82	SSHPublicKeys []types.SSHPublicKeyMetadata
83
84	// Metadata pertaining to the operation's result.
85	ResultMetadata middleware.Metadata
86}
87
88func addOperationListSSHPublicKeysMiddlewares(stack *middleware.Stack, options Options) (err error) {
89	err = stack.Serialize.Add(&awsAwsquery_serializeOpListSSHPublicKeys{}, middleware.After)
90	if err != nil {
91		return err
92	}
93	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpListSSHPublicKeys{}, middleware.After)
94	if err != nil {
95		return err
96	}
97	if err = addSetLoggerMiddleware(stack, options); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
101		return err
102	}
103	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
104		return err
105	}
106	if err = addResolveEndpointMiddleware(stack, options); err != nil {
107		return err
108	}
109	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
110		return err
111	}
112	if err = addRetryMiddlewares(stack, options); err != nil {
113		return err
114	}
115	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
116		return err
117	}
118	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
119		return err
120	}
121	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
122		return err
123	}
124	if err = addClientUserAgent(stack); err != nil {
125		return err
126	}
127	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
128		return err
129	}
130	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
131		return err
132	}
133	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListSSHPublicKeys(options.Region), middleware.Before); err != nil {
134		return err
135	}
136	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
137		return err
138	}
139	if err = addResponseErrorMiddleware(stack); err != nil {
140		return err
141	}
142	if err = addRequestResponseLogging(stack, options); err != nil {
143		return err
144	}
145	return nil
146}
147
148// ListSSHPublicKeysAPIClient is a client that implements the ListSSHPublicKeys
149// operation.
150type ListSSHPublicKeysAPIClient interface {
151	ListSSHPublicKeys(context.Context, *ListSSHPublicKeysInput, ...func(*Options)) (*ListSSHPublicKeysOutput, error)
152}
153
154var _ ListSSHPublicKeysAPIClient = (*Client)(nil)
155
156// ListSSHPublicKeysPaginatorOptions is the paginator options for ListSSHPublicKeys
157type ListSSHPublicKeysPaginatorOptions struct {
158	// Use this only when paginating results to indicate the maximum number of items
159	// you want in the response. If additional items exist beyond the maximum you
160	// specify, the IsTruncated response element is true. If you do not include this
161	// parameter, the number of items defaults to 100. Note that IAM might return fewer
162	// results, even when there are more results available. In that case, the
163	// IsTruncated response element returns true, and Marker contains a value to
164	// include in the subsequent call that tells the service where to continue from.
165	Limit int32
166
167	// Set to true if pagination should stop if the service returns a pagination token
168	// that matches the most recent token provided to the service.
169	StopOnDuplicateToken bool
170}
171
172// ListSSHPublicKeysPaginator is a paginator for ListSSHPublicKeys
173type ListSSHPublicKeysPaginator struct {
174	options   ListSSHPublicKeysPaginatorOptions
175	client    ListSSHPublicKeysAPIClient
176	params    *ListSSHPublicKeysInput
177	nextToken *string
178	firstPage bool
179}
180
181// NewListSSHPublicKeysPaginator returns a new ListSSHPublicKeysPaginator
182func NewListSSHPublicKeysPaginator(client ListSSHPublicKeysAPIClient, params *ListSSHPublicKeysInput, optFns ...func(*ListSSHPublicKeysPaginatorOptions)) *ListSSHPublicKeysPaginator {
183	if params == nil {
184		params = &ListSSHPublicKeysInput{}
185	}
186
187	options := ListSSHPublicKeysPaginatorOptions{}
188	if params.MaxItems != nil {
189		options.Limit = *params.MaxItems
190	}
191
192	for _, fn := range optFns {
193		fn(&options)
194	}
195
196	return &ListSSHPublicKeysPaginator{
197		options:   options,
198		client:    client,
199		params:    params,
200		firstPage: true,
201	}
202}
203
204// HasMorePages returns a boolean indicating whether more pages are available
205func (p *ListSSHPublicKeysPaginator) HasMorePages() bool {
206	return p.firstPage || p.nextToken != nil
207}
208
209// NextPage retrieves the next ListSSHPublicKeys page.
210func (p *ListSSHPublicKeysPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListSSHPublicKeysOutput, error) {
211	if !p.HasMorePages() {
212		return nil, fmt.Errorf("no more pages available")
213	}
214
215	params := *p.params
216	params.Marker = p.nextToken
217
218	var limit *int32
219	if p.options.Limit > 0 {
220		limit = &p.options.Limit
221	}
222	params.MaxItems = limit
223
224	result, err := p.client.ListSSHPublicKeys(ctx, &params, optFns...)
225	if err != nil {
226		return nil, err
227	}
228	p.firstPage = false
229
230	prevToken := p.nextToken
231	p.nextToken = result.Marker
232
233	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
234		p.nextToken = nil
235	}
236
237	return result, nil
238}
239
240func newServiceMetadataMiddleware_opListSSHPublicKeys(region string) *awsmiddleware.RegisterServiceMetadata {
241	return &awsmiddleware.RegisterServiceMetadata{
242		Region:        region,
243		ServiceID:     ServiceID,
244		SigningName:   "iam",
245		OperationName: "ListSSHPublicKeys",
246	}
247}
248