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/tracing"
25	"net/http"
26)
27
28// LogFilesClient is the the Microsoft Azure management API provides create, read, update, and delete functionality for
29// Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and configurations with
30// new business model.
31type LogFilesClient struct {
32	BaseClient
33}
34
35// NewLogFilesClient creates an instance of the LogFilesClient client.
36func NewLogFilesClient(subscriptionID string) LogFilesClient {
37	return NewLogFilesClientWithBaseURI(DefaultBaseURI, subscriptionID)
38}
39
40// NewLogFilesClientWithBaseURI creates an instance of the LogFilesClient client using a custom endpoint.  Use this
41// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
42func NewLogFilesClientWithBaseURI(baseURI string, subscriptionID string) LogFilesClient {
43	return LogFilesClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// ListByServer list all the log files in a given server.
47// Parameters:
48// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
49// from the Azure Resource Manager API or the portal.
50// serverName - the name of the server.
51func (client LogFilesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result LogFileListResult, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/LogFilesClient.ListByServer")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "mysql.LogFilesClient", "ListByServer", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.ListByServerSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "mysql.LogFilesClient", "ListByServer", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.ListByServerResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "mysql.LogFilesClient", "ListByServer", resp, "Failure responding to request")
78		return
79	}
80
81	return
82}
83
84// ListByServerPreparer prepares the ListByServer request.
85func (client LogFilesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"resourceGroupName": autorest.Encode("path", resourceGroupName),
88		"serverName":        autorest.Encode("path", serverName),
89		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2017-12-01-preview"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsGet(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySQL/servers/{serverName}/logFiles", pathParameters),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// ListByServerSender sends the ListByServer request. The method will close the
106// http.Response Body if it receives an error.
107func (client LogFilesClient) ListByServerSender(req *http.Request) (*http.Response, error) {
108	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
109}
110
111// ListByServerResponder handles the response to the ListByServer request. The method always
112// closes the http.Response Body.
113func (client LogFilesClient) ListByServerResponder(resp *http.Response) (result LogFileListResult, err error) {
114	err = autorest.Respond(
115		resp,
116		azure.WithErrorUnlessStatusCode(http.StatusOK),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122