1package postgresql
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// LogFilesClient is the the Microsoft Azure management API provides create, read, update, and delete functionality for
18// Azure PostgreSQL resources including servers, databases, firewall rules, VNET rules, security alert policies, log
19// files and configurations with new business model.
20type LogFilesClient struct {
21	BaseClient
22}
23
24// NewLogFilesClient creates an instance of the LogFilesClient client.
25func NewLogFilesClient(subscriptionID string) LogFilesClient {
26	return NewLogFilesClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewLogFilesClientWithBaseURI creates an instance of the LogFilesClient client using a custom endpoint.  Use this
30// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
31func NewLogFilesClientWithBaseURI(baseURI string, subscriptionID string) LogFilesClient {
32	return LogFilesClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// ListByServer list all the log files in a given server.
36// Parameters:
37// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
38// from the Azure Resource Manager API or the portal.
39// serverName - the name of the server.
40func (client LogFilesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result LogFileListResult, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/LogFilesClient.ListByServer")
43		defer func() {
44			sc := -1
45			if result.Response.Response != nil {
46				sc = result.Response.Response.StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName)
52	if err != nil {
53		err = autorest.NewErrorWithError(err, "postgresql.LogFilesClient", "ListByServer", nil, "Failure preparing request")
54		return
55	}
56
57	resp, err := client.ListByServerSender(req)
58	if err != nil {
59		result.Response = autorest.Response{Response: resp}
60		err = autorest.NewErrorWithError(err, "postgresql.LogFilesClient", "ListByServer", resp, "Failure sending request")
61		return
62	}
63
64	result, err = client.ListByServerResponder(resp)
65	if err != nil {
66		err = autorest.NewErrorWithError(err, "postgresql.LogFilesClient", "ListByServer", resp, "Failure responding to request")
67		return
68	}
69
70	return
71}
72
73// ListByServerPreparer prepares the ListByServer request.
74func (client LogFilesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
75	pathParameters := map[string]interface{}{
76		"resourceGroupName": autorest.Encode("path", resourceGroupName),
77		"serverName":        autorest.Encode("path", serverName),
78		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
79	}
80
81	const APIVersion = "2017-12-01-preview"
82	queryParameters := map[string]interface{}{
83		"api-version": APIVersion,
84	}
85
86	preparer := autorest.CreatePreparer(
87		autorest.AsGet(),
88		autorest.WithBaseURL(client.BaseURI),
89		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSQL/servers/{serverName}/logFiles", pathParameters),
90		autorest.WithQueryParameters(queryParameters))
91	return preparer.Prepare((&http.Request{}).WithContext(ctx))
92}
93
94// ListByServerSender sends the ListByServer request. The method will close the
95// http.Response Body if it receives an error.
96func (client LogFilesClient) ListByServerSender(req *http.Request) (*http.Response, error) {
97	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
98}
99
100// ListByServerResponder handles the response to the ListByServer request. The method always
101// closes the http.Response Body.
102func (client LogFilesClient) ListByServerResponder(resp *http.Response) (result LogFileListResult, err error) {
103	err = autorest.Respond(
104		resp,
105		azure.WithErrorUnlessStatusCode(http.StatusOK),
106		autorest.ByUnmarshallingJSON(&result),
107		autorest.ByClosing())
108	result.Response = autorest.Response{Response: resp}
109	return
110}
111