1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package servicecatalog
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/servicecatalog/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Creates a product. A delegated admin is authorized to invoke this command. The
16// user or role that performs this operation must have the
17// cloudformation:GetTemplate IAM policy permission. This policy permission is
18// required when using the ImportFromPhysicalId template source in the information
19// data section.
20func (c *Client) CreateProduct(ctx context.Context, params *CreateProductInput, optFns ...func(*Options)) (*CreateProductOutput, error) {
21	if params == nil {
22		params = &CreateProductInput{}
23	}
24
25	result, metadata, err := c.invokeOperation(ctx, "CreateProduct", params, optFns, addOperationCreateProductMiddlewares)
26	if err != nil {
27		return nil, err
28	}
29
30	out := result.(*CreateProductOutput)
31	out.ResultMetadata = metadata
32	return out, nil
33}
34
35type CreateProductInput struct {
36
37	// A unique identifier that you provide to ensure idempotency. If multiple requests
38	// differ only by the idempotency token, the same response is returned for each
39	// repeated request.
40	//
41	// This member is required.
42	IdempotencyToken *string
43
44	// The name of the product.
45	//
46	// This member is required.
47	Name *string
48
49	// The owner of the product.
50	//
51	// This member is required.
52	Owner *string
53
54	// The type of product.
55	//
56	// This member is required.
57	ProductType types.ProductType
58
59	// The configuration of the provisioning artifact.
60	//
61	// This member is required.
62	ProvisioningArtifactParameters *types.ProvisioningArtifactProperties
63
64	// The language code.
65	//
66	// * en - English (default)
67	//
68	// * jp - Japanese
69	//
70	// * zh - Chinese
71	AcceptLanguage *string
72
73	// The description of the product.
74	Description *string
75
76	// The distributor of the product.
77	Distributor *string
78
79	// The support information about the product.
80	SupportDescription *string
81
82	// The contact email for product support.
83	SupportEmail *string
84
85	// The contact URL for product support. ^https?:\/\// / is the pattern used to
86	// validate SupportUrl.
87	SupportUrl *string
88
89	// One or more tags.
90	Tags []types.Tag
91}
92
93type CreateProductOutput struct {
94
95	// Information about the product view.
96	ProductViewDetail *types.ProductViewDetail
97
98	// Information about the provisioning artifact.
99	ProvisioningArtifactDetail *types.ProvisioningArtifactDetail
100
101	// Information about the tags associated with the product.
102	Tags []types.Tag
103
104	// Metadata pertaining to the operation's result.
105	ResultMetadata middleware.Metadata
106}
107
108func addOperationCreateProductMiddlewares(stack *middleware.Stack, options Options) (err error) {
109	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateProduct{}, middleware.After)
110	if err != nil {
111		return err
112	}
113	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateProduct{}, middleware.After)
114	if err != nil {
115		return err
116	}
117	if err = addSetLoggerMiddleware(stack, options); err != nil {
118		return err
119	}
120	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
121		return err
122	}
123	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addResolveEndpointMiddleware(stack, options); err != nil {
127		return err
128	}
129	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
130		return err
131	}
132	if err = addRetryMiddlewares(stack, options); err != nil {
133		return err
134	}
135	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
136		return err
137	}
138	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
139		return err
140	}
141	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
142		return err
143	}
144	if err = addClientUserAgent(stack); err != nil {
145		return err
146	}
147	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
148		return err
149	}
150	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
151		return err
152	}
153	if err = addIdempotencyToken_opCreateProductMiddleware(stack, options); err != nil {
154		return err
155	}
156	if err = addOpCreateProductValidationMiddleware(stack); err != nil {
157		return err
158	}
159	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateProduct(options.Region), middleware.Before); err != nil {
160		return err
161	}
162	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
163		return err
164	}
165	if err = addResponseErrorMiddleware(stack); err != nil {
166		return err
167	}
168	if err = addRequestResponseLogging(stack, options); err != nil {
169		return err
170	}
171	return nil
172}
173
174type idempotencyToken_initializeOpCreateProduct struct {
175	tokenProvider IdempotencyTokenProvider
176}
177
178func (*idempotencyToken_initializeOpCreateProduct) ID() string {
179	return "OperationIdempotencyTokenAutoFill"
180}
181
182func (m *idempotencyToken_initializeOpCreateProduct) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
183	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
184) {
185	if m.tokenProvider == nil {
186		return next.HandleInitialize(ctx, in)
187	}
188
189	input, ok := in.Parameters.(*CreateProductInput)
190	if !ok {
191		return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateProductInput ")
192	}
193
194	if input.IdempotencyToken == nil {
195		t, err := m.tokenProvider.GetIdempotencyToken()
196		if err != nil {
197			return out, metadata, err
198		}
199		input.IdempotencyToken = &t
200	}
201	return next.HandleInitialize(ctx, in)
202}
203func addIdempotencyToken_opCreateProductMiddleware(stack *middleware.Stack, cfg Options) error {
204	return stack.Initialize.Add(&idempotencyToken_initializeOpCreateProduct{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
205}
206
207func newServiceMetadataMiddleware_opCreateProduct(region string) *awsmiddleware.RegisterServiceMetadata {
208	return &awsmiddleware.RegisterServiceMetadata{
209		Region:        region,
210		ServiceID:     ServiceID,
211		SigningName:   "servicecatalog",
212		OperationName: "CreateProduct",
213	}
214}
215