...

Source file src/github.com/Azure/azure-sdk-for-go/services/windowsiot/mgmt/2019-06-01/windowsiot/services.go

Documentation: github.com/Azure/azure-sdk-for-go/services/windowsiot/mgmt/2019-06-01/windowsiot

     1  package windowsiot
     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  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // ServicesClient is the use this API to manage the Windows IoT device services in your Azure subscription.
    19  type ServicesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewServicesClient creates an instance of the ServicesClient client.
    24  func NewServicesClient(subscriptionID string) ServicesClient {
    25  	return NewServicesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewServicesClientWithBaseURI creates an instance of the ServicesClient client using a custom endpoint.  Use this
    29  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewServicesClientWithBaseURI(baseURI string, subscriptionID string) ServicesClient {
    31  	return ServicesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CheckDeviceServiceNameAvailability check if a Windows IoT Device Service name is available.
    35  // Parameters:
    36  // deviceServiceCheckNameAvailabilityParameters - set the name parameter in the
    37  // DeviceServiceCheckNameAvailabilityParameters structure to the name of the Windows IoT Device Service to
    38  // check.
    39  func (client ServicesClient) CheckDeviceServiceNameAvailability(ctx context.Context, deviceServiceCheckNameAvailabilityParameters DeviceServiceCheckNameAvailabilityParameters) (result DeviceServiceNameAvailabilityInfo, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.CheckDeviceServiceNameAvailability")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: deviceServiceCheckNameAvailabilityParameters,
    52  			Constraints: []validation.Constraint{{Target: "deviceServiceCheckNameAvailabilityParameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    53  		return result, validation.NewError("windowsiot.ServicesClient", "CheckDeviceServiceNameAvailability", err.Error())
    54  	}
    55  
    56  	req, err := client.CheckDeviceServiceNameAvailabilityPreparer(ctx, deviceServiceCheckNameAvailabilityParameters)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "CheckDeviceServiceNameAvailability", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	resp, err := client.CheckDeviceServiceNameAvailabilitySender(req)
    63  	if err != nil {
    64  		result.Response = autorest.Response{Response: resp}
    65  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "CheckDeviceServiceNameAvailability", resp, "Failure sending request")
    66  		return
    67  	}
    68  
    69  	result, err = client.CheckDeviceServiceNameAvailabilityResponder(resp)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "CheckDeviceServiceNameAvailability", resp, "Failure responding to request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // CheckDeviceServiceNameAvailabilityPreparer prepares the CheckDeviceServiceNameAvailability request.
    79  func (client ServicesClient) CheckDeviceServiceNameAvailabilityPreparer(ctx context.Context, deviceServiceCheckNameAvailabilityParameters DeviceServiceCheckNameAvailabilityParameters) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
    82  	}
    83  
    84  	const APIVersion = "2019-06-01"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  	}
    88  
    89  	preparer := autorest.CreatePreparer(
    90  		autorest.AsContentType("application/json; charset=utf-8"),
    91  		autorest.AsPost(),
    92  		autorest.WithBaseURL(client.BaseURI),
    93  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.WindowsIoT/checkDeviceServiceNameAvailability", pathParameters),
    94  		autorest.WithJSON(deviceServiceCheckNameAvailabilityParameters),
    95  		autorest.WithQueryParameters(queryParameters))
    96  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    97  }
    98  
    99  // CheckDeviceServiceNameAvailabilitySender sends the CheckDeviceServiceNameAvailability request. The method will close the
   100  // http.Response Body if it receives an error.
   101  func (client ServicesClient) CheckDeviceServiceNameAvailabilitySender(req *http.Request) (*http.Response, error) {
   102  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  }
   104  
   105  // CheckDeviceServiceNameAvailabilityResponder handles the response to the CheckDeviceServiceNameAvailability request. The method always
   106  // closes the http.Response Body.
   107  func (client ServicesClient) CheckDeviceServiceNameAvailabilityResponder(resp *http.Response) (result DeviceServiceNameAvailabilityInfo, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   111  		autorest.ByUnmarshallingJSON(&result),
   112  		autorest.ByClosing())
   113  	result.Response = autorest.Response{Response: resp}
   114  	return
   115  }
   116  
   117  // CreateOrUpdate create or update the metadata of a Windows IoT Device Service. The usual pattern to modify a property
   118  // is to retrieve the Windows IoT Device Service metadata and security metadata, and then combine them with the
   119  // modified values in a new body to update the Windows IoT Device Service.
   120  // Parameters:
   121  // resourceGroupName - the name of the resource group that contains the Windows IoT Device Service.
   122  // deviceName - the name of the Windows IoT Device Service.
   123  // deviceService - the Windows IoT Device Service metadata and security metadata.
   124  // ifMatch - eTag of the Windows IoT Device Service. Do not specify for creating a new Windows IoT Device
   125  // Service. Required to update an existing Windows IoT Device Service.
   126  func (client ServicesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, deviceName string, deviceService DeviceServiceProperties, ifMatch string) (result DeviceService, err error) {
   127  	if tracing.IsEnabled() {
   128  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.CreateOrUpdate")
   129  		defer func() {
   130  			sc := -1
   131  			if result.Response.Response != nil {
   132  				sc = result.Response.Response.StatusCode
   133  			}
   134  			tracing.EndSpan(ctx, sc, err)
   135  		}()
   136  	}
   137  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, deviceName, deviceService, ifMatch)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "CreateOrUpdate", nil, "Failure preparing request")
   140  		return
   141  	}
   142  
   143  	resp, err := client.CreateOrUpdateSender(req)
   144  	if err != nil {
   145  		result.Response = autorest.Response{Response: resp}
   146  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "CreateOrUpdate", resp, "Failure sending request")
   147  		return
   148  	}
   149  
   150  	result, err = client.CreateOrUpdateResponder(resp)
   151  	if err != nil {
   152  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "CreateOrUpdate", resp, "Failure responding to request")
   153  		return
   154  	}
   155  
   156  	return
   157  }
   158  
   159  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
   160  func (client ServicesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, deviceName string, deviceService DeviceServiceProperties, ifMatch string) (*http.Request, error) {
   161  	pathParameters := map[string]interface{}{
   162  		"deviceName":        autorest.Encode("path", deviceName),
   163  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   164  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   165  	}
   166  
   167  	const APIVersion = "2019-06-01"
   168  	queryParameters := map[string]interface{}{
   169  		"api-version": APIVersion,
   170  	}
   171  
   172  	deviceService.StartDate = nil
   173  	preparer := autorest.CreatePreparer(
   174  		autorest.AsContentType("application/json; charset=utf-8"),
   175  		autorest.AsPut(),
   176  		autorest.WithBaseURL(client.BaseURI),
   177  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.WindowsIoT/deviceServices/{deviceName}", pathParameters),
   178  		autorest.WithJSON(deviceService),
   179  		autorest.WithQueryParameters(queryParameters))
   180  	if len(ifMatch) > 0 {
   181  		preparer = autorest.DecoratePreparer(preparer,
   182  			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   183  	}
   184  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   185  }
   186  
   187  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   188  // http.Response Body if it receives an error.
   189  func (client ServicesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   190  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   191  }
   192  
   193  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   194  // closes the http.Response Body.
   195  func (client ServicesClient) CreateOrUpdateResponder(resp *http.Response) (result DeviceService, err error) {
   196  	err = autorest.Respond(
   197  		resp,
   198  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   199  		autorest.ByUnmarshallingJSON(&result),
   200  		autorest.ByClosing())
   201  	result.Response = autorest.Response{Response: resp}
   202  	return
   203  }
   204  
   205  // Delete delete a Windows IoT Device Service.
   206  // Parameters:
   207  // resourceGroupName - the name of the resource group that contains the Windows IoT Device Service.
   208  // deviceName - the name of the Windows IoT Device Service.
   209  func (client ServicesClient) Delete(ctx context.Context, resourceGroupName string, deviceName string) (result DeviceService, err error) {
   210  	if tracing.IsEnabled() {
   211  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Delete")
   212  		defer func() {
   213  			sc := -1
   214  			if result.Response.Response != nil {
   215  				sc = result.Response.Response.StatusCode
   216  			}
   217  			tracing.EndSpan(ctx, sc, err)
   218  		}()
   219  	}
   220  	req, err := client.DeletePreparer(ctx, resourceGroupName, deviceName)
   221  	if err != nil {
   222  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Delete", nil, "Failure preparing request")
   223  		return
   224  	}
   225  
   226  	resp, err := client.DeleteSender(req)
   227  	if err != nil {
   228  		result.Response = autorest.Response{Response: resp}
   229  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Delete", resp, "Failure sending request")
   230  		return
   231  	}
   232  
   233  	result, err = client.DeleteResponder(resp)
   234  	if err != nil {
   235  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Delete", resp, "Failure responding to request")
   236  		return
   237  	}
   238  
   239  	return
   240  }
   241  
   242  // DeletePreparer prepares the Delete request.
   243  func (client ServicesClient) DeletePreparer(ctx context.Context, resourceGroupName string, deviceName string) (*http.Request, error) {
   244  	pathParameters := map[string]interface{}{
   245  		"deviceName":        autorest.Encode("path", deviceName),
   246  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   247  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   248  	}
   249  
   250  	const APIVersion = "2019-06-01"
   251  	queryParameters := map[string]interface{}{
   252  		"api-version": APIVersion,
   253  	}
   254  
   255  	preparer := autorest.CreatePreparer(
   256  		autorest.AsDelete(),
   257  		autorest.WithBaseURL(client.BaseURI),
   258  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.WindowsIoT/deviceServices/{deviceName}", pathParameters),
   259  		autorest.WithQueryParameters(queryParameters))
   260  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   261  }
   262  
   263  // DeleteSender sends the Delete request. The method will close the
   264  // http.Response Body if it receives an error.
   265  func (client ServicesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   266  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   267  }
   268  
   269  // DeleteResponder handles the response to the Delete request. The method always
   270  // closes the http.Response Body.
   271  func (client ServicesClient) DeleteResponder(resp *http.Response) (result DeviceService, err error) {
   272  	err = autorest.Respond(
   273  		resp,
   274  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   275  		autorest.ByUnmarshallingJSON(&result),
   276  		autorest.ByClosing())
   277  	result.Response = autorest.Response{Response: resp}
   278  	return
   279  }
   280  
   281  // Get get the non-security related metadata of a Windows IoT Device Service.
   282  // Parameters:
   283  // resourceGroupName - the name of the resource group that contains the Windows IoT Device Service.
   284  // deviceName - the name of the Windows IoT Device Service.
   285  func (client ServicesClient) Get(ctx context.Context, resourceGroupName string, deviceName string) (result DeviceService, err error) {
   286  	if tracing.IsEnabled() {
   287  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Get")
   288  		defer func() {
   289  			sc := -1
   290  			if result.Response.Response != nil {
   291  				sc = result.Response.Response.StatusCode
   292  			}
   293  			tracing.EndSpan(ctx, sc, err)
   294  		}()
   295  	}
   296  	req, err := client.GetPreparer(ctx, resourceGroupName, deviceName)
   297  	if err != nil {
   298  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Get", nil, "Failure preparing request")
   299  		return
   300  	}
   301  
   302  	resp, err := client.GetSender(req)
   303  	if err != nil {
   304  		result.Response = autorest.Response{Response: resp}
   305  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Get", resp, "Failure sending request")
   306  		return
   307  	}
   308  
   309  	result, err = client.GetResponder(resp)
   310  	if err != nil {
   311  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Get", resp, "Failure responding to request")
   312  		return
   313  	}
   314  
   315  	return
   316  }
   317  
   318  // GetPreparer prepares the Get request.
   319  func (client ServicesClient) GetPreparer(ctx context.Context, resourceGroupName string, deviceName string) (*http.Request, error) {
   320  	pathParameters := map[string]interface{}{
   321  		"deviceName":        autorest.Encode("path", deviceName),
   322  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   323  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   324  	}
   325  
   326  	const APIVersion = "2019-06-01"
   327  	queryParameters := map[string]interface{}{
   328  		"api-version": APIVersion,
   329  	}
   330  
   331  	preparer := autorest.CreatePreparer(
   332  		autorest.AsGet(),
   333  		autorest.WithBaseURL(client.BaseURI),
   334  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.WindowsIoT/deviceServices/{deviceName}", pathParameters),
   335  		autorest.WithQueryParameters(queryParameters))
   336  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   337  }
   338  
   339  // GetSender sends the Get request. The method will close the
   340  // http.Response Body if it receives an error.
   341  func (client ServicesClient) GetSender(req *http.Request) (*http.Response, error) {
   342  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   343  }
   344  
   345  // GetResponder handles the response to the Get request. The method always
   346  // closes the http.Response Body.
   347  func (client ServicesClient) GetResponder(resp *http.Response) (result DeviceService, err error) {
   348  	err = autorest.Respond(
   349  		resp,
   350  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   351  		autorest.ByUnmarshallingJSON(&result),
   352  		autorest.ByClosing())
   353  	result.Response = autorest.Response{Response: resp}
   354  	return
   355  }
   356  
   357  // List get all the IoT hubs in a subscription.
   358  func (client ServicesClient) List(ctx context.Context) (result DeviceServiceDescriptionListResultPage, err error) {
   359  	if tracing.IsEnabled() {
   360  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.List")
   361  		defer func() {
   362  			sc := -1
   363  			if result.dsdlr.Response.Response != nil {
   364  				sc = result.dsdlr.Response.Response.StatusCode
   365  			}
   366  			tracing.EndSpan(ctx, sc, err)
   367  		}()
   368  	}
   369  	result.fn = client.listNextResults
   370  	req, err := client.ListPreparer(ctx)
   371  	if err != nil {
   372  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "List", nil, "Failure preparing request")
   373  		return
   374  	}
   375  
   376  	resp, err := client.ListSender(req)
   377  	if err != nil {
   378  		result.dsdlr.Response = autorest.Response{Response: resp}
   379  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "List", resp, "Failure sending request")
   380  		return
   381  	}
   382  
   383  	result.dsdlr, err = client.ListResponder(resp)
   384  	if err != nil {
   385  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "List", resp, "Failure responding to request")
   386  		return
   387  	}
   388  	if result.dsdlr.hasNextLink() && result.dsdlr.IsEmpty() {
   389  		err = result.NextWithContext(ctx)
   390  		return
   391  	}
   392  
   393  	return
   394  }
   395  
   396  // ListPreparer prepares the List request.
   397  func (client ServicesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   398  	pathParameters := map[string]interface{}{
   399  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   400  	}
   401  
   402  	const APIVersion = "2019-06-01"
   403  	queryParameters := map[string]interface{}{
   404  		"api-version": APIVersion,
   405  	}
   406  
   407  	preparer := autorest.CreatePreparer(
   408  		autorest.AsGet(),
   409  		autorest.WithBaseURL(client.BaseURI),
   410  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.WindowsIoT/deviceServices", pathParameters),
   411  		autorest.WithQueryParameters(queryParameters))
   412  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   413  }
   414  
   415  // ListSender sends the List request. The method will close the
   416  // http.Response Body if it receives an error.
   417  func (client ServicesClient) ListSender(req *http.Request) (*http.Response, error) {
   418  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   419  }
   420  
   421  // ListResponder handles the response to the List request. The method always
   422  // closes the http.Response Body.
   423  func (client ServicesClient) ListResponder(resp *http.Response) (result DeviceServiceDescriptionListResult, err error) {
   424  	err = autorest.Respond(
   425  		resp,
   426  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   427  		autorest.ByUnmarshallingJSON(&result),
   428  		autorest.ByClosing())
   429  	result.Response = autorest.Response{Response: resp}
   430  	return
   431  }
   432  
   433  // listNextResults retrieves the next set of results, if any.
   434  func (client ServicesClient) listNextResults(ctx context.Context, lastResults DeviceServiceDescriptionListResult) (result DeviceServiceDescriptionListResult, err error) {
   435  	req, err := lastResults.deviceServiceDescriptionListResultPreparer(ctx)
   436  	if err != nil {
   437  		return result, autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "listNextResults", nil, "Failure preparing next results request")
   438  	}
   439  	if req == nil {
   440  		return
   441  	}
   442  	resp, err := client.ListSender(req)
   443  	if err != nil {
   444  		result.Response = autorest.Response{Response: resp}
   445  		return result, autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "listNextResults", resp, "Failure sending next results request")
   446  	}
   447  	result, err = client.ListResponder(resp)
   448  	if err != nil {
   449  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "listNextResults", resp, "Failure responding to next results request")
   450  	}
   451  	return
   452  }
   453  
   454  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   455  func (client ServicesClient) ListComplete(ctx context.Context) (result DeviceServiceDescriptionListResultIterator, err error) {
   456  	if tracing.IsEnabled() {
   457  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.List")
   458  		defer func() {
   459  			sc := -1
   460  			if result.Response().Response.Response != nil {
   461  				sc = result.page.Response().Response.Response.StatusCode
   462  			}
   463  			tracing.EndSpan(ctx, sc, err)
   464  		}()
   465  	}
   466  	result.page, err = client.List(ctx)
   467  	return
   468  }
   469  
   470  // ListByResourceGroup get all the IoT hubs in a resource group.
   471  // Parameters:
   472  // resourceGroupName - the name of the resource group that contains the Windows IoT Device Service.
   473  func (client ServicesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result DeviceServiceDescriptionListResultPage, err error) {
   474  	if tracing.IsEnabled() {
   475  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListByResourceGroup")
   476  		defer func() {
   477  			sc := -1
   478  			if result.dsdlr.Response.Response != nil {
   479  				sc = result.dsdlr.Response.Response.StatusCode
   480  			}
   481  			tracing.EndSpan(ctx, sc, err)
   482  		}()
   483  	}
   484  	result.fn = client.listByResourceGroupNextResults
   485  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   486  	if err != nil {
   487  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "ListByResourceGroup", nil, "Failure preparing request")
   488  		return
   489  	}
   490  
   491  	resp, err := client.ListByResourceGroupSender(req)
   492  	if err != nil {
   493  		result.dsdlr.Response = autorest.Response{Response: resp}
   494  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "ListByResourceGroup", resp, "Failure sending request")
   495  		return
   496  	}
   497  
   498  	result.dsdlr, err = client.ListByResourceGroupResponder(resp)
   499  	if err != nil {
   500  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "ListByResourceGroup", resp, "Failure responding to request")
   501  		return
   502  	}
   503  	if result.dsdlr.hasNextLink() && result.dsdlr.IsEmpty() {
   504  		err = result.NextWithContext(ctx)
   505  		return
   506  	}
   507  
   508  	return
   509  }
   510  
   511  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   512  func (client ServicesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   513  	pathParameters := map[string]interface{}{
   514  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   515  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   516  	}
   517  
   518  	const APIVersion = "2019-06-01"
   519  	queryParameters := map[string]interface{}{
   520  		"api-version": APIVersion,
   521  	}
   522  
   523  	preparer := autorest.CreatePreparer(
   524  		autorest.AsGet(),
   525  		autorest.WithBaseURL(client.BaseURI),
   526  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.WindowsIoT/deviceServices", pathParameters),
   527  		autorest.WithQueryParameters(queryParameters))
   528  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   529  }
   530  
   531  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   532  // http.Response Body if it receives an error.
   533  func (client ServicesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   534  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   535  }
   536  
   537  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   538  // closes the http.Response Body.
   539  func (client ServicesClient) ListByResourceGroupResponder(resp *http.Response) (result DeviceServiceDescriptionListResult, err error) {
   540  	err = autorest.Respond(
   541  		resp,
   542  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   543  		autorest.ByUnmarshallingJSON(&result),
   544  		autorest.ByClosing())
   545  	result.Response = autorest.Response{Response: resp}
   546  	return
   547  }
   548  
   549  // listByResourceGroupNextResults retrieves the next set of results, if any.
   550  func (client ServicesClient) listByResourceGroupNextResults(ctx context.Context, lastResults DeviceServiceDescriptionListResult) (result DeviceServiceDescriptionListResult, err error) {
   551  	req, err := lastResults.deviceServiceDescriptionListResultPreparer(ctx)
   552  	if err != nil {
   553  		return result, autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
   554  	}
   555  	if req == nil {
   556  		return
   557  	}
   558  	resp, err := client.ListByResourceGroupSender(req)
   559  	if err != nil {
   560  		result.Response = autorest.Response{Response: resp}
   561  		return result, autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
   562  	}
   563  	result, err = client.ListByResourceGroupResponder(resp)
   564  	if err != nil {
   565  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
   566  	}
   567  	return
   568  }
   569  
   570  // ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   571  func (client ServicesClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result DeviceServiceDescriptionListResultIterator, err error) {
   572  	if tracing.IsEnabled() {
   573  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.ListByResourceGroup")
   574  		defer func() {
   575  			sc := -1
   576  			if result.Response().Response.Response != nil {
   577  				sc = result.page.Response().Response.Response.StatusCode
   578  			}
   579  			tracing.EndSpan(ctx, sc, err)
   580  		}()
   581  	}
   582  	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
   583  	return
   584  }
   585  
   586  // Update updates the metadata of a Windows IoT Device Service. The usual pattern to modify a property is to retrieve
   587  // the Windows IoT Device Service metadata and security metadata, and then combine them with the modified values in a
   588  // new body to update the Windows IoT Device Service.
   589  // Parameters:
   590  // resourceGroupName - the name of the resource group that contains the Windows IoT Device Service.
   591  // deviceName - the name of the Windows IoT Device Service.
   592  // deviceService - the Windows IoT Device Service metadata and security metadata.
   593  // ifMatch - eTag of the Windows IoT Device Service. Do not specify for creating a brand new Windows IoT Device
   594  // Service. Required to update an existing Windows IoT Device Service.
   595  func (client ServicesClient) Update(ctx context.Context, resourceGroupName string, deviceName string, deviceService DeviceServiceProperties, ifMatch string) (result DeviceService, err error) {
   596  	if tracing.IsEnabled() {
   597  		ctx = tracing.StartSpan(ctx, fqdn+"/ServicesClient.Update")
   598  		defer func() {
   599  			sc := -1
   600  			if result.Response.Response != nil {
   601  				sc = result.Response.Response.StatusCode
   602  			}
   603  			tracing.EndSpan(ctx, sc, err)
   604  		}()
   605  	}
   606  	req, err := client.UpdatePreparer(ctx, resourceGroupName, deviceName, deviceService, ifMatch)
   607  	if err != nil {
   608  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Update", nil, "Failure preparing request")
   609  		return
   610  	}
   611  
   612  	resp, err := client.UpdateSender(req)
   613  	if err != nil {
   614  		result.Response = autorest.Response{Response: resp}
   615  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Update", resp, "Failure sending request")
   616  		return
   617  	}
   618  
   619  	result, err = client.UpdateResponder(resp)
   620  	if err != nil {
   621  		err = autorest.NewErrorWithError(err, "windowsiot.ServicesClient", "Update", resp, "Failure responding to request")
   622  		return
   623  	}
   624  
   625  	return
   626  }
   627  
   628  // UpdatePreparer prepares the Update request.
   629  func (client ServicesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, deviceName string, deviceService DeviceServiceProperties, ifMatch string) (*http.Request, error) {
   630  	pathParameters := map[string]interface{}{
   631  		"deviceName":        autorest.Encode("path", deviceName),
   632  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   633  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   634  	}
   635  
   636  	const APIVersion = "2019-06-01"
   637  	queryParameters := map[string]interface{}{
   638  		"api-version": APIVersion,
   639  	}
   640  
   641  	deviceService.StartDate = nil
   642  	preparer := autorest.CreatePreparer(
   643  		autorest.AsContentType("application/json; charset=utf-8"),
   644  		autorest.AsPatch(),
   645  		autorest.WithBaseURL(client.BaseURI),
   646  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.WindowsIoT/deviceServices/{deviceName}", pathParameters),
   647  		autorest.WithJSON(deviceService),
   648  		autorest.WithQueryParameters(queryParameters))
   649  	if len(ifMatch) > 0 {
   650  		preparer = autorest.DecoratePreparer(preparer,
   651  			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
   652  	}
   653  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   654  }
   655  
   656  // UpdateSender sends the Update request. The method will close the
   657  // http.Response Body if it receives an error.
   658  func (client ServicesClient) UpdateSender(req *http.Request) (*http.Response, error) {
   659  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   660  }
   661  
   662  // UpdateResponder handles the response to the Update request. The method always
   663  // closes the http.Response Body.
   664  func (client ServicesClient) UpdateResponder(resp *http.Response) (result DeviceService, err error) {
   665  	err = autorest.Respond(
   666  		resp,
   667  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   668  		autorest.ByUnmarshallingJSON(&result),
   669  		autorest.ByClosing())
   670  	result.Response = autorest.Response{Response: resp}
   671  	return
   672  }
   673  

View as plain text