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 constraint. A delegated admin is authorized to invoke this command. 16func (c *Client) CreateConstraint(ctx context.Context, params *CreateConstraintInput, optFns ...func(*Options)) (*CreateConstraintOutput, error) { 17 if params == nil { 18 params = &CreateConstraintInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "CreateConstraint", params, optFns, c.addOperationCreateConstraintMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*CreateConstraintOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type CreateConstraintInput struct { 32 33 // A unique identifier that you provide to ensure idempotency. If multiple requests 34 // differ only by the idempotency token, the same response is returned for each 35 // repeated request. 36 // 37 // This member is required. 38 IdempotencyToken *string 39 40 // The constraint parameters, in JSON format. The syntax depends on the constraint 41 // type as follows: LAUNCH You are required to specify either the RoleArn or the 42 // LocalRoleName but can't use both. Specify the RoleArn property as follows: 43 // {"RoleArn" : "arn:aws:iam::123456789012:role/LaunchRole"} Specify the 44 // LocalRoleName property as follows: {"LocalRoleName": "SCBasicLaunchRole"} If you 45 // specify the LocalRoleName property, when an account uses the launch constraint, 46 // the IAM role with that name in the account will be used. This allows launch-role 47 // constraints to be account-agnostic so the administrator can create fewer 48 // resources per shared account. The given role name must exist in the account used 49 // to create the launch constraint and the account of the user who launches a 50 // product with this launch constraint. You cannot have both a LAUNCH and a 51 // STACKSET constraint. You also cannot have more than one LAUNCH constraint on a 52 // product and portfolio. NOTIFICATION Specify the NotificationArns property as 53 // follows: {"NotificationArns" : ["arn:aws:sns:us-east-1:123456789012:Topic"]} 54 // RESOURCE_UPDATE Specify the TagUpdatesOnProvisionedProduct property as follows: 55 // {"Version":"2.0","Properties":{"TagUpdateOnProvisionedProduct":"String"}} The 56 // TagUpdatesOnProvisionedProduct property accepts a string value of ALLOWED or 57 // NOT_ALLOWED. STACKSET Specify the Parameters property as follows: {"Version": 58 // "String", "Properties": {"AccountList": [ "String" ], "RegionList": [ "String" 59 // ], "AdminRole": "String", "ExecutionRole": "String"}} You cannot have both a 60 // LAUNCH and a STACKSET constraint. You also cannot have more than one STACKSET 61 // constraint on a product and portfolio. Products with a STACKSET constraint will 62 // launch an AWS CloudFormation stack set. TEMPLATE Specify the Rules property. For 63 // more information, see Template Constraint Rules 64 // (http://docs.aws.amazon.com/servicecatalog/latest/adminguide/reference-template_constraint_rules.html). 65 // 66 // This member is required. 67 Parameters *string 68 69 // The portfolio identifier. 70 // 71 // This member is required. 72 PortfolioId *string 73 74 // The product identifier. 75 // 76 // This member is required. 77 ProductId *string 78 79 // The type of constraint. 80 // 81 // * LAUNCH 82 // 83 // * NOTIFICATION 84 // 85 // * RESOURCE_UPDATE 86 // 87 // * 88 // STACKSET 89 // 90 // * TEMPLATE 91 // 92 // This member is required. 93 Type *string 94 95 // The language code. 96 // 97 // * en - English (default) 98 // 99 // * jp - Japanese 100 // 101 // * zh - Chinese 102 AcceptLanguage *string 103 104 // The description of the constraint. 105 Description *string 106 107 noSmithyDocumentSerde 108} 109 110type CreateConstraintOutput struct { 111 112 // Information about the constraint. 113 ConstraintDetail *types.ConstraintDetail 114 115 // The constraint parameters. 116 ConstraintParameters *string 117 118 // The status of the current request. 119 Status types.Status 120 121 // Metadata pertaining to the operation's result. 122 ResultMetadata middleware.Metadata 123 124 noSmithyDocumentSerde 125} 126 127func (c *Client) addOperationCreateConstraintMiddlewares(stack *middleware.Stack, options Options) (err error) { 128 err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateConstraint{}, middleware.After) 129 if err != nil { 130 return err 131 } 132 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateConstraint{}, middleware.After) 133 if err != nil { 134 return err 135 } 136 if err = addSetLoggerMiddleware(stack, options); err != nil { 137 return err 138 } 139 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 140 return err 141 } 142 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 143 return err 144 } 145 if err = addResolveEndpointMiddleware(stack, options); err != nil { 146 return err 147 } 148 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 149 return err 150 } 151 if err = addRetryMiddlewares(stack, options); err != nil { 152 return err 153 } 154 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 155 return err 156 } 157 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 158 return err 159 } 160 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 161 return err 162 } 163 if err = addClientUserAgent(stack); err != nil { 164 return err 165 } 166 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 167 return err 168 } 169 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 170 return err 171 } 172 if err = addIdempotencyToken_opCreateConstraintMiddleware(stack, options); err != nil { 173 return err 174 } 175 if err = addOpCreateConstraintValidationMiddleware(stack); err != nil { 176 return err 177 } 178 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateConstraint(options.Region), middleware.Before); err != nil { 179 return err 180 } 181 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 182 return err 183 } 184 if err = addResponseErrorMiddleware(stack); err != nil { 185 return err 186 } 187 if err = addRequestResponseLogging(stack, options); err != nil { 188 return err 189 } 190 return nil 191} 192 193type idempotencyToken_initializeOpCreateConstraint struct { 194 tokenProvider IdempotencyTokenProvider 195} 196 197func (*idempotencyToken_initializeOpCreateConstraint) ID() string { 198 return "OperationIdempotencyTokenAutoFill" 199} 200 201func (m *idempotencyToken_initializeOpCreateConstraint) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) ( 202 out middleware.InitializeOutput, metadata middleware.Metadata, err error, 203) { 204 if m.tokenProvider == nil { 205 return next.HandleInitialize(ctx, in) 206 } 207 208 input, ok := in.Parameters.(*CreateConstraintInput) 209 if !ok { 210 return out, metadata, fmt.Errorf("expected middleware input to be of type *CreateConstraintInput ") 211 } 212 213 if input.IdempotencyToken == nil { 214 t, err := m.tokenProvider.GetIdempotencyToken() 215 if err != nil { 216 return out, metadata, err 217 } 218 input.IdempotencyToken = &t 219 } 220 return next.HandleInitialize(ctx, in) 221} 222func addIdempotencyToken_opCreateConstraintMiddleware(stack *middleware.Stack, cfg Options) error { 223 return stack.Initialize.Add(&idempotencyToken_initializeOpCreateConstraint{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before) 224} 225 226func newServiceMetadataMiddleware_opCreateConstraint(region string) *awsmiddleware.RegisterServiceMetadata { 227 return &awsmiddleware.RegisterServiceMetadata{ 228 Region: region, 229 ServiceID: ServiceID, 230 SigningName: "servicecatalog", 231 OperationName: "CreateConstraint", 232 } 233} 234