...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/dtl/artifact.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/devtestlabs/mgmt/2015-05-21-preview/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  // ArtifactClient is the azure DevTest Labs REST API version 2015-05-21-preview.
    18  type ArtifactClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewArtifactClient creates an instance of the ArtifactClient client.
    23  func NewArtifactClient(subscriptionID string) ArtifactClient {
    24  	return NewArtifactClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewArtifactClientWithBaseURI creates an instance of the ArtifactClient 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).
    29  func NewArtifactClientWithBaseURI(baseURI string, subscriptionID string) ArtifactClient {
    30  	return ArtifactClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // GenerateArmTemplate generates an ARM template for the given artifact, uploads the required files to a storage
    34  // account, and validates the generated artifact.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // labName - the name of the lab.
    38  // artifactSourceName - the name of the artifact source.
    39  // name - the name of the artifact.
    40  func (client ArtifactClient) GenerateArmTemplate(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, generateArmTemplateRequest GenerateArmTemplateRequest) (result ArmTemplateInfo, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.GenerateArmTemplate")
    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  	req, err := client.GenerateArmTemplatePreparer(ctx, resourceGroupName, labName, artifactSourceName, name, generateArmTemplateRequest)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GenerateArmTemplate", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.GenerateArmTemplateSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GenerateArmTemplate", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.GenerateArmTemplateResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GenerateArmTemplate", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // GenerateArmTemplatePreparer prepares the GenerateArmTemplate request.
    74  func (client ArtifactClient) GenerateArmTemplatePreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, generateArmTemplateRequest GenerateArmTemplateRequest) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
    77  		"labName":            autorest.Encode("path", labName),
    78  		"name":               autorest.Encode("path", name),
    79  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
    80  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
    81  	}
    82  
    83  	const APIVersion = "2015-05-21-preview"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  
    88  	preparer := autorest.CreatePreparer(
    89  		autorest.AsContentType("application/json; charset=utf-8"),
    90  		autorest.AsPost(),
    91  		autorest.WithBaseURL(client.BaseURI),
    92  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}/generateArmTemplate", pathParameters),
    93  		autorest.WithJSON(generateArmTemplateRequest),
    94  		autorest.WithQueryParameters(queryParameters))
    95  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    96  }
    97  
    98  // GenerateArmTemplateSender sends the GenerateArmTemplate request. The method will close the
    99  // http.Response Body if it receives an error.
   100  func (client ArtifactClient) GenerateArmTemplateSender(req *http.Request) (*http.Response, error) {
   101  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   102  }
   103  
   104  // GenerateArmTemplateResponder handles the response to the GenerateArmTemplate request. The method always
   105  // closes the http.Response Body.
   106  func (client ArtifactClient) GenerateArmTemplateResponder(resp *http.Response) (result ArmTemplateInfo, err error) {
   107  	err = autorest.Respond(
   108  		resp,
   109  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   110  		autorest.ByUnmarshallingJSON(&result),
   111  		autorest.ByClosing())
   112  	result.Response = autorest.Response{Response: resp}
   113  	return
   114  }
   115  
   116  // GetResource get artifact.
   117  // Parameters:
   118  // resourceGroupName - the name of the resource group.
   119  // labName - the name of the lab.
   120  // artifactSourceName - the name of the artifact source.
   121  // name - the name of the artifact.
   122  func (client ArtifactClient) GetResource(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string) (result Artifact, err error) {
   123  	if tracing.IsEnabled() {
   124  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.GetResource")
   125  		defer func() {
   126  			sc := -1
   127  			if result.Response.Response != nil {
   128  				sc = result.Response.Response.StatusCode
   129  			}
   130  			tracing.EndSpan(ctx, sc, err)
   131  		}()
   132  	}
   133  	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, artifactSourceName, name)
   134  	if err != nil {
   135  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GetResource", nil, "Failure preparing request")
   136  		return
   137  	}
   138  
   139  	resp, err := client.GetResourceSender(req)
   140  	if err != nil {
   141  		result.Response = autorest.Response{Response: resp}
   142  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GetResource", resp, "Failure sending request")
   143  		return
   144  	}
   145  
   146  	result, err = client.GetResourceResponder(resp)
   147  	if err != nil {
   148  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "GetResource", resp, "Failure responding to request")
   149  		return
   150  	}
   151  
   152  	return
   153  }
   154  
   155  // GetResourcePreparer prepares the GetResource request.
   156  func (client ArtifactClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string) (*http.Request, error) {
   157  	pathParameters := map[string]interface{}{
   158  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
   159  		"labName":            autorest.Encode("path", labName),
   160  		"name":               autorest.Encode("path", name),
   161  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   162  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   163  	}
   164  
   165  	const APIVersion = "2015-05-21-preview"
   166  	queryParameters := map[string]interface{}{
   167  		"api-version": APIVersion,
   168  	}
   169  
   170  	preparer := autorest.CreatePreparer(
   171  		autorest.AsGet(),
   172  		autorest.WithBaseURL(client.BaseURI),
   173  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}", pathParameters),
   174  		autorest.WithQueryParameters(queryParameters))
   175  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   176  }
   177  
   178  // GetResourceSender sends the GetResource request. The method will close the
   179  // http.Response Body if it receives an error.
   180  func (client ArtifactClient) GetResourceSender(req *http.Request) (*http.Response, error) {
   181  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   182  }
   183  
   184  // GetResourceResponder handles the response to the GetResource request. The method always
   185  // closes the http.Response Body.
   186  func (client ArtifactClient) GetResourceResponder(resp *http.Response) (result Artifact, err error) {
   187  	err = autorest.Respond(
   188  		resp,
   189  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   190  		autorest.ByUnmarshallingJSON(&result),
   191  		autorest.ByClosing())
   192  	result.Response = autorest.Response{Response: resp}
   193  	return
   194  }
   195  
   196  // List list artifacts.
   197  // Parameters:
   198  // resourceGroupName - the name of the resource group.
   199  // labName - the name of the lab.
   200  // artifactSourceName - the name of the artifact source.
   201  // filter - the filter to apply on the operation.
   202  func (client ArtifactClient) List(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationArtifactPage, err error) {
   203  	if tracing.IsEnabled() {
   204  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.List")
   205  		defer func() {
   206  			sc := -1
   207  			if result.rwca.Response.Response != nil {
   208  				sc = result.rwca.Response.Response.StatusCode
   209  			}
   210  			tracing.EndSpan(ctx, sc, err)
   211  		}()
   212  	}
   213  	result.fn = client.listNextResults
   214  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, artifactSourceName, filter, top, orderBy)
   215  	if err != nil {
   216  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "List", nil, "Failure preparing request")
   217  		return
   218  	}
   219  
   220  	resp, err := client.ListSender(req)
   221  	if err != nil {
   222  		result.rwca.Response = autorest.Response{Response: resp}
   223  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "List", resp, "Failure sending request")
   224  		return
   225  	}
   226  
   227  	result.rwca, err = client.ListResponder(resp)
   228  	if err != nil {
   229  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "List", resp, "Failure responding to request")
   230  		return
   231  	}
   232  	if result.rwca.hasNextLink() && result.rwca.IsEmpty() {
   233  		err = result.NextWithContext(ctx)
   234  		return
   235  	}
   236  
   237  	return
   238  }
   239  
   240  // ListPreparer prepares the List request.
   241  func (client ArtifactClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, filter string, top *int32, orderBy string) (*http.Request, error) {
   242  	pathParameters := map[string]interface{}{
   243  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
   244  		"labName":            autorest.Encode("path", labName),
   245  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   246  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   247  	}
   248  
   249  	const APIVersion = "2015-05-21-preview"
   250  	queryParameters := map[string]interface{}{
   251  		"api-version": APIVersion,
   252  	}
   253  	if len(filter) > 0 {
   254  		queryParameters["$filter"] = autorest.Encode("query", filter)
   255  	}
   256  	if top != nil {
   257  		queryParameters["$top"] = autorest.Encode("query", *top)
   258  	}
   259  	if len(orderBy) > 0 {
   260  		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
   261  	}
   262  
   263  	preparer := autorest.CreatePreparer(
   264  		autorest.AsGet(),
   265  		autorest.WithBaseURL(client.BaseURI),
   266  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts", pathParameters),
   267  		autorest.WithQueryParameters(queryParameters))
   268  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   269  }
   270  
   271  // ListSender sends the List request. The method will close the
   272  // http.Response Body if it receives an error.
   273  func (client ArtifactClient) ListSender(req *http.Request) (*http.Response, error) {
   274  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   275  }
   276  
   277  // ListResponder handles the response to the List request. The method always
   278  // closes the http.Response Body.
   279  func (client ArtifactClient) ListResponder(resp *http.Response) (result ResponseWithContinuationArtifact, err error) {
   280  	err = autorest.Respond(
   281  		resp,
   282  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   283  		autorest.ByUnmarshallingJSON(&result),
   284  		autorest.ByClosing())
   285  	result.Response = autorest.Response{Response: resp}
   286  	return
   287  }
   288  
   289  // listNextResults retrieves the next set of results, if any.
   290  func (client ArtifactClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationArtifact) (result ResponseWithContinuationArtifact, err error) {
   291  	req, err := lastResults.responseWithContinuationArtifactPreparer(ctx)
   292  	if err != nil {
   293  		return result, autorest.NewErrorWithError(err, "dtl.ArtifactClient", "listNextResults", nil, "Failure preparing next results request")
   294  	}
   295  	if req == nil {
   296  		return
   297  	}
   298  	resp, err := client.ListSender(req)
   299  	if err != nil {
   300  		result.Response = autorest.Response{Response: resp}
   301  		return result, autorest.NewErrorWithError(err, "dtl.ArtifactClient", "listNextResults", resp, "Failure sending next results request")
   302  	}
   303  	result, err = client.ListResponder(resp)
   304  	if err != nil {
   305  		err = autorest.NewErrorWithError(err, "dtl.ArtifactClient", "listNextResults", resp, "Failure responding to next results request")
   306  	}
   307  	return
   308  }
   309  
   310  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   311  func (client ArtifactClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationArtifactIterator, err error) {
   312  	if tracing.IsEnabled() {
   313  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactClient.List")
   314  		defer func() {
   315  			sc := -1
   316  			if result.Response().Response.Response != nil {
   317  				sc = result.page.Response().Response.Response.StatusCode
   318  			}
   319  			tracing.EndSpan(ctx, sc, err)
   320  		}()
   321  	}
   322  	result.page, err = client.List(ctx, resourceGroupName, labName, artifactSourceName, filter, top, orderBy)
   323  	return
   324  }
   325  

View as plain text