...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl/artifacts.go

Documentation: github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-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  // ArtifactsClient is the the DevTest Labs Client.
    18  type ArtifactsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewArtifactsClient creates an instance of the ArtifactsClient client.
    23  func NewArtifactsClient(subscriptionID string) ArtifactsClient {
    24  	return NewArtifactsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewArtifactsClientWithBaseURI creates an instance of the ArtifactsClient 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 NewArtifactsClientWithBaseURI(baseURI string, subscriptionID string) ArtifactsClient {
    30  	return ArtifactsClient{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  // generateArmTemplateRequest - parameters for generating an ARM template for deploying artifacts.
    41  func (client ArtifactsClient) GenerateArmTemplate(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, generateArmTemplateRequest GenerateArmTemplateRequest) (result ArmTemplateInfo, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.GenerateArmTemplate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	req, err := client.GenerateArmTemplatePreparer(ctx, resourceGroupName, labName, artifactSourceName, name, generateArmTemplateRequest)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "GenerateArmTemplate", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	resp, err := client.GenerateArmTemplateSender(req)
    59  	if err != nil {
    60  		result.Response = autorest.Response{Response: resp}
    61  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "GenerateArmTemplate", resp, "Failure sending request")
    62  		return
    63  	}
    64  
    65  	result, err = client.GenerateArmTemplateResponder(resp)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "GenerateArmTemplate", resp, "Failure responding to request")
    68  		return
    69  	}
    70  
    71  	return
    72  }
    73  
    74  // GenerateArmTemplatePreparer prepares the GenerateArmTemplate request.
    75  func (client ArtifactsClient) GenerateArmTemplatePreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, generateArmTemplateRequest GenerateArmTemplateRequest) (*http.Request, error) {
    76  	pathParameters := map[string]interface{}{
    77  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
    78  		"labName":            autorest.Encode("path", labName),
    79  		"name":               autorest.Encode("path", name),
    80  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
    81  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
    82  	}
    83  
    84  	const APIVersion = "2018-09-15"
    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}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}/generateArmTemplate", pathParameters),
    94  		autorest.WithJSON(generateArmTemplateRequest),
    95  		autorest.WithQueryParameters(queryParameters))
    96  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    97  }
    98  
    99  // GenerateArmTemplateSender sends the GenerateArmTemplate request. The method will close the
   100  // http.Response Body if it receives an error.
   101  func (client ArtifactsClient) GenerateArmTemplateSender(req *http.Request) (*http.Response, error) {
   102  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  }
   104  
   105  // GenerateArmTemplateResponder handles the response to the GenerateArmTemplate request. The method always
   106  // closes the http.Response Body.
   107  func (client ArtifactsClient) GenerateArmTemplateResponder(resp *http.Response) (result ArmTemplateInfo, 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  // Get get artifact.
   118  // Parameters:
   119  // resourceGroupName - the name of the resource group.
   120  // labName - the name of the lab.
   121  // artifactSourceName - the name of the artifact source.
   122  // name - the name of the artifact.
   123  // expand - specify the $expand query. Example: 'properties($select=title)'
   124  func (client ArtifactsClient) Get(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, expand string) (result Artifact, err error) {
   125  	if tracing.IsEnabled() {
   126  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.Get")
   127  		defer func() {
   128  			sc := -1
   129  			if result.Response.Response != nil {
   130  				sc = result.Response.Response.StatusCode
   131  			}
   132  			tracing.EndSpan(ctx, sc, err)
   133  		}()
   134  	}
   135  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, artifactSourceName, name, expand)
   136  	if err != nil {
   137  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "Get", nil, "Failure preparing request")
   138  		return
   139  	}
   140  
   141  	resp, err := client.GetSender(req)
   142  	if err != nil {
   143  		result.Response = autorest.Response{Response: resp}
   144  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "Get", resp, "Failure sending request")
   145  		return
   146  	}
   147  
   148  	result, err = client.GetResponder(resp)
   149  	if err != nil {
   150  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "Get", resp, "Failure responding to request")
   151  		return
   152  	}
   153  
   154  	return
   155  }
   156  
   157  // GetPreparer prepares the Get request.
   158  func (client ArtifactsClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, name string, expand string) (*http.Request, error) {
   159  	pathParameters := map[string]interface{}{
   160  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
   161  		"labName":            autorest.Encode("path", labName),
   162  		"name":               autorest.Encode("path", name),
   163  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   164  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   165  	}
   166  
   167  	const APIVersion = "2018-09-15"
   168  	queryParameters := map[string]interface{}{
   169  		"api-version": APIVersion,
   170  	}
   171  	if len(expand) > 0 {
   172  		queryParameters["$expand"] = autorest.Encode("query", expand)
   173  	}
   174  
   175  	preparer := autorest.CreatePreparer(
   176  		autorest.AsGet(),
   177  		autorest.WithBaseURL(client.BaseURI),
   178  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}", pathParameters),
   179  		autorest.WithQueryParameters(queryParameters))
   180  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   181  }
   182  
   183  // GetSender sends the Get request. The method will close the
   184  // http.Response Body if it receives an error.
   185  func (client ArtifactsClient) GetSender(req *http.Request) (*http.Response, error) {
   186  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   187  }
   188  
   189  // GetResponder handles the response to the Get request. The method always
   190  // closes the http.Response Body.
   191  func (client ArtifactsClient) GetResponder(resp *http.Response) (result Artifact, err error) {
   192  	err = autorest.Respond(
   193  		resp,
   194  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   195  		autorest.ByUnmarshallingJSON(&result),
   196  		autorest.ByClosing())
   197  	result.Response = autorest.Response{Response: resp}
   198  	return
   199  }
   200  
   201  // List list artifacts in a given artifact source.
   202  // Parameters:
   203  // resourceGroupName - the name of the resource group.
   204  // labName - the name of the lab.
   205  // artifactSourceName - the name of the artifact source.
   206  // expand - specify the $expand query. Example: 'properties($select=title)'
   207  // filter - the filter to apply to the operation. Example: '$filter=contains(name,'myName')
   208  // top - the maximum number of resources to return from the operation. Example: '$top=10'
   209  // orderby - the ordering expression for the results, using OData notation. Example: '$orderby=name desc'
   210  func (client ArtifactsClient) List(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, expand string, filter string, top *int32, orderby string) (result ArtifactListPage, err error) {
   211  	if tracing.IsEnabled() {
   212  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.List")
   213  		defer func() {
   214  			sc := -1
   215  			if result.al.Response.Response != nil {
   216  				sc = result.al.Response.Response.StatusCode
   217  			}
   218  			tracing.EndSpan(ctx, sc, err)
   219  		}()
   220  	}
   221  	result.fn = client.listNextResults
   222  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, artifactSourceName, expand, filter, top, orderby)
   223  	if err != nil {
   224  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "List", nil, "Failure preparing request")
   225  		return
   226  	}
   227  
   228  	resp, err := client.ListSender(req)
   229  	if err != nil {
   230  		result.al.Response = autorest.Response{Response: resp}
   231  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "List", resp, "Failure sending request")
   232  		return
   233  	}
   234  
   235  	result.al, err = client.ListResponder(resp)
   236  	if err != nil {
   237  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "List", resp, "Failure responding to request")
   238  		return
   239  	}
   240  	if result.al.hasNextLink() && result.al.IsEmpty() {
   241  		err = result.NextWithContext(ctx)
   242  		return
   243  	}
   244  
   245  	return
   246  }
   247  
   248  // ListPreparer prepares the List request.
   249  func (client ArtifactsClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   250  	pathParameters := map[string]interface{}{
   251  		"artifactSourceName": autorest.Encode("path", artifactSourceName),
   252  		"labName":            autorest.Encode("path", labName),
   253  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   254  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   255  	}
   256  
   257  	const APIVersion = "2018-09-15"
   258  	queryParameters := map[string]interface{}{
   259  		"api-version": APIVersion,
   260  	}
   261  	if len(expand) > 0 {
   262  		queryParameters["$expand"] = autorest.Encode("query", expand)
   263  	}
   264  	if len(filter) > 0 {
   265  		queryParameters["$filter"] = autorest.Encode("query", filter)
   266  	}
   267  	if top != nil {
   268  		queryParameters["$top"] = autorest.Encode("query", *top)
   269  	}
   270  	if len(orderby) > 0 {
   271  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   272  	}
   273  
   274  	preparer := autorest.CreatePreparer(
   275  		autorest.AsGet(),
   276  		autorest.WithBaseURL(client.BaseURI),
   277  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts", pathParameters),
   278  		autorest.WithQueryParameters(queryParameters))
   279  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   280  }
   281  
   282  // ListSender sends the List request. The method will close the
   283  // http.Response Body if it receives an error.
   284  func (client ArtifactsClient) ListSender(req *http.Request) (*http.Response, error) {
   285  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   286  }
   287  
   288  // ListResponder handles the response to the List request. The method always
   289  // closes the http.Response Body.
   290  func (client ArtifactsClient) ListResponder(resp *http.Response) (result ArtifactList, err error) {
   291  	err = autorest.Respond(
   292  		resp,
   293  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   294  		autorest.ByUnmarshallingJSON(&result),
   295  		autorest.ByClosing())
   296  	result.Response = autorest.Response{Response: resp}
   297  	return
   298  }
   299  
   300  // listNextResults retrieves the next set of results, if any.
   301  func (client ArtifactsClient) listNextResults(ctx context.Context, lastResults ArtifactList) (result ArtifactList, err error) {
   302  	req, err := lastResults.artifactListPreparer(ctx)
   303  	if err != nil {
   304  		return result, autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "listNextResults", nil, "Failure preparing next results request")
   305  	}
   306  	if req == nil {
   307  		return
   308  	}
   309  	resp, err := client.ListSender(req)
   310  	if err != nil {
   311  		result.Response = autorest.Response{Response: resp}
   312  		return result, autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "listNextResults", resp, "Failure sending next results request")
   313  	}
   314  	result, err = client.ListResponder(resp)
   315  	if err != nil {
   316  		err = autorest.NewErrorWithError(err, "dtl.ArtifactsClient", "listNextResults", resp, "Failure responding to next results request")
   317  	}
   318  	return
   319  }
   320  
   321  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   322  func (client ArtifactsClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, artifactSourceName string, expand string, filter string, top *int32, orderby string) (result ArtifactListIterator, err error) {
   323  	if tracing.IsEnabled() {
   324  		ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.List")
   325  		defer func() {
   326  			sc := -1
   327  			if result.Response().Response.Response != nil {
   328  				sc = result.page.Response().Response.Response.StatusCode
   329  			}
   330  			tracing.EndSpan(ctx, sc, err)
   331  		}()
   332  	}
   333  	result.page, err = client.List(ctx, resourceGroupName, labName, artifactSourceName, expand, filter, top, orderby)
   334  	return
   335  }
   336  

View as plain text