...

Source file src/github.com/Azure/azure-sdk-for-go/services/hybriddatamanager/mgmt/2019-06-01/hybriddata/publickeys.go

Documentation: github.com/Azure/azure-sdk-for-go/services/hybriddatamanager/mgmt/2019-06-01/hybriddata

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

View as plain text