/
method.go
443 lines (397 loc) · 18.3 KB
/
method.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
// *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package apigateway
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Provides a HTTP Method for an API Gateway Resource.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/apigateway"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// myDemoAPI, err := apigateway.NewRestApi(ctx, "myDemoAPI", &apigateway.RestApiArgs{
// Description: pulumi.String("This is my API for demonstration purposes"),
// })
// if err != nil {
// return err
// }
// myDemoResource, err := apigateway.NewResource(ctx, "myDemoResource", &apigateway.ResourceArgs{
// RestApi: myDemoAPI.ID(),
// ParentId: myDemoAPI.RootResourceId,
// PathPart: pulumi.String("mydemoresource"),
// })
// if err != nil {
// return err
// }
// _, err = apigateway.NewMethod(ctx, "myDemoMethod", &apigateway.MethodArgs{
// RestApi: myDemoAPI.ID(),
// ResourceId: myDemoResource.ID(),
// HttpMethod: pulumi.String("GET"),
// Authorization: pulumi.String("NONE"),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
// ## Usage with Cognito User Pool Authorizer
//
// ```go
// package main
//
// import (
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/apigateway"
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cognito"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// cfg := config.New(ctx, "")
// cognitoUserPoolName := cfg.RequireObject("cognitoUserPoolName")
// thisUserPools, err := cognito.GetUserPools(ctx, &cognito.GetUserPoolsArgs{
// Name: cognitoUserPoolName,
// }, nil)
// if err != nil {
// return err
// }
// thisRestApi, err := apigateway.NewRestApi(ctx, "thisRestApi", nil)
// if err != nil {
// return err
// }
// thisResource, err := apigateway.NewResource(ctx, "thisResource", &apigateway.ResourceArgs{
// RestApi: thisRestApi.ID(),
// ParentId: thisRestApi.RootResourceId,
// PathPart: pulumi.String("{proxy+}"),
// })
// if err != nil {
// return err
// }
// thisAuthorizer, err := apigateway.NewAuthorizer(ctx, "thisAuthorizer", &apigateway.AuthorizerArgs{
// Type: pulumi.String("COGNITO_USER_POOLS"),
// RestApi: thisRestApi.ID(),
// ProviderArns: interface{}(thisUserPools.Arns),
// })
// if err != nil {
// return err
// }
// _, err = apigateway.NewMethod(ctx, "any", &apigateway.MethodArgs{
// RestApi: thisRestApi.ID(),
// ResourceId: thisResource.ID(),
// HttpMethod: pulumi.String("ANY"),
// Authorization: pulumi.String("COGNITO_USER_POOLS"),
// AuthorizerId: thisAuthorizer.ID(),
// RequestParameters: pulumi.BoolMap{
// "method.request.path.proxy": pulumi.Bool(true),
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// `aws_api_gateway_method` can be imported using `REST-API-ID/RESOURCE-ID/HTTP-METHOD`, e.g.,
//
// ```sh
// $ pulumi import aws:apigateway/method:Method example 12345abcde/67890fghij/GET
// ```
type Method struct {
pulumi.CustomResourceState
// Specify if the method requires an API key
ApiKeyRequired pulumi.BoolPtrOutput `pulumi:"apiKeyRequired"`
// The type of authorization used for the method (`NONE`, `CUSTOM`, `AWS_IAM`, `COGNITO_USER_POOLS`)
Authorization pulumi.StringOutput `pulumi:"authorization"`
// The authorization scopes used when the authorization is `COGNITO_USER_POOLS`
AuthorizationScopes pulumi.StringArrayOutput `pulumi:"authorizationScopes"`
// The authorizer id to be used when the authorization is `CUSTOM` or `COGNITO_USER_POOLS`
AuthorizerId pulumi.StringPtrOutput `pulumi:"authorizerId"`
// The HTTP Method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTIONS`, `ANY`)
HttpMethod pulumi.StringOutput `pulumi:"httpMethod"`
// The function name that will be given to the method when generating an SDK through API Gateway. If omitted, API Gateway will generate a function name based on the resource path and HTTP verb.
OperationName pulumi.StringPtrOutput `pulumi:"operationName"`
// A map of the API models used for the request's content type
// where key is the content type (e.g., `application/json`)
// and value is either `Error`, `Empty` (built-in models) or `apigateway.Model`'s `name`.
RequestModels pulumi.StringMapOutput `pulumi:"requestModels"`
// A map of request parameters (from the path, query string and headers) that should be passed to the integration. The boolean value indicates whether the parameter is required (`true`) or optional (`false`).
// For example: `requestParameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true}` would define that the header `X-Some-Header` and the query string `some-query-param` must be provided in the request.
RequestParameters pulumi.BoolMapOutput `pulumi:"requestParameters"`
// The ID of a `apigateway.RequestValidator`
RequestValidatorId pulumi.StringPtrOutput `pulumi:"requestValidatorId"`
// The API resource ID
ResourceId pulumi.StringOutput `pulumi:"resourceId"`
// The ID of the associated REST API
RestApi pulumi.StringOutput `pulumi:"restApi"`
}
// NewMethod registers a new resource with the given unique name, arguments, and options.
func NewMethod(ctx *pulumi.Context,
name string, args *MethodArgs, opts ...pulumi.ResourceOption) (*Method, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Authorization == nil {
return nil, errors.New("invalid value for required argument 'Authorization'")
}
if args.HttpMethod == nil {
return nil, errors.New("invalid value for required argument 'HttpMethod'")
}
if args.ResourceId == nil {
return nil, errors.New("invalid value for required argument 'ResourceId'")
}
if args.RestApi == nil {
return nil, errors.New("invalid value for required argument 'RestApi'")
}
var resource Method
err := ctx.RegisterResource("aws:apigateway/method:Method", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetMethod gets an existing Method resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetMethod(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *MethodState, opts ...pulumi.ResourceOption) (*Method, error) {
var resource Method
err := ctx.ReadResource("aws:apigateway/method:Method", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Method resources.
type methodState struct {
// Specify if the method requires an API key
ApiKeyRequired *bool `pulumi:"apiKeyRequired"`
// The type of authorization used for the method (`NONE`, `CUSTOM`, `AWS_IAM`, `COGNITO_USER_POOLS`)
Authorization *string `pulumi:"authorization"`
// The authorization scopes used when the authorization is `COGNITO_USER_POOLS`
AuthorizationScopes []string `pulumi:"authorizationScopes"`
// The authorizer id to be used when the authorization is `CUSTOM` or `COGNITO_USER_POOLS`
AuthorizerId *string `pulumi:"authorizerId"`
// The HTTP Method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTIONS`, `ANY`)
HttpMethod *string `pulumi:"httpMethod"`
// The function name that will be given to the method when generating an SDK through API Gateway. If omitted, API Gateway will generate a function name based on the resource path and HTTP verb.
OperationName *string `pulumi:"operationName"`
// A map of the API models used for the request's content type
// where key is the content type (e.g., `application/json`)
// and value is either `Error`, `Empty` (built-in models) or `apigateway.Model`'s `name`.
RequestModels map[string]string `pulumi:"requestModels"`
// A map of request parameters (from the path, query string and headers) that should be passed to the integration. The boolean value indicates whether the parameter is required (`true`) or optional (`false`).
// For example: `requestParameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true}` would define that the header `X-Some-Header` and the query string `some-query-param` must be provided in the request.
RequestParameters map[string]bool `pulumi:"requestParameters"`
// The ID of a `apigateway.RequestValidator`
RequestValidatorId *string `pulumi:"requestValidatorId"`
// The API resource ID
ResourceId *string `pulumi:"resourceId"`
// The ID of the associated REST API
RestApi interface{} `pulumi:"restApi"`
}
type MethodState struct {
// Specify if the method requires an API key
ApiKeyRequired pulumi.BoolPtrInput
// The type of authorization used for the method (`NONE`, `CUSTOM`, `AWS_IAM`, `COGNITO_USER_POOLS`)
Authorization pulumi.StringPtrInput
// The authorization scopes used when the authorization is `COGNITO_USER_POOLS`
AuthorizationScopes pulumi.StringArrayInput
// The authorizer id to be used when the authorization is `CUSTOM` or `COGNITO_USER_POOLS`
AuthorizerId pulumi.StringPtrInput
// The HTTP Method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTIONS`, `ANY`)
HttpMethod pulumi.StringPtrInput
// The function name that will be given to the method when generating an SDK through API Gateway. If omitted, API Gateway will generate a function name based on the resource path and HTTP verb.
OperationName pulumi.StringPtrInput
// A map of the API models used for the request's content type
// where key is the content type (e.g., `application/json`)
// and value is either `Error`, `Empty` (built-in models) or `apigateway.Model`'s `name`.
RequestModels pulumi.StringMapInput
// A map of request parameters (from the path, query string and headers) that should be passed to the integration. The boolean value indicates whether the parameter is required (`true`) or optional (`false`).
// For example: `requestParameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true}` would define that the header `X-Some-Header` and the query string `some-query-param` must be provided in the request.
RequestParameters pulumi.BoolMapInput
// The ID of a `apigateway.RequestValidator`
RequestValidatorId pulumi.StringPtrInput
// The API resource ID
ResourceId pulumi.StringPtrInput
// The ID of the associated REST API
RestApi pulumi.Input
}
func (MethodState) ElementType() reflect.Type {
return reflect.TypeOf((*methodState)(nil)).Elem()
}
type methodArgs struct {
// Specify if the method requires an API key
ApiKeyRequired *bool `pulumi:"apiKeyRequired"`
// The type of authorization used for the method (`NONE`, `CUSTOM`, `AWS_IAM`, `COGNITO_USER_POOLS`)
Authorization string `pulumi:"authorization"`
// The authorization scopes used when the authorization is `COGNITO_USER_POOLS`
AuthorizationScopes []string `pulumi:"authorizationScopes"`
// The authorizer id to be used when the authorization is `CUSTOM` or `COGNITO_USER_POOLS`
AuthorizerId *string `pulumi:"authorizerId"`
// The HTTP Method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTIONS`, `ANY`)
HttpMethod string `pulumi:"httpMethod"`
// The function name that will be given to the method when generating an SDK through API Gateway. If omitted, API Gateway will generate a function name based on the resource path and HTTP verb.
OperationName *string `pulumi:"operationName"`
// A map of the API models used for the request's content type
// where key is the content type (e.g., `application/json`)
// and value is either `Error`, `Empty` (built-in models) or `apigateway.Model`'s `name`.
RequestModels map[string]string `pulumi:"requestModels"`
// A map of request parameters (from the path, query string and headers) that should be passed to the integration. The boolean value indicates whether the parameter is required (`true`) or optional (`false`).
// For example: `requestParameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true}` would define that the header `X-Some-Header` and the query string `some-query-param` must be provided in the request.
RequestParameters map[string]bool `pulumi:"requestParameters"`
// The ID of a `apigateway.RequestValidator`
RequestValidatorId *string `pulumi:"requestValidatorId"`
// The API resource ID
ResourceId string `pulumi:"resourceId"`
// The ID of the associated REST API
RestApi interface{} `pulumi:"restApi"`
}
// The set of arguments for constructing a Method resource.
type MethodArgs struct {
// Specify if the method requires an API key
ApiKeyRequired pulumi.BoolPtrInput
// The type of authorization used for the method (`NONE`, `CUSTOM`, `AWS_IAM`, `COGNITO_USER_POOLS`)
Authorization pulumi.StringInput
// The authorization scopes used when the authorization is `COGNITO_USER_POOLS`
AuthorizationScopes pulumi.StringArrayInput
// The authorizer id to be used when the authorization is `CUSTOM` or `COGNITO_USER_POOLS`
AuthorizerId pulumi.StringPtrInput
// The HTTP Method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTIONS`, `ANY`)
HttpMethod pulumi.StringInput
// The function name that will be given to the method when generating an SDK through API Gateway. If omitted, API Gateway will generate a function name based on the resource path and HTTP verb.
OperationName pulumi.StringPtrInput
// A map of the API models used for the request's content type
// where key is the content type (e.g., `application/json`)
// and value is either `Error`, `Empty` (built-in models) or `apigateway.Model`'s `name`.
RequestModels pulumi.StringMapInput
// A map of request parameters (from the path, query string and headers) that should be passed to the integration. The boolean value indicates whether the parameter is required (`true`) or optional (`false`).
// For example: `requestParameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true}` would define that the header `X-Some-Header` and the query string `some-query-param` must be provided in the request.
RequestParameters pulumi.BoolMapInput
// The ID of a `apigateway.RequestValidator`
RequestValidatorId pulumi.StringPtrInput
// The API resource ID
ResourceId pulumi.StringInput
// The ID of the associated REST API
RestApi pulumi.Input
}
func (MethodArgs) ElementType() reflect.Type {
return reflect.TypeOf((*methodArgs)(nil)).Elem()
}
type MethodInput interface {
pulumi.Input
ToMethodOutput() MethodOutput
ToMethodOutputWithContext(ctx context.Context) MethodOutput
}
func (*Method) ElementType() reflect.Type {
return reflect.TypeOf((**Method)(nil)).Elem()
}
func (i *Method) ToMethodOutput() MethodOutput {
return i.ToMethodOutputWithContext(context.Background())
}
func (i *Method) ToMethodOutputWithContext(ctx context.Context) MethodOutput {
return pulumi.ToOutputWithContext(ctx, i).(MethodOutput)
}
// MethodArrayInput is an input type that accepts MethodArray and MethodArrayOutput values.
// You can construct a concrete instance of `MethodArrayInput` via:
//
// MethodArray{ MethodArgs{...} }
type MethodArrayInput interface {
pulumi.Input
ToMethodArrayOutput() MethodArrayOutput
ToMethodArrayOutputWithContext(context.Context) MethodArrayOutput
}
type MethodArray []MethodInput
func (MethodArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Method)(nil)).Elem()
}
func (i MethodArray) ToMethodArrayOutput() MethodArrayOutput {
return i.ToMethodArrayOutputWithContext(context.Background())
}
func (i MethodArray) ToMethodArrayOutputWithContext(ctx context.Context) MethodArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(MethodArrayOutput)
}
// MethodMapInput is an input type that accepts MethodMap and MethodMapOutput values.
// You can construct a concrete instance of `MethodMapInput` via:
//
// MethodMap{ "key": MethodArgs{...} }
type MethodMapInput interface {
pulumi.Input
ToMethodMapOutput() MethodMapOutput
ToMethodMapOutputWithContext(context.Context) MethodMapOutput
}
type MethodMap map[string]MethodInput
func (MethodMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Method)(nil)).Elem()
}
func (i MethodMap) ToMethodMapOutput() MethodMapOutput {
return i.ToMethodMapOutputWithContext(context.Background())
}
func (i MethodMap) ToMethodMapOutputWithContext(ctx context.Context) MethodMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(MethodMapOutput)
}
type MethodOutput struct{ *pulumi.OutputState }
func (MethodOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Method)(nil)).Elem()
}
func (o MethodOutput) ToMethodOutput() MethodOutput {
return o
}
func (o MethodOutput) ToMethodOutputWithContext(ctx context.Context) MethodOutput {
return o
}
type MethodArrayOutput struct{ *pulumi.OutputState }
func (MethodArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Method)(nil)).Elem()
}
func (o MethodArrayOutput) ToMethodArrayOutput() MethodArrayOutput {
return o
}
func (o MethodArrayOutput) ToMethodArrayOutputWithContext(ctx context.Context) MethodArrayOutput {
return o
}
func (o MethodArrayOutput) Index(i pulumi.IntInput) MethodOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Method {
return vs[0].([]*Method)[vs[1].(int)]
}).(MethodOutput)
}
type MethodMapOutput struct{ *pulumi.OutputState }
func (MethodMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Method)(nil)).Elem()
}
func (o MethodMapOutput) ToMethodMapOutput() MethodMapOutput {
return o
}
func (o MethodMapOutput) ToMethodMapOutputWithContext(ctx context.Context) MethodMapOutput {
return o
}
func (o MethodMapOutput) MapIndex(k pulumi.StringInput) MethodOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Method {
return vs[0].(map[string]*Method)[vs[1].(string)]
}).(MethodOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*MethodInput)(nil)).Elem(), &Method{})
pulumi.RegisterInputType(reflect.TypeOf((*MethodArrayInput)(nil)).Elem(), MethodArray{})
pulumi.RegisterInputType(reflect.TypeOf((*MethodMapInput)(nil)).Elem(), MethodMap{})
pulumi.RegisterOutputType(MethodOutput{})
pulumi.RegisterOutputType(MethodArrayOutput{})
pulumi.RegisterOutputType(MethodMapOutput{})
}