1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package cloudwatchlogs
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/smithy-go/middleware"
10	smithyhttp "github.com/aws/smithy-go/transport/http"
11)
12
13// Creates or updates a query definition for CloudWatch Logs Insights. For more
14// information, see Analyzing Log Data with CloudWatch Logs Insights
15// (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html).
16// To update a query definition, specify its queryDefinitionId in your request. The
17// values of name, queryString, and logGroupNames are changed to the values that
18// you specify in your update operation. No current values are retained from the
19// current query definition. For example, if you update a current query definition
20// that includes log groups, and you don't specify the logGroupNames parameter in
21// your update operation, the query definition changes to contain no log groups.
22// You must have the logs:PutQueryDefinition permission to be able to perform this
23// operation.
24func (c *Client) PutQueryDefinition(ctx context.Context, params *PutQueryDefinitionInput, optFns ...func(*Options)) (*PutQueryDefinitionOutput, error) {
25	if params == nil {
26		params = &PutQueryDefinitionInput{}
27	}
28
29	result, metadata, err := c.invokeOperation(ctx, "PutQueryDefinition", params, optFns, addOperationPutQueryDefinitionMiddlewares)
30	if err != nil {
31		return nil, err
32	}
33
34	out := result.(*PutQueryDefinitionOutput)
35	out.ResultMetadata = metadata
36	return out, nil
37}
38
39type PutQueryDefinitionInput struct {
40
41	// A name for the query definition. If you are saving a lot of query definitions,
42	// we recommend that you name them so that you can easily find the ones you want by
43	// using the first part of the name as a filter in the queryDefinitionNamePrefix
44	// parameter of DescribeQueryDefinitions
45	// (https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeQueryDefinitions.html).
46	//
47	// This member is required.
48	Name *string
49
50	// The query string to use for this definition. For more information, see
51	// CloudWatch Logs Insights Query Syntax
52	// (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html).
53	//
54	// This member is required.
55	QueryString *string
56
57	// Use this parameter to include specific log groups as part of your query
58	// definition. If you are updating a query definition and you omit this parameter,
59	// then the updated definition will contain no log groups.
60	LogGroupNames []string
61
62	// If you are updating a query definition, use this parameter to specify the ID of
63	// the query definition that you want to update. You can use
64	// DescribeQueryDefinitions
65	// (https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeQueryDefinitions.html)
66	// to retrieve the IDs of your saved query definitions. If you are creating a query
67	// definition, do not specify this parameter. CloudWatch generates a unique ID for
68	// the new query definition and include it in the response to this operation.
69	QueryDefinitionId *string
70}
71
72type PutQueryDefinitionOutput struct {
73
74	// The ID of the query definition.
75	QueryDefinitionId *string
76
77	// Metadata pertaining to the operation's result.
78	ResultMetadata middleware.Metadata
79}
80
81func addOperationPutQueryDefinitionMiddlewares(stack *middleware.Stack, options Options) (err error) {
82	err = stack.Serialize.Add(&awsAwsjson11_serializeOpPutQueryDefinition{}, middleware.After)
83	if err != nil {
84		return err
85	}
86	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpPutQueryDefinition{}, middleware.After)
87	if err != nil {
88		return err
89	}
90	if err = addSetLoggerMiddleware(stack, options); err != nil {
91		return err
92	}
93	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
97		return err
98	}
99	if err = addResolveEndpointMiddleware(stack, options); err != nil {
100		return err
101	}
102	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
103		return err
104	}
105	if err = addRetryMiddlewares(stack, options); err != nil {
106		return err
107	}
108	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
112		return err
113	}
114	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
115		return err
116	}
117	if err = addClientUserAgent(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addOpPutQueryDefinitionValidationMiddleware(stack); err != nil {
127		return err
128	}
129	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutQueryDefinition(options.Region), middleware.Before); err != nil {
130		return err
131	}
132	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
133		return err
134	}
135	if err = addResponseErrorMiddleware(stack); err != nil {
136		return err
137	}
138	if err = addRequestResponseLogging(stack, options); err != nil {
139		return err
140	}
141	return nil
142}
143
144func newServiceMetadataMiddleware_opPutQueryDefinition(region string) *awsmiddleware.RegisterServiceMetadata {
145	return &awsmiddleware.RegisterServiceMetadata{
146		Region:        region,
147		ServiceID:     ServiceID,
148		SigningName:   "logs",
149		OperationName: "PutQueryDefinition",
150	}
151}
152