1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iot
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/iot/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Creates a 2048-bit RSA key pair and issues an X.509 certificate using the issued
15// public key. You can also call CreateKeysAndCertificate over MQTT from a device,
16// for more information, see Provisioning MQTT API
17// (https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html#provision-mqtt-api).
18// Note This is the only time IoT issues the private key for this certificate, so
19// it is important to keep it in a secure location. Requires permission to access
20// the CreateKeysAndCertificate
21// (https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions)
22// action.
23func (c *Client) CreateKeysAndCertificate(ctx context.Context, params *CreateKeysAndCertificateInput, optFns ...func(*Options)) (*CreateKeysAndCertificateOutput, error) {
24	if params == nil {
25		params = &CreateKeysAndCertificateInput{}
26	}
27
28	result, metadata, err := c.invokeOperation(ctx, "CreateKeysAndCertificate", params, optFns, c.addOperationCreateKeysAndCertificateMiddlewares)
29	if err != nil {
30		return nil, err
31	}
32
33	out := result.(*CreateKeysAndCertificateOutput)
34	out.ResultMetadata = metadata
35	return out, nil
36}
37
38// The input for the CreateKeysAndCertificate operation. Requires permission to
39// access the CreateKeysAndCertificateRequest
40// (https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions)
41// action.
42type CreateKeysAndCertificateInput struct {
43
44	// Specifies whether the certificate is active.
45	SetAsActive bool
46
47	noSmithyDocumentSerde
48}
49
50// The output of the CreateKeysAndCertificate operation.
51type CreateKeysAndCertificateOutput struct {
52
53	// The ARN of the certificate.
54	CertificateArn *string
55
56	// The ID of the certificate. IoT issues a default subject name for the certificate
57	// (for example, IoT Certificate).
58	CertificateId *string
59
60	// The certificate data, in PEM format.
61	CertificatePem *string
62
63	// The generated key pair.
64	KeyPair *types.KeyPair
65
66	// Metadata pertaining to the operation's result.
67	ResultMetadata middleware.Metadata
68
69	noSmithyDocumentSerde
70}
71
72func (c *Client) addOperationCreateKeysAndCertificateMiddlewares(stack *middleware.Stack, options Options) (err error) {
73	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateKeysAndCertificate{}, middleware.After)
74	if err != nil {
75		return err
76	}
77	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateKeysAndCertificate{}, middleware.After)
78	if err != nil {
79		return err
80	}
81	if err = addSetLoggerMiddleware(stack, options); err != nil {
82		return err
83	}
84	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
85		return err
86	}
87	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
88		return err
89	}
90	if err = addResolveEndpointMiddleware(stack, options); err != nil {
91		return err
92	}
93	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
94		return err
95	}
96	if err = addRetryMiddlewares(stack, options); err != nil {
97		return err
98	}
99	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
100		return err
101	}
102	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
103		return err
104	}
105	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
106		return err
107	}
108	if err = addClientUserAgent(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
112		return err
113	}
114	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
115		return err
116	}
117	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateKeysAndCertificate(options.Region), middleware.Before); err != nil {
118		return err
119	}
120	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addResponseErrorMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addRequestResponseLogging(stack, options); err != nil {
127		return err
128	}
129	return nil
130}
131
132func newServiceMetadataMiddleware_opCreateKeysAndCertificate(region string) *awsmiddleware.RegisterServiceMetadata {
133	return &awsmiddleware.RegisterServiceMetadata{
134		Region:        region,
135		ServiceID:     ServiceID,
136		SigningName:   "execute-api",
137		OperationName: "CreateKeysAndCertificate",
138	}
139}
140