1package support 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// ServicesClient is the microsoft Azure Support Resource Provider. 18type ServicesClient struct { 19 BaseClient 20} 21 22// NewServicesClient creates an instance of the ServicesClient client. 23func NewServicesClient(subscriptionID string) ServicesClient { 24 return NewServicesClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewServicesClientWithBaseURI creates an instance of the ServicesClient client using a custom endpoint. Use this 28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewServicesClientWithBaseURI(baseURI string, subscriptionID string) ServicesClient { 30 return ServicesClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// Get gets a specific Azure service for support ticket creation. 34// Parameters: 35// serviceName - name of the Azure service. 36func (client ServicesClient) Get(ctx context.Context, serviceName string) (result Service, err error) { 37 if tracing.IsEnabled() { 38 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Get") 39 defer func() { 40 sc := -1 41 if result.Response.Response != nil { 42 sc = result.Response.Response.StatusCode 43 } 44 tracing.EndSpan(ctx, sc, err) 45 }() 46 } 47 req, err := client.GetPreparer(ctx, serviceName) 48 if err != nil { 49 err = autorest.NewErrorWithError(err, "support.ServicesClient", "Get", nil, "Failure preparing request") 50 return 51 } 52 53 resp, err := client.GetSender(req) 54 if err != nil { 55 result.Response = autorest.Response{Response: resp} 56 err = autorest.NewErrorWithError(err, "support.ServicesClient", "Get", resp, "Failure sending request") 57 return 58 } 59 60 result, err = client.GetResponder(resp) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "support.ServicesClient", "Get", resp, "Failure responding to request") 63 return 64 } 65 66 return 67} 68 69// GetPreparer prepares the Get request. 70func (client ServicesClient) GetPreparer(ctx context.Context, serviceName string) (*http.Request, error) { 71 pathParameters := map[string]interface{}{ 72 "serviceName": autorest.Encode("path", serviceName), 73 } 74 75 const APIVersion = "2020-04-01" 76 queryParameters := map[string]interface{}{ 77 "api-version": APIVersion, 78 } 79 80 preparer := autorest.CreatePreparer( 81 autorest.AsGet(), 82 autorest.WithBaseURL(client.BaseURI), 83 autorest.WithPathParameters("/providers/Microsoft.Support/services/{serviceName}", pathParameters), 84 autorest.WithQueryParameters(queryParameters)) 85 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 86} 87 88// GetSender sends the Get request. The method will close the 89// http.Response Body if it receives an error. 90func (client ServicesClient) GetSender(req *http.Request) (*http.Response, error) { 91 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 92} 93 94// GetResponder handles the response to the Get request. The method always 95// closes the http.Response Body. 96func (client ServicesClient) GetResponder(resp *http.Response) (result Service, err error) { 97 err = autorest.Respond( 98 resp, 99 azure.WithErrorUnlessStatusCode(http.StatusOK), 100 autorest.ByUnmarshallingJSON(&result), 101 autorest.ByClosing()) 102 result.Response = autorest.Response{Response: resp} 103 return 104} 105 106// List lists all the Azure services available for support ticket creation. For **Technical** issues, select the 107// Service Id that maps to the Azure service/product as displayed in the **Services** drop-down list on the Azure 108// portal's [New support request](https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/overview) 109// page. Always use the service and its corresponding problem classification(s) obtained programmatically for support 110// ticket creation. This practice ensures that you always have the most recent set of service and problem 111// classification Ids. 112func (client ServicesClient) List(ctx context.Context) (result ServicesListResult, err error) { 113 if tracing.IsEnabled() { 114 ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.List") 115 defer func() { 116 sc := -1 117 if result.Response.Response != nil { 118 sc = result.Response.Response.StatusCode 119 } 120 tracing.EndSpan(ctx, sc, err) 121 }() 122 } 123 req, err := client.ListPreparer(ctx) 124 if err != nil { 125 err = autorest.NewErrorWithError(err, "support.ServicesClient", "List", nil, "Failure preparing request") 126 return 127 } 128 129 resp, err := client.ListSender(req) 130 if err != nil { 131 result.Response = autorest.Response{Response: resp} 132 err = autorest.NewErrorWithError(err, "support.ServicesClient", "List", resp, "Failure sending request") 133 return 134 } 135 136 result, err = client.ListResponder(resp) 137 if err != nil { 138 err = autorest.NewErrorWithError(err, "support.ServicesClient", "List", resp, "Failure responding to request") 139 return 140 } 141 142 return 143} 144 145// ListPreparer prepares the List request. 146func (client ServicesClient) ListPreparer(ctx context.Context) (*http.Request, error) { 147 const APIVersion = "2020-04-01" 148 queryParameters := map[string]interface{}{ 149 "api-version": APIVersion, 150 } 151 152 preparer := autorest.CreatePreparer( 153 autorest.AsGet(), 154 autorest.WithBaseURL(client.BaseURI), 155 autorest.WithPath("/providers/Microsoft.Support/services"), 156 autorest.WithQueryParameters(queryParameters)) 157 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 158} 159 160// ListSender sends the List request. The method will close the 161// http.Response Body if it receives an error. 162func (client ServicesClient) ListSender(req *http.Request) (*http.Response, error) { 163 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 164} 165 166// ListResponder handles the response to the List request. The method always 167// closes the http.Response Body. 168func (client ServicesClient) ListResponder(resp *http.Response) (result ServicesListResult, err error) { 169 err = autorest.Respond( 170 resp, 171 azure.WithErrorUnlessStatusCode(http.StatusOK), 172 autorest.ByUnmarshallingJSON(&result), 173 autorest.ByClosing()) 174 result.Response = autorest.Response{Response: resp} 175 return 176} 177