1package mysql 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// QueryTextsClient is the the Microsoft Azure management API provides create, read, update, and delete functionality 30// for Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and configurations 31// with new business model. 32type QueryTextsClient struct { 33 BaseClient 34} 35 36// NewQueryTextsClient creates an instance of the QueryTextsClient client. 37func NewQueryTextsClient(subscriptionID string) QueryTextsClient { 38 return NewQueryTextsClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewQueryTextsClientWithBaseURI creates an instance of the QueryTextsClient client using a custom endpoint. Use this 42// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 43func NewQueryTextsClientWithBaseURI(baseURI string, subscriptionID string) QueryTextsClient { 44 return QueryTextsClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// Get retrieve the Query-Store query texts for the queryId. 48// Parameters: 49// resourceGroupName - the name of the resource group. The name is case insensitive. 50// serverName - the name of the server. 51// queryID - the Query-Store query identifier. 52func (client QueryTextsClient) Get(ctx context.Context, resourceGroupName string, serverName string, queryID string) (result QueryText, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/QueryTextsClient.Get") 55 defer func() { 56 sc := -1 57 if result.Response.Response != nil { 58 sc = result.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: client.SubscriptionID, 65 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 66 {TargetValue: resourceGroupName, 67 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 68 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 69 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 70 return result, validation.NewError("mysql.QueryTextsClient", "Get", err.Error()) 71 } 72 73 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, queryID) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "Get", nil, "Failure preparing request") 76 return 77 } 78 79 resp, err := client.GetSender(req) 80 if err != nil { 81 result.Response = autorest.Response{Response: resp} 82 err = autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "Get", resp, "Failure sending request") 83 return 84 } 85 86 result, err = client.GetResponder(resp) 87 if err != nil { 88 err = autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "Get", resp, "Failure responding to request") 89 return 90 } 91 92 return 93} 94 95// GetPreparer prepares the Get request. 96func (client QueryTextsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, queryID string) (*http.Request, error) { 97 pathParameters := map[string]interface{}{ 98 "queryId": autorest.Encode("path", queryID), 99 "resourceGroupName": autorest.Encode("path", resourceGroupName), 100 "serverName": autorest.Encode("path", serverName), 101 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 102 } 103 104 const APIVersion = "2018-06-01" 105 queryParameters := map[string]interface{}{ 106 "api-version": APIVersion, 107 } 108 109 preparer := autorest.CreatePreparer( 110 autorest.AsGet(), 111 autorest.WithBaseURL(client.BaseURI), 112 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/queryTexts/{queryId}", pathParameters), 113 autorest.WithQueryParameters(queryParameters)) 114 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 115} 116 117// GetSender sends the Get request. The method will close the 118// http.Response Body if it receives an error. 119func (client QueryTextsClient) GetSender(req *http.Request) (*http.Response, error) { 120 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 121} 122 123// GetResponder handles the response to the Get request. The method always 124// closes the http.Response Body. 125func (client QueryTextsClient) GetResponder(resp *http.Response) (result QueryText, err error) { 126 err = autorest.Respond( 127 resp, 128 azure.WithErrorUnlessStatusCode(http.StatusOK), 129 autorest.ByUnmarshallingJSON(&result), 130 autorest.ByClosing()) 131 result.Response = autorest.Response{Response: resp} 132 return 133} 134 135// ListByServer retrieve the Query-Store query texts for specified queryIds. 136// Parameters: 137// resourceGroupName - the name of the resource group. The name is case insensitive. 138// serverName - the name of the server. 139// queryIds - the query identifiers 140func (client QueryTextsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string, queryIds []string) (result QueryTextsResultListPage, err error) { 141 if tracing.IsEnabled() { 142 ctx = tracing.StartSpan(ctx, fqdn+"/QueryTextsClient.ListByServer") 143 defer func() { 144 sc := -1 145 if result.qtrl.Response.Response != nil { 146 sc = result.qtrl.Response.Response.StatusCode 147 } 148 tracing.EndSpan(ctx, sc, err) 149 }() 150 } 151 if err := validation.Validate([]validation.Validation{ 152 {TargetValue: client.SubscriptionID, 153 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 154 {TargetValue: resourceGroupName, 155 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 156 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 157 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 158 {TargetValue: queryIds, 159 Constraints: []validation.Constraint{{Target: "queryIds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 160 return result, validation.NewError("mysql.QueryTextsClient", "ListByServer", err.Error()) 161 } 162 163 result.fn = client.listByServerNextResults 164 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName, queryIds) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "ListByServer", nil, "Failure preparing request") 167 return 168 } 169 170 resp, err := client.ListByServerSender(req) 171 if err != nil { 172 result.qtrl.Response = autorest.Response{Response: resp} 173 err = autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "ListByServer", resp, "Failure sending request") 174 return 175 } 176 177 result.qtrl, err = client.ListByServerResponder(resp) 178 if err != nil { 179 err = autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "ListByServer", resp, "Failure responding to request") 180 return 181 } 182 if result.qtrl.hasNextLink() && result.qtrl.IsEmpty() { 183 err = result.NextWithContext(ctx) 184 return 185 } 186 187 return 188} 189 190// ListByServerPreparer prepares the ListByServer request. 191func (client QueryTextsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string, queryIds []string) (*http.Request, error) { 192 pathParameters := map[string]interface{}{ 193 "resourceGroupName": autorest.Encode("path", resourceGroupName), 194 "serverName": autorest.Encode("path", serverName), 195 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 196 } 197 198 const APIVersion = "2018-06-01" 199 queryParameters := map[string]interface{}{ 200 "api-version": APIVersion, 201 "queryIds": queryIds, 202 } 203 204 preparer := autorest.CreatePreparer( 205 autorest.AsGet(), 206 autorest.WithBaseURL(client.BaseURI), 207 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/queryTexts", pathParameters), 208 autorest.WithQueryParameters(queryParameters)) 209 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 210} 211 212// ListByServerSender sends the ListByServer request. The method will close the 213// http.Response Body if it receives an error. 214func (client QueryTextsClient) ListByServerSender(req *http.Request) (*http.Response, error) { 215 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 216} 217 218// ListByServerResponder handles the response to the ListByServer request. The method always 219// closes the http.Response Body. 220func (client QueryTextsClient) ListByServerResponder(resp *http.Response) (result QueryTextsResultList, err error) { 221 err = autorest.Respond( 222 resp, 223 azure.WithErrorUnlessStatusCode(http.StatusOK), 224 autorest.ByUnmarshallingJSON(&result), 225 autorest.ByClosing()) 226 result.Response = autorest.Response{Response: resp} 227 return 228} 229 230// listByServerNextResults retrieves the next set of results, if any. 231func (client QueryTextsClient) listByServerNextResults(ctx context.Context, lastResults QueryTextsResultList) (result QueryTextsResultList, err error) { 232 req, err := lastResults.queryTextsResultListPreparer(ctx) 233 if err != nil { 234 return result, autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "listByServerNextResults", nil, "Failure preparing next results request") 235 } 236 if req == nil { 237 return 238 } 239 resp, err := client.ListByServerSender(req) 240 if err != nil { 241 result.Response = autorest.Response{Response: resp} 242 return result, autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "listByServerNextResults", resp, "Failure sending next results request") 243 } 244 result, err = client.ListByServerResponder(resp) 245 if err != nil { 246 err = autorest.NewErrorWithError(err, "mysql.QueryTextsClient", "listByServerNextResults", resp, "Failure responding to next results request") 247 } 248 return 249} 250 251// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 252func (client QueryTextsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string, queryIds []string) (result QueryTextsResultListIterator, err error) { 253 if tracing.IsEnabled() { 254 ctx = tracing.StartSpan(ctx, fqdn+"/QueryTextsClient.ListByServer") 255 defer func() { 256 sc := -1 257 if result.Response().Response.Response != nil { 258 sc = result.page.Response().Response.Response.StatusCode 259 } 260 tracing.EndSpan(ctx, sc, err) 261 }() 262 } 263 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName, queryIds) 264 return 265} 266