...

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

View as plain text