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 an IoT policy. The created policy is the default version for the policy.
15// This operation creates a policy version with a version identifier of 1 and sets
16// 1 as the policy's default version. Requires permission to access the
17// CreatePolicy
18// (https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions)
19// action.
20func (c *Client) CreatePolicy(ctx context.Context, params *CreatePolicyInput, optFns ...func(*Options)) (*CreatePolicyOutput, error) {
21	if params == nil {
22		params = &CreatePolicyInput{}
23	}
24
25	result, metadata, err := c.invokeOperation(ctx, "CreatePolicy", params, optFns, c.addOperationCreatePolicyMiddlewares)
26	if err != nil {
27		return nil, err
28	}
29
30	out := result.(*CreatePolicyOutput)
31	out.ResultMetadata = metadata
32	return out, nil
33}
34
35// The input for the CreatePolicy operation.
36type CreatePolicyInput struct {
37
38	// The JSON document that describes the policy. policyDocument must have a minimum
39	// length of 1, with a maximum length of 2048, excluding whitespace.
40	//
41	// This member is required.
42	PolicyDocument *string
43
44	// The policy name.
45	//
46	// This member is required.
47	PolicyName *string
48
49	// Metadata which can be used to manage the policy. For URI Request parameters use
50	// format: ...key1=value1&key2=value2... For the CLI command-line parameter use
51	// format: &&tags "key1=value1&key2=value2..." For the cli-input-json file use
52	// format: "tags": "key1=value1&key2=value2..."
53	Tags []types.Tag
54
55	noSmithyDocumentSerde
56}
57
58// The output from the CreatePolicy operation.
59type CreatePolicyOutput struct {
60
61	// The policy ARN.
62	PolicyArn *string
63
64	// The JSON document that describes the policy.
65	PolicyDocument *string
66
67	// The policy name.
68	PolicyName *string
69
70	// The policy version ID.
71	PolicyVersionId *string
72
73	// Metadata pertaining to the operation's result.
74	ResultMetadata middleware.Metadata
75
76	noSmithyDocumentSerde
77}
78
79func (c *Client) addOperationCreatePolicyMiddlewares(stack *middleware.Stack, options Options) (err error) {
80	err = stack.Serialize.Add(&awsRestjson1_serializeOpCreatePolicy{}, middleware.After)
81	if err != nil {
82		return err
83	}
84	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreatePolicy{}, middleware.After)
85	if err != nil {
86		return err
87	}
88	if err = addSetLoggerMiddleware(stack, options); err != nil {
89		return err
90	}
91	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
92		return err
93	}
94	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
95		return err
96	}
97	if err = addResolveEndpointMiddleware(stack, options); err != nil {
98		return err
99	}
100	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
101		return err
102	}
103	if err = addRetryMiddlewares(stack, options); err != nil {
104		return err
105	}
106	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
107		return err
108	}
109	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
110		return err
111	}
112	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
113		return err
114	}
115	if err = addClientUserAgent(stack); err != nil {
116		return err
117	}
118	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
119		return err
120	}
121	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addOpCreatePolicyValidationMiddleware(stack); err != nil {
125		return err
126	}
127	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreatePolicy(options.Region), middleware.Before); err != nil {
128		return err
129	}
130	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
131		return err
132	}
133	if err = addResponseErrorMiddleware(stack); err != nil {
134		return err
135	}
136	if err = addRequestResponseLogging(stack, options); err != nil {
137		return err
138	}
139	return nil
140}
141
142func newServiceMetadataMiddleware_opCreatePolicy(region string) *awsmiddleware.RegisterServiceMetadata {
143	return &awsmiddleware.RegisterServiceMetadata{
144		Region:        region,
145		ServiceID:     ServiceID,
146		SigningName:   "execute-api",
147		OperationName: "CreatePolicy",
148	}
149}
150