...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/servicemap/ports.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/servicemap

     1  package servicemap
     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/date"
    14  	"github.com/Azure/go-autorest/autorest/validation"
    15  	"github.com/Azure/go-autorest/tracing"
    16  	"net/http"
    17  )
    18  
    19  // PortsClient is the service Map API Reference
    20  type PortsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewPortsClient creates an instance of the PortsClient client.
    25  func NewPortsClient(subscriptionID string) PortsClient {
    26  	return NewPortsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewPortsClientWithBaseURI creates an instance of the PortsClient client using a custom endpoint.  Use this when
    30  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewPortsClientWithBaseURI(baseURI string, subscriptionID string) PortsClient {
    32  	return PortsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Get returns the specified port. The port must be live during the specified time interval. If the port is not live
    36  // during the interval, status 404 (Not Found) is returned.
    37  // Parameters:
    38  // resourceGroupName - resource group name within the specified subscriptionId.
    39  // workspaceName - OMS workspace containing the resources of interest.
    40  // machineName - machine resource name.
    41  // portName - port resource name.
    42  // startTime - UTC date and time specifying the start time of an interval. When not specified the service uses
    43  // DateTime.UtcNow - 10m
    44  // endTime - UTC date and time specifying the end time of an interval. When not specified the service uses
    45  // DateTime.UtcNow
    46  func (client PortsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (result Port, err error) {
    47  	if tracing.IsEnabled() {
    48  		ctx = tracing.StartSpan(ctx, fqdn+"/PortsClient.Get")
    49  		defer func() {
    50  			sc := -1
    51  			if result.Response.Response != nil {
    52  				sc = result.Response.Response.StatusCode
    53  			}
    54  			tracing.EndSpan(ctx, sc, err)
    55  		}()
    56  	}
    57  	if err := validation.Validate([]validation.Validation{
    58  		{TargetValue: resourceGroupName,
    59  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
    60  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    61  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_-]+`, Chain: nil}}},
    62  		{TargetValue: workspaceName,
    63  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
    64  				{Target: "workspaceName", Name: validation.MinLength, Rule: 3, Chain: nil},
    65  				{Target: "workspaceName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_][a-zA-Z0-9_-]+[a-zA-Z0-9_]`, Chain: nil}}},
    66  		{TargetValue: machineName,
    67  			Constraints: []validation.Constraint{{Target: "machineName", Name: validation.MaxLength, Rule: 64, Chain: nil},
    68  				{Target: "machineName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
    69  		{TargetValue: portName,
    70  			Constraints: []validation.Constraint{{Target: "portName", Name: validation.MaxLength, Rule: 64, Chain: nil},
    71  				{Target: "portName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
    72  		return result, validation.NewError("servicemap.PortsClient", "Get", err.Error())
    73  	}
    74  
    75  	req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, machineName, portName, startTime, endTime)
    76  	if err != nil {
    77  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "Get", nil, "Failure preparing request")
    78  		return
    79  	}
    80  
    81  	resp, err := client.GetSender(req)
    82  	if err != nil {
    83  		result.Response = autorest.Response{Response: resp}
    84  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "Get", resp, "Failure sending request")
    85  		return
    86  	}
    87  
    88  	result, err = client.GetResponder(resp)
    89  	if err != nil {
    90  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "Get", resp, "Failure responding to request")
    91  		return
    92  	}
    93  
    94  	return
    95  }
    96  
    97  // GetPreparer prepares the Get request.
    98  func (client PortsClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (*http.Request, error) {
    99  	pathParameters := map[string]interface{}{
   100  		"machineName":       autorest.Encode("path", machineName),
   101  		"portName":          autorest.Encode("path", portName),
   102  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   103  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   104  		"workspaceName":     autorest.Encode("path", workspaceName),
   105  	}
   106  
   107  	const APIVersion = "2015-11-01-preview"
   108  	queryParameters := map[string]interface{}{
   109  		"api-version": APIVersion,
   110  	}
   111  	if startTime != nil {
   112  		queryParameters["startTime"] = autorest.Encode("query", *startTime)
   113  	}
   114  	if endTime != nil {
   115  		queryParameters["endTime"] = autorest.Encode("query", *endTime)
   116  	}
   117  
   118  	preparer := autorest.CreatePreparer(
   119  		autorest.AsGet(),
   120  		autorest.WithBaseURL(client.BaseURI),
   121  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/features/serviceMap/machines/{machineName}/ports/{portName}", pathParameters),
   122  		autorest.WithQueryParameters(queryParameters))
   123  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   124  }
   125  
   126  // GetSender sends the Get request. The method will close the
   127  // http.Response Body if it receives an error.
   128  func (client PortsClient) GetSender(req *http.Request) (*http.Response, error) {
   129  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   130  }
   131  
   132  // GetResponder handles the response to the Get request. The method always
   133  // closes the http.Response Body.
   134  func (client PortsClient) GetResponder(resp *http.Response) (result Port, err error) {
   135  	err = autorest.Respond(
   136  		resp,
   137  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   138  		autorest.ByUnmarshallingJSON(&result),
   139  		autorest.ByClosing())
   140  	result.Response = autorest.Response{Response: resp}
   141  	return
   142  }
   143  
   144  // GetLiveness obtains the liveness status of the port during the specified time interval.
   145  // Parameters:
   146  // resourceGroupName - resource group name within the specified subscriptionId.
   147  // workspaceName - OMS workspace containing the resources of interest.
   148  // machineName - machine resource name.
   149  // portName - port resource name.
   150  // startTime - UTC date and time specifying the start time of an interval. When not specified the service uses
   151  // DateTime.UtcNow - 10m
   152  // endTime - UTC date and time specifying the end time of an interval. When not specified the service uses
   153  // DateTime.UtcNow
   154  func (client PortsClient) GetLiveness(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (result Liveness, err error) {
   155  	if tracing.IsEnabled() {
   156  		ctx = tracing.StartSpan(ctx, fqdn+"/PortsClient.GetLiveness")
   157  		defer func() {
   158  			sc := -1
   159  			if result.Response.Response != nil {
   160  				sc = result.Response.Response.StatusCode
   161  			}
   162  			tracing.EndSpan(ctx, sc, err)
   163  		}()
   164  	}
   165  	if err := validation.Validate([]validation.Validation{
   166  		{TargetValue: resourceGroupName,
   167  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   168  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   169  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_-]+`, Chain: nil}}},
   170  		{TargetValue: workspaceName,
   171  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
   172  				{Target: "workspaceName", Name: validation.MinLength, Rule: 3, Chain: nil},
   173  				{Target: "workspaceName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_][a-zA-Z0-9_-]+[a-zA-Z0-9_]`, Chain: nil}}},
   174  		{TargetValue: machineName,
   175  			Constraints: []validation.Constraint{{Target: "machineName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   176  				{Target: "machineName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
   177  		{TargetValue: portName,
   178  			Constraints: []validation.Constraint{{Target: "portName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   179  				{Target: "portName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
   180  		return result, validation.NewError("servicemap.PortsClient", "GetLiveness", err.Error())
   181  	}
   182  
   183  	req, err := client.GetLivenessPreparer(ctx, resourceGroupName, workspaceName, machineName, portName, startTime, endTime)
   184  	if err != nil {
   185  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "GetLiveness", nil, "Failure preparing request")
   186  		return
   187  	}
   188  
   189  	resp, err := client.GetLivenessSender(req)
   190  	if err != nil {
   191  		result.Response = autorest.Response{Response: resp}
   192  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "GetLiveness", resp, "Failure sending request")
   193  		return
   194  	}
   195  
   196  	result, err = client.GetLivenessResponder(resp)
   197  	if err != nil {
   198  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "GetLiveness", resp, "Failure responding to request")
   199  		return
   200  	}
   201  
   202  	return
   203  }
   204  
   205  // GetLivenessPreparer prepares the GetLiveness request.
   206  func (client PortsClient) GetLivenessPreparer(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (*http.Request, error) {
   207  	pathParameters := map[string]interface{}{
   208  		"machineName":       autorest.Encode("path", machineName),
   209  		"portName":          autorest.Encode("path", portName),
   210  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   211  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   212  		"workspaceName":     autorest.Encode("path", workspaceName),
   213  	}
   214  
   215  	const APIVersion = "2015-11-01-preview"
   216  	queryParameters := map[string]interface{}{
   217  		"api-version": APIVersion,
   218  	}
   219  	if startTime != nil {
   220  		queryParameters["startTime"] = autorest.Encode("query", *startTime)
   221  	}
   222  	if endTime != nil {
   223  		queryParameters["endTime"] = autorest.Encode("query", *endTime)
   224  	}
   225  
   226  	preparer := autorest.CreatePreparer(
   227  		autorest.AsGet(),
   228  		autorest.WithBaseURL(client.BaseURI),
   229  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/features/serviceMap/machines/{machineName}/ports/{portName}/liveness", pathParameters),
   230  		autorest.WithQueryParameters(queryParameters))
   231  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   232  }
   233  
   234  // GetLivenessSender sends the GetLiveness request. The method will close the
   235  // http.Response Body if it receives an error.
   236  func (client PortsClient) GetLivenessSender(req *http.Request) (*http.Response, error) {
   237  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   238  }
   239  
   240  // GetLivenessResponder handles the response to the GetLiveness request. The method always
   241  // closes the http.Response Body.
   242  func (client PortsClient) GetLivenessResponder(resp *http.Response) (result Liveness, err error) {
   243  	err = autorest.Respond(
   244  		resp,
   245  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   246  		autorest.ByUnmarshallingJSON(&result),
   247  		autorest.ByClosing())
   248  	result.Response = autorest.Response{Response: resp}
   249  	return
   250  }
   251  
   252  // ListAcceptingProcesses returns a collection of processes accepting on the specified port
   253  // Parameters:
   254  // resourceGroupName - resource group name within the specified subscriptionId.
   255  // workspaceName - OMS workspace containing the resources of interest.
   256  // machineName - machine resource name.
   257  // portName - port resource name.
   258  // startTime - UTC date and time specifying the start time of an interval. When not specified the service uses
   259  // DateTime.UtcNow - 10m
   260  // endTime - UTC date and time specifying the end time of an interval. When not specified the service uses
   261  // DateTime.UtcNow
   262  func (client PortsClient) ListAcceptingProcesses(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (result ProcessCollectionPage, err error) {
   263  	if tracing.IsEnabled() {
   264  		ctx = tracing.StartSpan(ctx, fqdn+"/PortsClient.ListAcceptingProcesses")
   265  		defer func() {
   266  			sc := -1
   267  			if result.pc.Response.Response != nil {
   268  				sc = result.pc.Response.Response.StatusCode
   269  			}
   270  			tracing.EndSpan(ctx, sc, err)
   271  		}()
   272  	}
   273  	if err := validation.Validate([]validation.Validation{
   274  		{TargetValue: resourceGroupName,
   275  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   276  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   277  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_-]+`, Chain: nil}}},
   278  		{TargetValue: workspaceName,
   279  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
   280  				{Target: "workspaceName", Name: validation.MinLength, Rule: 3, Chain: nil},
   281  				{Target: "workspaceName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_][a-zA-Z0-9_-]+[a-zA-Z0-9_]`, Chain: nil}}},
   282  		{TargetValue: machineName,
   283  			Constraints: []validation.Constraint{{Target: "machineName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   284  				{Target: "machineName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
   285  		{TargetValue: portName,
   286  			Constraints: []validation.Constraint{{Target: "portName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   287  				{Target: "portName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
   288  		return result, validation.NewError("servicemap.PortsClient", "ListAcceptingProcesses", err.Error())
   289  	}
   290  
   291  	result.fn = client.listAcceptingProcessesNextResults
   292  	req, err := client.ListAcceptingProcessesPreparer(ctx, resourceGroupName, workspaceName, machineName, portName, startTime, endTime)
   293  	if err != nil {
   294  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "ListAcceptingProcesses", nil, "Failure preparing request")
   295  		return
   296  	}
   297  
   298  	resp, err := client.ListAcceptingProcessesSender(req)
   299  	if err != nil {
   300  		result.pc.Response = autorest.Response{Response: resp}
   301  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "ListAcceptingProcesses", resp, "Failure sending request")
   302  		return
   303  	}
   304  
   305  	result.pc, err = client.ListAcceptingProcessesResponder(resp)
   306  	if err != nil {
   307  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "ListAcceptingProcesses", resp, "Failure responding to request")
   308  		return
   309  	}
   310  	if result.pc.hasNextLink() && result.pc.IsEmpty() {
   311  		err = result.NextWithContext(ctx)
   312  		return
   313  	}
   314  
   315  	return
   316  }
   317  
   318  // ListAcceptingProcessesPreparer prepares the ListAcceptingProcesses request.
   319  func (client PortsClient) ListAcceptingProcessesPreparer(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (*http.Request, error) {
   320  	pathParameters := map[string]interface{}{
   321  		"machineName":       autorest.Encode("path", machineName),
   322  		"portName":          autorest.Encode("path", portName),
   323  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   324  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   325  		"workspaceName":     autorest.Encode("path", workspaceName),
   326  	}
   327  
   328  	const APIVersion = "2015-11-01-preview"
   329  	queryParameters := map[string]interface{}{
   330  		"api-version": APIVersion,
   331  	}
   332  	if startTime != nil {
   333  		queryParameters["startTime"] = autorest.Encode("query", *startTime)
   334  	}
   335  	if endTime != nil {
   336  		queryParameters["endTime"] = autorest.Encode("query", *endTime)
   337  	}
   338  
   339  	preparer := autorest.CreatePreparer(
   340  		autorest.AsGet(),
   341  		autorest.WithBaseURL(client.BaseURI),
   342  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/features/serviceMap/machines/{machineName}/ports/{portName}/acceptingProcesses", pathParameters),
   343  		autorest.WithQueryParameters(queryParameters))
   344  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   345  }
   346  
   347  // ListAcceptingProcessesSender sends the ListAcceptingProcesses request. The method will close the
   348  // http.Response Body if it receives an error.
   349  func (client PortsClient) ListAcceptingProcessesSender(req *http.Request) (*http.Response, error) {
   350  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   351  }
   352  
   353  // ListAcceptingProcessesResponder handles the response to the ListAcceptingProcesses request. The method always
   354  // closes the http.Response Body.
   355  func (client PortsClient) ListAcceptingProcessesResponder(resp *http.Response) (result ProcessCollection, err error) {
   356  	err = autorest.Respond(
   357  		resp,
   358  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   359  		autorest.ByUnmarshallingJSON(&result),
   360  		autorest.ByClosing())
   361  	result.Response = autorest.Response{Response: resp}
   362  	return
   363  }
   364  
   365  // listAcceptingProcessesNextResults retrieves the next set of results, if any.
   366  func (client PortsClient) listAcceptingProcessesNextResults(ctx context.Context, lastResults ProcessCollection) (result ProcessCollection, err error) {
   367  	req, err := lastResults.processCollectionPreparer(ctx)
   368  	if err != nil {
   369  		return result, autorest.NewErrorWithError(err, "servicemap.PortsClient", "listAcceptingProcessesNextResults", nil, "Failure preparing next results request")
   370  	}
   371  	if req == nil {
   372  		return
   373  	}
   374  	resp, err := client.ListAcceptingProcessesSender(req)
   375  	if err != nil {
   376  		result.Response = autorest.Response{Response: resp}
   377  		return result, autorest.NewErrorWithError(err, "servicemap.PortsClient", "listAcceptingProcessesNextResults", resp, "Failure sending next results request")
   378  	}
   379  	result, err = client.ListAcceptingProcessesResponder(resp)
   380  	if err != nil {
   381  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "listAcceptingProcessesNextResults", resp, "Failure responding to next results request")
   382  	}
   383  	return
   384  }
   385  
   386  // ListAcceptingProcessesComplete enumerates all values, automatically crossing page boundaries as required.
   387  func (client PortsClient) ListAcceptingProcessesComplete(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (result ProcessCollectionIterator, err error) {
   388  	if tracing.IsEnabled() {
   389  		ctx = tracing.StartSpan(ctx, fqdn+"/PortsClient.ListAcceptingProcesses")
   390  		defer func() {
   391  			sc := -1
   392  			if result.Response().Response.Response != nil {
   393  				sc = result.page.Response().Response.Response.StatusCode
   394  			}
   395  			tracing.EndSpan(ctx, sc, err)
   396  		}()
   397  	}
   398  	result.page, err = client.ListAcceptingProcesses(ctx, resourceGroupName, workspaceName, machineName, portName, startTime, endTime)
   399  	return
   400  }
   401  
   402  // ListConnections returns a collection of connections established via the specified port.
   403  // Parameters:
   404  // resourceGroupName - resource group name within the specified subscriptionId.
   405  // workspaceName - OMS workspace containing the resources of interest.
   406  // machineName - machine resource name.
   407  // portName - port resource name.
   408  // startTime - UTC date and time specifying the start time of an interval. When not specified the service uses
   409  // DateTime.UtcNow - 10m
   410  // endTime - UTC date and time specifying the end time of an interval. When not specified the service uses
   411  // DateTime.UtcNow
   412  func (client PortsClient) ListConnections(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (result ConnectionCollectionPage, err error) {
   413  	if tracing.IsEnabled() {
   414  		ctx = tracing.StartSpan(ctx, fqdn+"/PortsClient.ListConnections")
   415  		defer func() {
   416  			sc := -1
   417  			if result.cc.Response.Response != nil {
   418  				sc = result.cc.Response.Response.StatusCode
   419  			}
   420  			tracing.EndSpan(ctx, sc, err)
   421  		}()
   422  	}
   423  	if err := validation.Validate([]validation.Validation{
   424  		{TargetValue: resourceGroupName,
   425  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   426  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   427  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_-]+`, Chain: nil}}},
   428  		{TargetValue: workspaceName,
   429  			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
   430  				{Target: "workspaceName", Name: validation.MinLength, Rule: 3, Chain: nil},
   431  				{Target: "workspaceName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_][a-zA-Z0-9_-]+[a-zA-Z0-9_]`, Chain: nil}}},
   432  		{TargetValue: machineName,
   433  			Constraints: []validation.Constraint{{Target: "machineName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   434  				{Target: "machineName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
   435  		{TargetValue: portName,
   436  			Constraints: []validation.Constraint{{Target: "portName", Name: validation.MaxLength, Rule: 64, Chain: nil},
   437  				{Target: "portName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil {
   438  		return result, validation.NewError("servicemap.PortsClient", "ListConnections", err.Error())
   439  	}
   440  
   441  	result.fn = client.listConnectionsNextResults
   442  	req, err := client.ListConnectionsPreparer(ctx, resourceGroupName, workspaceName, machineName, portName, startTime, endTime)
   443  	if err != nil {
   444  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "ListConnections", nil, "Failure preparing request")
   445  		return
   446  	}
   447  
   448  	resp, err := client.ListConnectionsSender(req)
   449  	if err != nil {
   450  		result.cc.Response = autorest.Response{Response: resp}
   451  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "ListConnections", resp, "Failure sending request")
   452  		return
   453  	}
   454  
   455  	result.cc, err = client.ListConnectionsResponder(resp)
   456  	if err != nil {
   457  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "ListConnections", resp, "Failure responding to request")
   458  		return
   459  	}
   460  	if result.cc.hasNextLink() && result.cc.IsEmpty() {
   461  		err = result.NextWithContext(ctx)
   462  		return
   463  	}
   464  
   465  	return
   466  }
   467  
   468  // ListConnectionsPreparer prepares the ListConnections request.
   469  func (client PortsClient) ListConnectionsPreparer(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (*http.Request, error) {
   470  	pathParameters := map[string]interface{}{
   471  		"machineName":       autorest.Encode("path", machineName),
   472  		"portName":          autorest.Encode("path", portName),
   473  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   474  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   475  		"workspaceName":     autorest.Encode("path", workspaceName),
   476  	}
   477  
   478  	const APIVersion = "2015-11-01-preview"
   479  	queryParameters := map[string]interface{}{
   480  		"api-version": APIVersion,
   481  	}
   482  	if startTime != nil {
   483  		queryParameters["startTime"] = autorest.Encode("query", *startTime)
   484  	}
   485  	if endTime != nil {
   486  		queryParameters["endTime"] = autorest.Encode("query", *endTime)
   487  	}
   488  
   489  	preparer := autorest.CreatePreparer(
   490  		autorest.AsGet(),
   491  		autorest.WithBaseURL(client.BaseURI),
   492  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/features/serviceMap/machines/{machineName}/ports/{portName}/connections", pathParameters),
   493  		autorest.WithQueryParameters(queryParameters))
   494  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   495  }
   496  
   497  // ListConnectionsSender sends the ListConnections request. The method will close the
   498  // http.Response Body if it receives an error.
   499  func (client PortsClient) ListConnectionsSender(req *http.Request) (*http.Response, error) {
   500  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   501  }
   502  
   503  // ListConnectionsResponder handles the response to the ListConnections request. The method always
   504  // closes the http.Response Body.
   505  func (client PortsClient) ListConnectionsResponder(resp *http.Response) (result ConnectionCollection, err error) {
   506  	err = autorest.Respond(
   507  		resp,
   508  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   509  		autorest.ByUnmarshallingJSON(&result),
   510  		autorest.ByClosing())
   511  	result.Response = autorest.Response{Response: resp}
   512  	return
   513  }
   514  
   515  // listConnectionsNextResults retrieves the next set of results, if any.
   516  func (client PortsClient) listConnectionsNextResults(ctx context.Context, lastResults ConnectionCollection) (result ConnectionCollection, err error) {
   517  	req, err := lastResults.connectionCollectionPreparer(ctx)
   518  	if err != nil {
   519  		return result, autorest.NewErrorWithError(err, "servicemap.PortsClient", "listConnectionsNextResults", nil, "Failure preparing next results request")
   520  	}
   521  	if req == nil {
   522  		return
   523  	}
   524  	resp, err := client.ListConnectionsSender(req)
   525  	if err != nil {
   526  		result.Response = autorest.Response{Response: resp}
   527  		return result, autorest.NewErrorWithError(err, "servicemap.PortsClient", "listConnectionsNextResults", resp, "Failure sending next results request")
   528  	}
   529  	result, err = client.ListConnectionsResponder(resp)
   530  	if err != nil {
   531  		err = autorest.NewErrorWithError(err, "servicemap.PortsClient", "listConnectionsNextResults", resp, "Failure responding to next results request")
   532  	}
   533  	return
   534  }
   535  
   536  // ListConnectionsComplete enumerates all values, automatically crossing page boundaries as required.
   537  func (client PortsClient) ListConnectionsComplete(ctx context.Context, resourceGroupName string, workspaceName string, machineName string, portName string, startTime *date.Time, endTime *date.Time) (result ConnectionCollectionIterator, err error) {
   538  	if tracing.IsEnabled() {
   539  		ctx = tracing.StartSpan(ctx, fqdn+"/PortsClient.ListConnections")
   540  		defer func() {
   541  			sc := -1
   542  			if result.Response().Response.Response != nil {
   543  				sc = result.page.Response().Response.Response.StatusCode
   544  			}
   545  			tracing.EndSpan(ctx, sc, err)
   546  		}()
   547  	}
   548  	result.page, err = client.ListConnections(ctx, resourceGroupName, workspaceName, machineName, portName, startTime, endTime)
   549  	return
   550  }
   551  

View as plain text