1package databoxedge 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// AlertsClient is the client for the Alerts methods of the Databoxedge service. 18type AlertsClient struct { 19 BaseClient 20} 21 22// NewAlertsClient creates an instance of the AlertsClient client. 23func NewAlertsClient(subscriptionID string) AlertsClient { 24 return NewAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewAlertsClientWithBaseURI creates an instance of the AlertsClient client using a custom endpoint. Use this when 28// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewAlertsClientWithBaseURI(baseURI string, subscriptionID string) AlertsClient { 30 return AlertsClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// Get sends the get request. 34// Parameters: 35// deviceName - the device name. 36// name - the alert name. 37// resourceGroupName - the resource group name. 38func (client AlertsClient) Get(ctx context.Context, deviceName string, name string, resourceGroupName string) (result Alert, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.Get") 41 defer func() { 42 sc := -1 43 if result.Response.Response != nil { 44 sc = result.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 req, err := client.GetPreparer(ctx, deviceName, name, resourceGroupName) 50 if err != nil { 51 err = autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "Get", nil, "Failure preparing request") 52 return 53 } 54 55 resp, err := client.GetSender(req) 56 if err != nil { 57 result.Response = autorest.Response{Response: resp} 58 err = autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "Get", resp, "Failure sending request") 59 return 60 } 61 62 result, err = client.GetResponder(resp) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "Get", resp, "Failure responding to request") 65 return 66 } 67 68 return 69} 70 71// GetPreparer prepares the Get request. 72func (client AlertsClient) GetPreparer(ctx context.Context, deviceName string, name string, resourceGroupName string) (*http.Request, error) { 73 pathParameters := map[string]interface{}{ 74 "deviceName": autorest.Encode("path", deviceName), 75 "name": autorest.Encode("path", name), 76 "resourceGroupName": autorest.Encode("path", resourceGroupName), 77 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 78 } 79 80 const APIVersion = "2020-12-01" 81 queryParameters := map[string]interface{}{ 82 "api-version": APIVersion, 83 } 84 85 preparer := autorest.CreatePreparer( 86 autorest.AsGet(), 87 autorest.WithBaseURL(client.BaseURI), 88 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/alerts/{name}", pathParameters), 89 autorest.WithQueryParameters(queryParameters)) 90 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 91} 92 93// GetSender sends the Get request. The method will close the 94// http.Response Body if it receives an error. 95func (client AlertsClient) GetSender(req *http.Request) (*http.Response, error) { 96 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 97} 98 99// GetResponder handles the response to the Get request. The method always 100// closes the http.Response Body. 101func (client AlertsClient) GetResponder(resp *http.Response) (result Alert, err error) { 102 err = autorest.Respond( 103 resp, 104 azure.WithErrorUnlessStatusCode(http.StatusOK), 105 autorest.ByUnmarshallingJSON(&result), 106 autorest.ByClosing()) 107 result.Response = autorest.Response{Response: resp} 108 return 109} 110 111// ListByDataBoxEdgeDevice gets all the alerts for a Data Box Edge/Data Box Gateway device. 112// Parameters: 113// deviceName - the device name. 114// resourceGroupName - the resource group name. 115func (client AlertsClient) ListByDataBoxEdgeDevice(ctx context.Context, deviceName string, resourceGroupName string) (result AlertListPage, err error) { 116 if tracing.IsEnabled() { 117 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListByDataBoxEdgeDevice") 118 defer func() { 119 sc := -1 120 if result.al.Response.Response != nil { 121 sc = result.al.Response.Response.StatusCode 122 } 123 tracing.EndSpan(ctx, sc, err) 124 }() 125 } 126 result.fn = client.listByDataBoxEdgeDeviceNextResults 127 req, err := client.ListByDataBoxEdgeDevicePreparer(ctx, deviceName, resourceGroupName) 128 if err != nil { 129 err = autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "ListByDataBoxEdgeDevice", nil, "Failure preparing request") 130 return 131 } 132 133 resp, err := client.ListByDataBoxEdgeDeviceSender(req) 134 if err != nil { 135 result.al.Response = autorest.Response{Response: resp} 136 err = autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "ListByDataBoxEdgeDevice", resp, "Failure sending request") 137 return 138 } 139 140 result.al, err = client.ListByDataBoxEdgeDeviceResponder(resp) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "ListByDataBoxEdgeDevice", resp, "Failure responding to request") 143 return 144 } 145 if result.al.hasNextLink() && result.al.IsEmpty() { 146 err = result.NextWithContext(ctx) 147 return 148 } 149 150 return 151} 152 153// ListByDataBoxEdgeDevicePreparer prepares the ListByDataBoxEdgeDevice request. 154func (client AlertsClient) ListByDataBoxEdgeDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string) (*http.Request, error) { 155 pathParameters := map[string]interface{}{ 156 "deviceName": autorest.Encode("path", deviceName), 157 "resourceGroupName": autorest.Encode("path", resourceGroupName), 158 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 159 } 160 161 const APIVersion = "2020-12-01" 162 queryParameters := map[string]interface{}{ 163 "api-version": APIVersion, 164 } 165 166 preparer := autorest.CreatePreparer( 167 autorest.AsGet(), 168 autorest.WithBaseURL(client.BaseURI), 169 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/alerts", pathParameters), 170 autorest.WithQueryParameters(queryParameters)) 171 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 172} 173 174// ListByDataBoxEdgeDeviceSender sends the ListByDataBoxEdgeDevice request. The method will close the 175// http.Response Body if it receives an error. 176func (client AlertsClient) ListByDataBoxEdgeDeviceSender(req *http.Request) (*http.Response, error) { 177 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 178} 179 180// ListByDataBoxEdgeDeviceResponder handles the response to the ListByDataBoxEdgeDevice request. The method always 181// closes the http.Response Body. 182func (client AlertsClient) ListByDataBoxEdgeDeviceResponder(resp *http.Response) (result AlertList, err error) { 183 err = autorest.Respond( 184 resp, 185 azure.WithErrorUnlessStatusCode(http.StatusOK), 186 autorest.ByUnmarshallingJSON(&result), 187 autorest.ByClosing()) 188 result.Response = autorest.Response{Response: resp} 189 return 190} 191 192// listByDataBoxEdgeDeviceNextResults retrieves the next set of results, if any. 193func (client AlertsClient) listByDataBoxEdgeDeviceNextResults(ctx context.Context, lastResults AlertList) (result AlertList, err error) { 194 req, err := lastResults.alertListPreparer(ctx) 195 if err != nil { 196 return result, autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "listByDataBoxEdgeDeviceNextResults", nil, "Failure preparing next results request") 197 } 198 if req == nil { 199 return 200 } 201 resp, err := client.ListByDataBoxEdgeDeviceSender(req) 202 if err != nil { 203 result.Response = autorest.Response{Response: resp} 204 return result, autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "listByDataBoxEdgeDeviceNextResults", resp, "Failure sending next results request") 205 } 206 result, err = client.ListByDataBoxEdgeDeviceResponder(resp) 207 if err != nil { 208 err = autorest.NewErrorWithError(err, "databoxedge.AlertsClient", "listByDataBoxEdgeDeviceNextResults", resp, "Failure responding to next results request") 209 } 210 return 211} 212 213// ListByDataBoxEdgeDeviceComplete enumerates all values, automatically crossing page boundaries as required. 214func (client AlertsClient) ListByDataBoxEdgeDeviceComplete(ctx context.Context, deviceName string, resourceGroupName string) (result AlertListIterator, err error) { 215 if tracing.IsEnabled() { 216 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListByDataBoxEdgeDevice") 217 defer func() { 218 sc := -1 219 if result.Response().Response.Response != nil { 220 sc = result.page.Response().Response.Response.StatusCode 221 } 222 tracing.EndSpan(ctx, sc, err) 223 }() 224 } 225 result.page, err = client.ListByDataBoxEdgeDevice(ctx, deviceName, resourceGroupName) 226 return 227} 228