api_op_CreateKeyPair.go raw
1 // Code generated by smithy-go-codegen DO NOT EDIT.
2
3 package lightsail
4
5 import (
6 "context"
7 "fmt"
8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9 "github.com/aws/aws-sdk-go-v2/service/lightsail/types"
10 "github.com/aws/smithy-go/middleware"
11 smithyhttp "github.com/aws/smithy-go/transport/http"
12 )
13
14 // Creates a custom SSH key pair that you can use with an Amazon Lightsail
15 // instance.
16 //
17 // Use the [DownloadDefaultKeyPair] action to create a Lightsail default key pair in an Amazon Web
18 // Services Region where a default key pair does not currently exist.
19 //
20 // The create key pair operation supports tag-based access control via request
21 // tags. For more information, see the [Amazon Lightsail Developer Guide].
22 //
23 // [DownloadDefaultKeyPair]: https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_DownloadDefaultKeyPair.html
24 // [Amazon Lightsail Developer Guide]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-controlling-access-using-tags
25 func (c *Client) CreateKeyPair(ctx context.Context, params *CreateKeyPairInput, optFns ...func(*Options)) (*CreateKeyPairOutput, error) {
26 if params == nil {
27 params = &CreateKeyPairInput{}
28 }
29
30 result, metadata, err := c.invokeOperation(ctx, "CreateKeyPair", params, optFns, c.addOperationCreateKeyPairMiddlewares)
31 if err != nil {
32 return nil, err
33 }
34
35 out := result.(*CreateKeyPairOutput)
36 out.ResultMetadata = metadata
37 return out, nil
38 }
39
40 type CreateKeyPairInput struct {
41
42 // The name for your new key pair.
43 //
44 // This member is required.
45 KeyPairName *string
46
47 // The tag keys and optional values to add to the resource during create.
48 //
49 // Use the TagResource action to tag a resource after it's created.
50 Tags []types.Tag
51
52 noSmithyDocumentSerde
53 }
54
55 type CreateKeyPairOutput struct {
56
57 // An array of key-value pairs containing information about the new key pair you
58 // just created.
59 KeyPair *types.KeyPair
60
61 // An array of objects that describe the result of the action, such as the status
62 // of the request, the timestamp of the request, and the resources affected by the
63 // request.
64 Operation *types.Operation
65
66 // A base64-encoded RSA private key.
67 PrivateKeyBase64 *string
68
69 // A base64-encoded public key of the ssh-rsa type.
70 PublicKeyBase64 *string
71
72 // Metadata pertaining to the operation's result.
73 ResultMetadata middleware.Metadata
74
75 noSmithyDocumentSerde
76 }
77
78 func (c *Client) addOperationCreateKeyPairMiddlewares(stack *middleware.Stack, options Options) (err error) {
79 if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
80 return err
81 }
82 err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateKeyPair{}, middleware.After)
83 if err != nil {
84 return err
85 }
86 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateKeyPair{}, middleware.After)
87 if err != nil {
88 return err
89 }
90 if err := addProtocolFinalizerMiddlewares(stack, options, "CreateKeyPair"); err != nil {
91 return fmt.Errorf("add protocol finalizers: %v", err)
92 }
93
94 if err = addlegacyEndpointContextSetter(stack, options); err != nil {
95 return err
96 }
97 if err = addSetLoggerMiddleware(stack, options); err != nil {
98 return err
99 }
100 if err = addClientRequestID(stack); err != nil {
101 return err
102 }
103 if err = addComputeContentLength(stack); err != nil {
104 return err
105 }
106 if err = addResolveEndpointMiddleware(stack, options); err != nil {
107 return err
108 }
109 if err = addComputePayloadSHA256(stack); err != nil {
110 return err
111 }
112 if err = addRetry(stack, options); err != nil {
113 return err
114 }
115 if err = addRawResponseToMetadata(stack); err != nil {
116 return err
117 }
118 if err = addRecordResponseTiming(stack); err != nil {
119 return err
120 }
121 if err = addSpanRetryLoop(stack, options); err != nil {
122 return err
123 }
124 if err = addClientUserAgent(stack, options); 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 = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
134 return err
135 }
136 if err = addTimeOffsetBuild(stack, c); err != nil {
137 return err
138 }
139 if err = addUserAgentRetryMode(stack, options); err != nil {
140 return err
141 }
142 if err = addCredentialSource(stack, options); err != nil {
143 return err
144 }
145 if err = addOpCreateKeyPairValidationMiddleware(stack); err != nil {
146 return err
147 }
148 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateKeyPair(options.Region), middleware.Before); err != nil {
149 return err
150 }
151 if err = addRecursionDetection(stack); err != nil {
152 return err
153 }
154 if err = addRequestIDRetrieverMiddleware(stack); err != nil {
155 return err
156 }
157 if err = addResponseErrorMiddleware(stack); err != nil {
158 return err
159 }
160 if err = addRequestResponseLogging(stack, options); err != nil {
161 return err
162 }
163 if err = addDisableHTTPSMiddleware(stack, options); err != nil {
164 return err
165 }
166 if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
167 return err
168 }
169 if err = addInterceptAttempt(stack, options); err != nil {
170 return err
171 }
172 if err = addInterceptors(stack, options); err != nil {
173 return err
174 }
175 return nil
176 }
177
178 func newServiceMetadataMiddleware_opCreateKeyPair(region string) *awsmiddleware.RegisterServiceMetadata {
179 return &awsmiddleware.RegisterServiceMetadata{
180 Region: region,
181 ServiceID: ServiceID,
182 OperationName: "CreateKeyPair",
183 }
184 }
185