...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl/users.go

Documentation: github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl

     1  package dtl
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // UsersClient is the the DevTest Labs Client.
    18  type UsersClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewUsersClient creates an instance of the UsersClient client.
    23  func NewUsersClient(subscriptionID string) UsersClient {
    24  	return NewUsersClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewUsersClientWithBaseURI creates an instance of the UsersClient 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).
    29  func NewUsersClientWithBaseURI(baseURI string, subscriptionID string) UsersClient {
    30  	return UsersClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate create or replace an existing user profile.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // labName - the name of the lab.
    37  // name - the name of the user profile.
    38  // userParameter - profile of a lab user.
    39  func (client UsersClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, userParameter User) (result User, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.CreateOrUpdate")
    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  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, userParameter)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	resp, err := client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		result.Response = autorest.Response{Response: resp}
    59  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "CreateOrUpdate", resp, "Failure sending request")
    60  		return
    61  	}
    62  
    63  	result, err = client.CreateOrUpdateResponder(resp)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "CreateOrUpdate", resp, "Failure responding to request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client UsersClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, userParameter User) (*http.Request, error) {
    74  	pathParameters := map[string]interface{}{
    75  		"labName":           autorest.Encode("path", labName),
    76  		"name":              autorest.Encode("path", name),
    77  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    78  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    79  	}
    80  
    81  	const APIVersion = "2016-05-15"
    82  	queryParameters := map[string]interface{}{
    83  		"api-version": APIVersion,
    84  	}
    85  
    86  	preparer := autorest.CreatePreparer(
    87  		autorest.AsContentType("application/json; charset=utf-8"),
    88  		autorest.AsPut(),
    89  		autorest.WithBaseURL(client.BaseURI),
    90  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}", pathParameters),
    91  		autorest.WithJSON(userParameter),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client UsersClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
    99  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   100  }
   101  
   102  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   103  // closes the http.Response Body.
   104  func (client UsersClient) CreateOrUpdateResponder(resp *http.Response) (result User, err error) {
   105  	err = autorest.Respond(
   106  		resp,
   107  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   108  		autorest.ByUnmarshallingJSON(&result),
   109  		autorest.ByClosing())
   110  	result.Response = autorest.Response{Response: resp}
   111  	return
   112  }
   113  
   114  // Delete delete user profile. This operation can take a while to complete.
   115  // Parameters:
   116  // resourceGroupName - the name of the resource group.
   117  // labName - the name of the lab.
   118  // name - the name of the user profile.
   119  func (client UsersClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result UsersDeleteFuture, err error) {
   120  	if tracing.IsEnabled() {
   121  		ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.Delete")
   122  		defer func() {
   123  			sc := -1
   124  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   125  				sc = result.FutureAPI.Response().StatusCode
   126  			}
   127  			tracing.EndSpan(ctx, sc, err)
   128  		}()
   129  	}
   130  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
   131  	if err != nil {
   132  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Delete", nil, "Failure preparing request")
   133  		return
   134  	}
   135  
   136  	result, err = client.DeleteSender(req)
   137  	if err != nil {
   138  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Delete", result.Response(), "Failure sending request")
   139  		return
   140  	}
   141  
   142  	return
   143  }
   144  
   145  // DeletePreparer prepares the Delete request.
   146  func (client UsersClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   147  	pathParameters := map[string]interface{}{
   148  		"labName":           autorest.Encode("path", labName),
   149  		"name":              autorest.Encode("path", name),
   150  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   151  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   152  	}
   153  
   154  	const APIVersion = "2016-05-15"
   155  	queryParameters := map[string]interface{}{
   156  		"api-version": APIVersion,
   157  	}
   158  
   159  	preparer := autorest.CreatePreparer(
   160  		autorest.AsDelete(),
   161  		autorest.WithBaseURL(client.BaseURI),
   162  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}", pathParameters),
   163  		autorest.WithQueryParameters(queryParameters))
   164  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   165  }
   166  
   167  // DeleteSender sends the Delete request. The method will close the
   168  // http.Response Body if it receives an error.
   169  func (client UsersClient) DeleteSender(req *http.Request) (future UsersDeleteFuture, err error) {
   170  	var resp *http.Response
   171  	future.FutureAPI = &azure.Future{}
   172  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   173  	if err != nil {
   174  		return
   175  	}
   176  	var azf azure.Future
   177  	azf, err = azure.NewFutureFromResponse(resp)
   178  	future.FutureAPI = &azf
   179  	future.Result = future.result
   180  	return
   181  }
   182  
   183  // DeleteResponder handles the response to the Delete request. The method always
   184  // closes the http.Response Body.
   185  func (client UsersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   186  	err = autorest.Respond(
   187  		resp,
   188  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   189  		autorest.ByClosing())
   190  	result.Response = resp
   191  	return
   192  }
   193  
   194  // Get get user profile.
   195  // Parameters:
   196  // resourceGroupName - the name of the resource group.
   197  // labName - the name of the lab.
   198  // name - the name of the user profile.
   199  // expand - specify the $expand query. Example: 'properties($select=identity)'
   200  func (client UsersClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result User, err error) {
   201  	if tracing.IsEnabled() {
   202  		ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.Get")
   203  		defer func() {
   204  			sc := -1
   205  			if result.Response.Response != nil {
   206  				sc = result.Response.Response.StatusCode
   207  			}
   208  			tracing.EndSpan(ctx, sc, err)
   209  		}()
   210  	}
   211  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
   212  	if err != nil {
   213  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Get", nil, "Failure preparing request")
   214  		return
   215  	}
   216  
   217  	resp, err := client.GetSender(req)
   218  	if err != nil {
   219  		result.Response = autorest.Response{Response: resp}
   220  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Get", resp, "Failure sending request")
   221  		return
   222  	}
   223  
   224  	result, err = client.GetResponder(resp)
   225  	if err != nil {
   226  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Get", resp, "Failure responding to request")
   227  		return
   228  	}
   229  
   230  	return
   231  }
   232  
   233  // GetPreparer prepares the Get request.
   234  func (client UsersClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
   235  	pathParameters := map[string]interface{}{
   236  		"labName":           autorest.Encode("path", labName),
   237  		"name":              autorest.Encode("path", name),
   238  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   239  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   240  	}
   241  
   242  	const APIVersion = "2016-05-15"
   243  	queryParameters := map[string]interface{}{
   244  		"api-version": APIVersion,
   245  	}
   246  	if len(expand) > 0 {
   247  		queryParameters["$expand"] = autorest.Encode("query", expand)
   248  	}
   249  
   250  	preparer := autorest.CreatePreparer(
   251  		autorest.AsGet(),
   252  		autorest.WithBaseURL(client.BaseURI),
   253  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}", pathParameters),
   254  		autorest.WithQueryParameters(queryParameters))
   255  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   256  }
   257  
   258  // GetSender sends the Get request. The method will close the
   259  // http.Response Body if it receives an error.
   260  func (client UsersClient) GetSender(req *http.Request) (*http.Response, error) {
   261  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   262  }
   263  
   264  // GetResponder handles the response to the Get request. The method always
   265  // closes the http.Response Body.
   266  func (client UsersClient) GetResponder(resp *http.Response) (result User, err error) {
   267  	err = autorest.Respond(
   268  		resp,
   269  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   270  		autorest.ByUnmarshallingJSON(&result),
   271  		autorest.ByClosing())
   272  	result.Response = autorest.Response{Response: resp}
   273  	return
   274  }
   275  
   276  // List list user profiles in a given lab.
   277  // Parameters:
   278  // resourceGroupName - the name of the resource group.
   279  // labName - the name of the lab.
   280  // expand - specify the $expand query. Example: 'properties($select=identity)'
   281  // filter - the filter to apply to the operation.
   282  // top - the maximum number of resources to return from the operation.
   283  // orderby - the ordering expression for the results, using OData notation.
   284  func (client UsersClient) List(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationUserPage, err error) {
   285  	if tracing.IsEnabled() {
   286  		ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.List")
   287  		defer func() {
   288  			sc := -1
   289  			if result.rwcu.Response.Response != nil {
   290  				sc = result.rwcu.Response.Response.StatusCode
   291  			}
   292  			tracing.EndSpan(ctx, sc, err)
   293  		}()
   294  	}
   295  	result.fn = client.listNextResults
   296  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   297  	if err != nil {
   298  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "List", nil, "Failure preparing request")
   299  		return
   300  	}
   301  
   302  	resp, err := client.ListSender(req)
   303  	if err != nil {
   304  		result.rwcu.Response = autorest.Response{Response: resp}
   305  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "List", resp, "Failure sending request")
   306  		return
   307  	}
   308  
   309  	result.rwcu, err = client.ListResponder(resp)
   310  	if err != nil {
   311  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "List", resp, "Failure responding to request")
   312  		return
   313  	}
   314  	if result.rwcu.hasNextLink() && result.rwcu.IsEmpty() {
   315  		err = result.NextWithContext(ctx)
   316  		return
   317  	}
   318  
   319  	return
   320  }
   321  
   322  // ListPreparer prepares the List request.
   323  func (client UsersClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   324  	pathParameters := map[string]interface{}{
   325  		"labName":           autorest.Encode("path", labName),
   326  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   327  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   328  	}
   329  
   330  	const APIVersion = "2016-05-15"
   331  	queryParameters := map[string]interface{}{
   332  		"api-version": APIVersion,
   333  	}
   334  	if len(expand) > 0 {
   335  		queryParameters["$expand"] = autorest.Encode("query", expand)
   336  	}
   337  	if len(filter) > 0 {
   338  		queryParameters["$filter"] = autorest.Encode("query", filter)
   339  	}
   340  	if top != nil {
   341  		queryParameters["$top"] = autorest.Encode("query", *top)
   342  	}
   343  	if len(orderby) > 0 {
   344  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   345  	}
   346  
   347  	preparer := autorest.CreatePreparer(
   348  		autorest.AsGet(),
   349  		autorest.WithBaseURL(client.BaseURI),
   350  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users", pathParameters),
   351  		autorest.WithQueryParameters(queryParameters))
   352  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   353  }
   354  
   355  // ListSender sends the List request. The method will close the
   356  // http.Response Body if it receives an error.
   357  func (client UsersClient) ListSender(req *http.Request) (*http.Response, error) {
   358  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   359  }
   360  
   361  // ListResponder handles the response to the List request. The method always
   362  // closes the http.Response Body.
   363  func (client UsersClient) ListResponder(resp *http.Response) (result ResponseWithContinuationUser, err error) {
   364  	err = autorest.Respond(
   365  		resp,
   366  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   367  		autorest.ByUnmarshallingJSON(&result),
   368  		autorest.ByClosing())
   369  	result.Response = autorest.Response{Response: resp}
   370  	return
   371  }
   372  
   373  // listNextResults retrieves the next set of results, if any.
   374  func (client UsersClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationUser) (result ResponseWithContinuationUser, err error) {
   375  	req, err := lastResults.responseWithContinuationUserPreparer(ctx)
   376  	if err != nil {
   377  		return result, autorest.NewErrorWithError(err, "dtl.UsersClient", "listNextResults", nil, "Failure preparing next results request")
   378  	}
   379  	if req == nil {
   380  		return
   381  	}
   382  	resp, err := client.ListSender(req)
   383  	if err != nil {
   384  		result.Response = autorest.Response{Response: resp}
   385  		return result, autorest.NewErrorWithError(err, "dtl.UsersClient", "listNextResults", resp, "Failure sending next results request")
   386  	}
   387  	result, err = client.ListResponder(resp)
   388  	if err != nil {
   389  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "listNextResults", resp, "Failure responding to next results request")
   390  	}
   391  	return
   392  }
   393  
   394  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   395  func (client UsersClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationUserIterator, err error) {
   396  	if tracing.IsEnabled() {
   397  		ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.List")
   398  		defer func() {
   399  			sc := -1
   400  			if result.Response().Response.Response != nil {
   401  				sc = result.page.Response().Response.Response.StatusCode
   402  			}
   403  			tracing.EndSpan(ctx, sc, err)
   404  		}()
   405  	}
   406  	result.page, err = client.List(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   407  	return
   408  }
   409  
   410  // Update modify properties of user profiles.
   411  // Parameters:
   412  // resourceGroupName - the name of the resource group.
   413  // labName - the name of the lab.
   414  // name - the name of the user profile.
   415  // userParameter - profile of a lab user.
   416  func (client UsersClient) Update(ctx context.Context, resourceGroupName string, labName string, name string, userParameter UserFragment) (result User, err error) {
   417  	if tracing.IsEnabled() {
   418  		ctx = tracing.StartSpan(ctx, fqdn+"/UsersClient.Update")
   419  		defer func() {
   420  			sc := -1
   421  			if result.Response.Response != nil {
   422  				sc = result.Response.Response.StatusCode
   423  			}
   424  			tracing.EndSpan(ctx, sc, err)
   425  		}()
   426  	}
   427  	req, err := client.UpdatePreparer(ctx, resourceGroupName, labName, name, userParameter)
   428  	if err != nil {
   429  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Update", nil, "Failure preparing request")
   430  		return
   431  	}
   432  
   433  	resp, err := client.UpdateSender(req)
   434  	if err != nil {
   435  		result.Response = autorest.Response{Response: resp}
   436  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Update", resp, "Failure sending request")
   437  		return
   438  	}
   439  
   440  	result, err = client.UpdateResponder(resp)
   441  	if err != nil {
   442  		err = autorest.NewErrorWithError(err, "dtl.UsersClient", "Update", resp, "Failure responding to request")
   443  		return
   444  	}
   445  
   446  	return
   447  }
   448  
   449  // UpdatePreparer prepares the Update request.
   450  func (client UsersClient) UpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, userParameter UserFragment) (*http.Request, error) {
   451  	pathParameters := map[string]interface{}{
   452  		"labName":           autorest.Encode("path", labName),
   453  		"name":              autorest.Encode("path", name),
   454  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   455  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   456  	}
   457  
   458  	const APIVersion = "2016-05-15"
   459  	queryParameters := map[string]interface{}{
   460  		"api-version": APIVersion,
   461  	}
   462  
   463  	preparer := autorest.CreatePreparer(
   464  		autorest.AsContentType("application/json; charset=utf-8"),
   465  		autorest.AsPatch(),
   466  		autorest.WithBaseURL(client.BaseURI),
   467  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}", pathParameters),
   468  		autorest.WithJSON(userParameter),
   469  		autorest.WithQueryParameters(queryParameters))
   470  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   471  }
   472  
   473  // UpdateSender sends the Update request. The method will close the
   474  // http.Response Body if it receives an error.
   475  func (client UsersClient) UpdateSender(req *http.Request) (*http.Response, error) {
   476  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   477  }
   478  
   479  // UpdateResponder handles the response to the Update request. The method always
   480  // closes the http.Response Body.
   481  func (client UsersClient) UpdateResponder(resp *http.Response) (result User, err error) {
   482  	err = autorest.Respond(
   483  		resp,
   484  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   485  		autorest.ByUnmarshallingJSON(&result),
   486  		autorest.ByClosing())
   487  	result.Response = autorest.Response{Response: resp}
   488  	return
   489  }
   490  

View as plain text