...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-10-01-preview/insights/privatelinkresources.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2022-10-01-preview/insights

     1  package insights
     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  // PrivateLinkResourcesClient is the monitor Management Client
    19  type PrivateLinkResourcesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPrivateLinkResourcesClient creates an instance of the PrivateLinkResourcesClient client.
    24  func NewPrivateLinkResourcesClient(subscriptionID string) PrivateLinkResourcesClient {
    25  	return NewPrivateLinkResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewPrivateLinkResourcesClientWithBaseURI creates an instance of the PrivateLinkResourcesClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewPrivateLinkResourcesClientWithBaseURI(baseURI string, subscriptionID string) PrivateLinkResourcesClient {
    32  	return PrivateLinkResourcesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Get gets the private link resources that need to be created for a Azure Monitor PrivateLinkScope.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
    39  // groupName - the name of the private link resource.
    40  func (client PrivateLinkResourcesClient) Get(ctx context.Context, resourceGroupName string, scopeName string, groupName string) (result PrivateLinkResource, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.Get")
    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: client.SubscriptionID,
    53  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    54  		{TargetValue: resourceGroupName,
    55  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    57  		return result, validation.NewError("insights.PrivateLinkResourcesClient", "Get", err.Error())
    58  	}
    59  
    60  	req, err := client.GetPreparer(ctx, resourceGroupName, scopeName, groupName)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "Get", nil, "Failure preparing request")
    63  		return
    64  	}
    65  
    66  	resp, err := client.GetSender(req)
    67  	if err != nil {
    68  		result.Response = autorest.Response{Response: resp}
    69  		err = autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "Get", resp, "Failure sending request")
    70  		return
    71  	}
    72  
    73  	result, err = client.GetResponder(resp)
    74  	if err != nil {
    75  		err = autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "Get", resp, "Failure responding to request")
    76  		return
    77  	}
    78  
    79  	return
    80  }
    81  
    82  // GetPreparer prepares the Get request.
    83  func (client PrivateLinkResourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, scopeName string, groupName string) (*http.Request, error) {
    84  	pathParameters := map[string]interface{}{
    85  		"groupName":         autorest.Encode("path", groupName),
    86  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    87  		"scopeName":         autorest.Encode("path", scopeName),
    88  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    89  	}
    90  
    91  	const APIVersion = "2019-10-17-preview"
    92  	queryParameters := map[string]interface{}{
    93  		"api-version": APIVersion,
    94  	}
    95  
    96  	preparer := autorest.CreatePreparer(
    97  		autorest.AsGet(),
    98  		autorest.WithBaseURL(client.BaseURI),
    99  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/privateLinkResources/{groupName}", pathParameters),
   100  		autorest.WithQueryParameters(queryParameters))
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // GetSender sends the Get request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client PrivateLinkResourcesClient) GetSender(req *http.Request) (*http.Response, error) {
   107  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   108  }
   109  
   110  // GetResponder handles the response to the Get request. The method always
   111  // closes the http.Response Body.
   112  func (client PrivateLinkResourcesClient) GetResponder(resp *http.Response) (result PrivateLinkResource, err error) {
   113  	err = autorest.Respond(
   114  		resp,
   115  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   116  		autorest.ByUnmarshallingJSON(&result),
   117  		autorest.ByClosing())
   118  	result.Response = autorest.Response{Response: resp}
   119  	return
   120  }
   121  
   122  // ListByPrivateLinkScope gets the private link resources that need to be created for a Azure Monitor PrivateLinkScope.
   123  // Parameters:
   124  // resourceGroupName - the name of the resource group. The name is case insensitive.
   125  // scopeName - the name of the Azure Monitor PrivateLinkScope resource.
   126  func (client PrivateLinkResourcesClient) ListByPrivateLinkScope(ctx context.Context, resourceGroupName string, scopeName string) (result PrivateLinkResourceListResultPage, err error) {
   127  	if tracing.IsEnabled() {
   128  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.ListByPrivateLinkScope")
   129  		defer func() {
   130  			sc := -1
   131  			if result.plrlr.Response.Response != nil {
   132  				sc = result.plrlr.Response.Response.StatusCode
   133  			}
   134  			tracing.EndSpan(ctx, sc, err)
   135  		}()
   136  	}
   137  	if err := validation.Validate([]validation.Validation{
   138  		{TargetValue: client.SubscriptionID,
   139  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   140  		{TargetValue: resourceGroupName,
   141  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   142  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   143  		return result, validation.NewError("insights.PrivateLinkResourcesClient", "ListByPrivateLinkScope", err.Error())
   144  	}
   145  
   146  	result.fn = client.listByPrivateLinkScopeNextResults
   147  	req, err := client.ListByPrivateLinkScopePreparer(ctx, resourceGroupName, scopeName)
   148  	if err != nil {
   149  		err = autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "ListByPrivateLinkScope", nil, "Failure preparing request")
   150  		return
   151  	}
   152  
   153  	resp, err := client.ListByPrivateLinkScopeSender(req)
   154  	if err != nil {
   155  		result.plrlr.Response = autorest.Response{Response: resp}
   156  		err = autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "ListByPrivateLinkScope", resp, "Failure sending request")
   157  		return
   158  	}
   159  
   160  	result.plrlr, err = client.ListByPrivateLinkScopeResponder(resp)
   161  	if err != nil {
   162  		err = autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "ListByPrivateLinkScope", resp, "Failure responding to request")
   163  		return
   164  	}
   165  	if result.plrlr.hasNextLink() && result.plrlr.IsEmpty() {
   166  		err = result.NextWithContext(ctx)
   167  		return
   168  	}
   169  
   170  	return
   171  }
   172  
   173  // ListByPrivateLinkScopePreparer prepares the ListByPrivateLinkScope request.
   174  func (client PrivateLinkResourcesClient) ListByPrivateLinkScopePreparer(ctx context.Context, resourceGroupName string, scopeName string) (*http.Request, error) {
   175  	pathParameters := map[string]interface{}{
   176  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   177  		"scopeName":         autorest.Encode("path", scopeName),
   178  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   179  	}
   180  
   181  	const APIVersion = "2019-10-17-preview"
   182  	queryParameters := map[string]interface{}{
   183  		"api-version": APIVersion,
   184  	}
   185  
   186  	preparer := autorest.CreatePreparer(
   187  		autorest.AsGet(),
   188  		autorest.WithBaseURL(client.BaseURI),
   189  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/privateLinkScopes/{scopeName}/privateLinkResources", pathParameters),
   190  		autorest.WithQueryParameters(queryParameters))
   191  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   192  }
   193  
   194  // ListByPrivateLinkScopeSender sends the ListByPrivateLinkScope request. The method will close the
   195  // http.Response Body if it receives an error.
   196  func (client PrivateLinkResourcesClient) ListByPrivateLinkScopeSender(req *http.Request) (*http.Response, error) {
   197  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   198  }
   199  
   200  // ListByPrivateLinkScopeResponder handles the response to the ListByPrivateLinkScope request. The method always
   201  // closes the http.Response Body.
   202  func (client PrivateLinkResourcesClient) ListByPrivateLinkScopeResponder(resp *http.Response) (result PrivateLinkResourceListResult, err error) {
   203  	err = autorest.Respond(
   204  		resp,
   205  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   206  		autorest.ByUnmarshallingJSON(&result),
   207  		autorest.ByClosing())
   208  	result.Response = autorest.Response{Response: resp}
   209  	return
   210  }
   211  
   212  // listByPrivateLinkScopeNextResults retrieves the next set of results, if any.
   213  func (client PrivateLinkResourcesClient) listByPrivateLinkScopeNextResults(ctx context.Context, lastResults PrivateLinkResourceListResult) (result PrivateLinkResourceListResult, err error) {
   214  	req, err := lastResults.privateLinkResourceListResultPreparer(ctx)
   215  	if err != nil {
   216  		return result, autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "listByPrivateLinkScopeNextResults", nil, "Failure preparing next results request")
   217  	}
   218  	if req == nil {
   219  		return
   220  	}
   221  	resp, err := client.ListByPrivateLinkScopeSender(req)
   222  	if err != nil {
   223  		result.Response = autorest.Response{Response: resp}
   224  		return result, autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "listByPrivateLinkScopeNextResults", resp, "Failure sending next results request")
   225  	}
   226  	result, err = client.ListByPrivateLinkScopeResponder(resp)
   227  	if err != nil {
   228  		err = autorest.NewErrorWithError(err, "insights.PrivateLinkResourcesClient", "listByPrivateLinkScopeNextResults", resp, "Failure responding to next results request")
   229  	}
   230  	return
   231  }
   232  
   233  // ListByPrivateLinkScopeComplete enumerates all values, automatically crossing page boundaries as required.
   234  func (client PrivateLinkResourcesClient) ListByPrivateLinkScopeComplete(ctx context.Context, resourceGroupName string, scopeName string) (result PrivateLinkResourceListResultIterator, err error) {
   235  	if tracing.IsEnabled() {
   236  		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateLinkResourcesClient.ListByPrivateLinkScope")
   237  		defer func() {
   238  			sc := -1
   239  			if result.Response().Response.Response != nil {
   240  				sc = result.page.Response().Response.Response.StatusCode
   241  			}
   242  			tracing.EndSpan(ctx, sc, err)
   243  		}()
   244  	}
   245  	result.page, err = client.ListByPrivateLinkScope(ctx, resourceGroupName, scopeName)
   246  	return
   247  }
   248  

View as plain text