1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package apigateway
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/apigateway/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Add a method to an existing Resource resource.
15func (c *Client) PutMethod(ctx context.Context, params *PutMethodInput, optFns ...func(*Options)) (*PutMethodOutput, error) {
16	if params == nil {
17		params = &PutMethodInput{}
18	}
19
20	result, metadata, err := c.invokeOperation(ctx, "PutMethod", params, optFns, addOperationPutMethodMiddlewares)
21	if err != nil {
22		return nil, err
23	}
24
25	out := result.(*PutMethodOutput)
26	out.ResultMetadata = metadata
27	return out, nil
28}
29
30// Request to add a method to an existing Resource resource.
31type PutMethodInput struct {
32
33	// [Required] The method's authorization type. Valid values are NONE for open
34	// access, AWS_IAM for using AWS IAM permissions, CUSTOM for using a custom
35	// authorizer, or COGNITO_USER_POOLS for using a Cognito user pool.
36	//
37	// This member is required.
38	AuthorizationType *string
39
40	// [Required] Specifies the method request's HTTP method type.
41	//
42	// This member is required.
43	HttpMethod *string
44
45	// [Required] The Resource identifier for the new Method resource.
46	//
47	// This member is required.
48	ResourceId *string
49
50	// [Required] The string identifier of the associated RestApi.
51	//
52	// This member is required.
53	RestApiId *string
54
55	// Specifies whether the method required a valid ApiKey.
56	ApiKeyRequired bool
57
58	// A list of authorization scopes configured on the method. The scopes are used
59	// with a COGNITO_USER_POOLS authorizer to authorize the method invocation. The
60	// authorization works by matching the method scopes against the scopes parsed from
61	// the access token in the incoming request. The method invocation is authorized if
62	// any method scopes matches a claimed scope in the access token. Otherwise, the
63	// invocation is not authorized. When the method scope is configured, the client
64	// must provide an access token instead of an identity token for authorization
65	// purposes.
66	AuthorizationScopes []string
67
68	// Specifies the identifier of an Authorizer to use on this Method, if the type is
69	// CUSTOM or COGNITO_USER_POOLS. The authorizer identifier is generated by API
70	// Gateway when you created the authorizer.
71	AuthorizerId *string
72
73	// A human-friendly operation identifier for the method. For example, you can
74	// assign the operationName of ListPets for the GET /pets method in the PetStore
75	// example.
76	OperationName *string
77
78	// Specifies the Model resources used for the request's content type. Request
79	// models are represented as a key/value map, with a content type as the key and a
80	// Model name as the value.
81	RequestModels map[string]string
82
83	// A key-value map defining required or optional method request parameters that can
84	// be accepted by API Gateway. A key defines a method request parameter name
85	// matching the pattern of method.request.{location}.{name}, where location is
86	// querystring, path, or header and name is a valid and unique parameter name. The
87	// value associated with the key is a Boolean flag indicating whether the parameter
88	// is required (true) or optional (false). The method request parameter names
89	// defined here are available in Integration to be mapped to integration request
90	// parameters or body-mapping templates.
91	RequestParameters map[string]bool
92
93	// The identifier of a RequestValidator for validating the method request.
94	RequestValidatorId *string
95}
96
97// Represents a client-facing interface by which the client calls the API to access
98// back-end resources. A Method resource is integrated with an Integration
99// resource. Both consist of a request and one or more responses. The method
100// request takes the client input that is passed to the back end through the
101// integration request. A method response returns the output from the back end to
102// the client through an integration response. A method request is embodied in a
103// Method resource, whereas an integration request is embodied in an Integration
104// resource. On the other hand, a method response is represented by a
105// MethodResponse resource, whereas an integration response is represented by an
106// IntegrationResponse resource.
107// Example: Retrive the GET method on a specified
108// resource
109//
110// Request
111//
112// The following example request retrieves the information about
113// the GET method on an API resource (3kzxbg5sa2) of an API (fugvjdxtri). GET
114// /restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET HTTP/1.1 Content-Type:
115// application/json Host: apigateway.us-east-1.amazonaws.com X-Amz-Date:
116// 20160603T210259Z Authorization: AWS4-HMAC-SHA256
117// Credential={access_key_ID}/20160603/us-east-1/apigateway/aws4_request,
118// SignedHeaders=content-type;host;x-amz-date, Signature={sig4_hash}
119// Response
120//
121// The
122// successful response returns a 200 OK status code and a payload similar to the
123// following: { "_links": { "curies": [ { "href":
124// "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-integration-{rel}.html",
125// "name": "integration", "templated": true }, { "href":
126// "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-integration-response-{rel}.html",
127// "name": "integrationresponse", "templated": true }, { "href":
128// "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-method-{rel}.html",
129// "name": "method", "templated": true }, { "href":
130// "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-method-response-{rel}.html",
131// "name": "methodresponse", "templated": true } ], "self": { "href":
132// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET", "name": "GET", "title":
133// "GET" }, "integration:put": { "href":
134// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration" },
135// "method:delete": { "href":
136// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET" }, "method:integration":
137// { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration" },
138// "method:responses": { "href":
139// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200", "name":
140// "200", "title": "200" }, "method:update": { "href":
141// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET" }, "methodresponse:put":
142// { "href":
143// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/{status_code}",
144// "templated": true } }, "apiKeyRequired": true, "authorizationType": "NONE",
145// "httpMethod": "GET", "_embedded": { "method:integration": { "_links": { "self":
146// { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration" },
147// "integration:delete": { "href":
148// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration" },
149// "integration:responses": { "href":
150// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration/responses/200",
151// "name": "200", "title": "200" }, "integration:update": { "href":
152// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration" },
153// "integrationresponse:put": { "href":
154// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration/responses/{status_code}",
155// "templated": true } }, "cacheKeyParameters": [], "cacheNamespace": "3kzxbg5sa2",
156// "credentials": "arn:aws:iam::123456789012:role/apigAwsProxyRole", "httpMethod":
157// "POST", "passthroughBehavior": "WHEN_NO_MATCH", "requestParameters": {
158// "integration.request.header.Content-Type": "'application/x-amz-json-1.1'" },
159// "requestTemplates": { "application/json": "{\n}" }, "type": "AWS", "uri":
160// "arn:aws:apigateway:us-east-1:kinesis:action/ListStreams", "_embedded": {
161// "integration:responses": { "_links": { "self": { "href":
162// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration/responses/200",
163// "name": "200", "title": "200" }, "integrationresponse:delete": { "href":
164// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration/responses/200"
165// }, "integrationresponse:update": { "href":
166// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/integration/responses/200"
167// } }, "responseParameters": { "method.response.header.Content-Type":
168// "'application/xml'" }, "responseTemplates": { "application/json":
169// "$util.urlDecode(\"%3CkinesisStreams%3E%23foreach(%24stream%20in%20%24input.path(%27%24.StreamNames%27))%3Cstream%3E%3Cname%3E%24stream%3C%2Fname%3E%3C%2Fstream%3E%23end%3C%2FkinesisStreams%3E\")"
170// }, "statusCode": "200" } } }, "method:responses": { "_links": { "self": {
171// "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200",
172// "name": "200", "title": "200" }, "methodresponse:delete": { "href":
173// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200" },
174// "methodresponse:update": { "href":
175// "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200" } },
176// "responseModels": { "application/json": "Empty" }, "responseParameters": {
177// "method.response.header.Content-Type": false }, "statusCode": "200" } } } In the
178// example above, the response template for the 200 OK response maps the JSON
179// output from the ListStreams action in the back end to an XML output. The mapping
180// template is URL-encoded as
181// %3CkinesisStreams%3E%23foreach(%24stream%20in%20%24input.path(%27%24.StreamNames%27))%3Cstream%3E%3Cname%3E%24stream%3C%2Fname%3E%3C%2Fstream%3E%23end%3C%2FkinesisStreams%3E
182// and the output is decoded using the $util.urlDecode()
183// (https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#util-templat-reference)
184// helper function. MethodResponse, Integration, IntegrationResponse, Resource, Set
185// up an API's method
186// (https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings.html)
187type PutMethodOutput struct {
188
189	// A boolean flag specifying whether a valid ApiKey is required to invoke this
190	// method.
191	ApiKeyRequired *bool
192
193	// A list of authorization scopes configured on the method. The scopes are used
194	// with a COGNITO_USER_POOLS authorizer to authorize the method invocation. The
195	// authorization works by matching the method scopes against the scopes parsed from
196	// the access token in the incoming request. The method invocation is authorized if
197	// any method scopes matches a claimed scope in the access token. Otherwise, the
198	// invocation is not authorized. When the method scope is configured, the client
199	// must provide an access token instead of an identity token for authorization
200	// purposes.
201	AuthorizationScopes []string
202
203	// The method's authorization type. Valid values are NONE for open access, AWS_IAM
204	// for using AWS IAM permissions, CUSTOM for using a custom authorizer, or
205	// COGNITO_USER_POOLS for using a Cognito user pool.
206	AuthorizationType *string
207
208	// The identifier of an Authorizer to use on this method. The authorizationType
209	// must be CUSTOM.
210	AuthorizerId *string
211
212	// The method's HTTP verb.
213	HttpMethod *string
214
215	// Gets the method's integration responsible for passing the client-submitted
216	// request to the back end and performing necessary transformations to make the
217	// request compliant with the back end.
218	// Example:
219	//
220	// Request
221	//
222	//     GET
223	// /restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration HTTP/1.1
224	// Content-Type: application/json Host: apigateway.us-east-1.amazonaws.com
225	// Content-Length: 117 X-Amz-Date: 20160613T213210Z Authorization: AWS4-HMAC-SHA256
226	// Credential={access_key_ID}/20160613/us-east-1/apigateway/aws4_request,
227	// SignedHeaders=content-type;host;x-amz-date, Signature={sig4_hash}
228	//
229	// Response
230	//
231	// The
232	// successful response returns a 200 OK status code and a payload similar to the
233	// following: { "_links": { "curies": [ { "href":
234	// "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-integration-{rel}.html",
235	// "name": "integration", "templated": true }, { "href":
236	// "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-integration-response-{rel}.html",
237	// "name": "integrationresponse", "templated": true } ], "self": { "href":
238	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration" },
239	// "integration:delete": { "href":
240	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration" },
241	// "integration:responses": { "href":
242	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration/responses/200",
243	// "name": "200", "title": "200" }, "integration:update": { "href":
244	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration" },
245	// "integrationresponse:put": { "href":
246	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration/responses/{status_code}",
247	// "templated": true } }, "cacheKeyParameters": [], "cacheNamespace": "0cjtch",
248	// "credentials": "arn:aws:iam::123456789012:role/apigAwsProxyRole", "httpMethod":
249	// "POST", "passthroughBehavior": "WHEN_NO_MATCH", "requestTemplates": {
250	// "application/json": "{\n \"a\": \"$input.params('operand1')\",\n \"b\":
251	// \"$input.params('operand2')\", \n \"op\": \"$input.params('operator')\" \n}" },
252	// "type": "AWS", "uri":
253	// "arn:aws:apigateway:us-west-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:Calc/invocations",
254	// "_embedded": { "integration:responses": { "_links": { "self": { "href":
255	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration/responses/200",
256	// "name": "200", "title": "200" }, "integrationresponse:delete": { "href":
257	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration/responses/200" },
258	// "integrationresponse:update": { "href":
259	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/integration/responses/200" }
260	// }, "responseParameters": { "method.response.header.operator":
261	// "integration.response.body.op", "method.response.header.operand_2":
262	// "integration.response.body.b", "method.response.header.operand_1":
263	// "integration.response.body.a" }, "responseTemplates": { "application/json":
264	// "#set($res = $input.path('$'))\n{\n \"result\": \"$res.a, $res.b, $res.op =>
265	// $res.c\",\n \"a\" : \"$res.a\",\n \"b\" : \"$res.b\",\n \"op\" : \"$res.op\",\n
266	// \"c\" : \"$res.c\"\n}" }, "selectionPattern": "", "statusCode": "200" } } }AWS
267	// CLI
268	// (https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-integration.html)
269	MethodIntegration *types.Integration
270
271	// Gets a method response associated with a given HTTP status code. The collection
272	// of method responses are encapsulated in a key-value map, where the key is a
273	// response's HTTP status code and the value is a MethodResponse resource that
274	// specifies the response returned to the caller from the back end through the
275	// integration response.
276	// Example: Get a 200 OK response of a GET method
277	//
278	// Request
279	//
280	//
281	// GET /restapis/uojnr9hd57/resources/0cjtch/methods/GET/responses/200 HTTP/1.1
282	// Content-Type: application/json Host: apigateway.us-east-1.amazonaws.com
283	// Content-Length: 117 X-Amz-Date: 20160613T215008Z Authorization: AWS4-HMAC-SHA256
284	// Credential={access_key_ID}/20160613/us-east-1/apigateway/aws4_request,
285	// SignedHeaders=content-type;host;x-amz-date, Signature={sig4_hash}
286	//
287	// Response
288	//
289	// The
290	// successful response returns a 200 OK status code and a payload similar to the
291	// following: { "_links": { "curies": { "href":
292	// "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-method-response-{rel}.html",
293	// "name": "methodresponse", "templated": true }, "self": { "href":
294	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/responses/200", "title":
295	// "200" }, "methodresponse:delete": { "href":
296	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/responses/200" },
297	// "methodresponse:update": { "href":
298	// "/restapis/uojnr9hd57/resources/0cjtch/methods/GET/responses/200" } },
299	// "responseModels": { "application/json": "Empty" }, "responseParameters": {
300	// "method.response.header.operator": false, "method.response.header.operand_2":
301	// false, "method.response.header.operand_1": false }, "statusCode": "200" }AWS CLI
302	// (https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-method-response.html)
303	MethodResponses map[string]types.MethodResponse
304
305	// A human-friendly operation identifier for the method. For example, you can
306	// assign the operationName of ListPets for the GET /pets method in the PetStore
307	// example.
308	OperationName *string
309
310	// A key-value map specifying data schemas, represented by Model resources, (as the
311	// mapped value) of the request payloads of given content types (as the mapping
312	// key).
313	RequestModels map[string]string
314
315	// A key-value map defining required or optional method request parameters that can
316	// be accepted by API Gateway. A key is a method request parameter name matching
317	// the pattern of method.request.{location}.{name}, where location is querystring,
318	// path, or header and name is a valid and unique parameter name. The value
319	// associated with the key is a Boolean flag indicating whether the parameter is
320	// required (true) or optional (false). The method request parameter names defined
321	// here are available in Integration to be mapped to integration request parameters
322	// or templates.
323	RequestParameters map[string]bool
324
325	// The identifier of a RequestValidator for request validation.
326	RequestValidatorId *string
327
328	// Metadata pertaining to the operation's result.
329	ResultMetadata middleware.Metadata
330}
331
332func addOperationPutMethodMiddlewares(stack *middleware.Stack, options Options) (err error) {
333	err = stack.Serialize.Add(&awsRestjson1_serializeOpPutMethod{}, middleware.After)
334	if err != nil {
335		return err
336	}
337	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpPutMethod{}, middleware.After)
338	if err != nil {
339		return err
340	}
341	if err = addSetLoggerMiddleware(stack, options); err != nil {
342		return err
343	}
344	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
345		return err
346	}
347	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
348		return err
349	}
350	if err = addResolveEndpointMiddleware(stack, options); err != nil {
351		return err
352	}
353	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
354		return err
355	}
356	if err = addRetryMiddlewares(stack, options); err != nil {
357		return err
358	}
359	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
360		return err
361	}
362	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
363		return err
364	}
365	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
366		return err
367	}
368	if err = addClientUserAgent(stack); err != nil {
369		return err
370	}
371	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
372		return err
373	}
374	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
375		return err
376	}
377	if err = addOpPutMethodValidationMiddleware(stack); err != nil {
378		return err
379	}
380	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutMethod(options.Region), middleware.Before); err != nil {
381		return err
382	}
383	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
384		return err
385	}
386	if err = addResponseErrorMiddleware(stack); err != nil {
387		return err
388	}
389	if err = addAcceptHeader(stack); err != nil {
390		return err
391	}
392	if err = addRequestResponseLogging(stack, options); err != nil {
393		return err
394	}
395	return nil
396}
397
398func newServiceMetadataMiddleware_opPutMethod(region string) *awsmiddleware.RegisterServiceMetadata {
399	return &awsmiddleware.RegisterServiceMetadata{
400		Region:        region,
401		ServiceID:     ServiceID,
402		SigningName:   "apigateway",
403		OperationName: "PutMethod",
404	}
405}
406