...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple1200series/mgmt/2016-10-01/storsimple/chapsettings.go

Documentation: github.com/Azure/azure-sdk-for-go/services/storsimple1200series/mgmt/2016-10-01/storsimple

     1  package storsimple
     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  // ChapSettingsClient is the client for the ChapSettings methods of the Storsimple service.
    19  type ChapSettingsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewChapSettingsClient creates an instance of the ChapSettingsClient client.
    24  func NewChapSettingsClient(subscriptionID string) ChapSettingsClient {
    25  	return NewChapSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewChapSettingsClientWithBaseURI creates an instance of the ChapSettingsClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewChapSettingsClientWithBaseURI(baseURI string, subscriptionID string) ChapSettingsClient {
    31  	return ChapSettingsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates the chap setting.
    35  // Parameters:
    36  // deviceName - the device name.
    37  // chapUserName - the chap user name.
    38  // chapSetting - the chap setting to be added or updated.
    39  // resourceGroupName - the resource group name
    40  // managerName - the manager name
    41  func (client ChapSettingsClient) CreateOrUpdate(ctx context.Context, deviceName string, chapUserName string, chapSetting ChapSettings, resourceGroupName string, managerName string) (result ChapSettingsCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ChapSettingsClient.CreateOrUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: chapSetting,
    54  			Constraints: []validation.Constraint{{Target: "chapSetting.ChapProperties", Name: validation.Null, Rule: true,
    55  				Chain: []validation.Constraint{{Target: "chapSetting.ChapProperties.Password", Name: validation.Null, Rule: true,
    56  					Chain: []validation.Constraint{{Target: "chapSetting.ChapProperties.Password.Value", Name: validation.Null, Rule: true, Chain: nil}}},
    57  				}}}},
    58  		{TargetValue: managerName,
    59  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    60  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
    61  		return result, validation.NewError("storsimple.ChapSettingsClient", "CreateOrUpdate", err.Error())
    62  	}
    63  
    64  	req, err := client.CreateOrUpdatePreparer(ctx, deviceName, chapUserName, chapSetting, resourceGroupName, managerName)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "CreateOrUpdate", nil, "Failure preparing request")
    67  		return
    68  	}
    69  
    70  	result, err = client.CreateOrUpdateSender(req)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    73  		return
    74  	}
    75  
    76  	return
    77  }
    78  
    79  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    80  func (client ChapSettingsClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, chapUserName string, chapSetting ChapSettings, resourceGroupName string, managerName string) (*http.Request, error) {
    81  	pathParameters := map[string]interface{}{
    82  		"chapUserName":      autorest.Encode("path", chapUserName),
    83  		"deviceName":        autorest.Encode("path", deviceName),
    84  		"managerName":       autorest.Encode("path", managerName),
    85  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    86  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    87  	}
    88  
    89  	const APIVersion = "2016-10-01"
    90  	queryParameters := map[string]interface{}{
    91  		"api-version": APIVersion,
    92  	}
    93  
    94  	preparer := autorest.CreatePreparer(
    95  		autorest.AsContentType("application/json; charset=utf-8"),
    96  		autorest.AsPut(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/chapSettings/{chapUserName}", pathParameters),
    99  		autorest.WithJSON(chapSetting),
   100  		autorest.WithQueryParameters(queryParameters))
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client ChapSettingsClient) CreateOrUpdateSender(req *http.Request) (future ChapSettingsCreateOrUpdateFuture, err error) {
   107  	var resp *http.Response
   108  	future.FutureAPI = &azure.Future{}
   109  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   110  	if err != nil {
   111  		return
   112  	}
   113  	var azf azure.Future
   114  	azf, err = azure.NewFutureFromResponse(resp)
   115  	future.FutureAPI = &azf
   116  	future.Result = future.result
   117  	return
   118  }
   119  
   120  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   121  // closes the http.Response Body.
   122  func (client ChapSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result ChapSettings, err error) {
   123  	err = autorest.Respond(
   124  		resp,
   125  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   126  		autorest.ByUnmarshallingJSON(&result),
   127  		autorest.ByClosing())
   128  	result.Response = autorest.Response{Response: resp}
   129  	return
   130  }
   131  
   132  // Delete deletes the chap setting.
   133  // Parameters:
   134  // deviceName - the device name.
   135  // chapUserName - the chap user name.
   136  // resourceGroupName - the resource group name
   137  // managerName - the manager name
   138  func (client ChapSettingsClient) Delete(ctx context.Context, deviceName string, chapUserName string, resourceGroupName string, managerName string) (result ChapSettingsDeleteFuture, err error) {
   139  	if tracing.IsEnabled() {
   140  		ctx = tracing.StartSpan(ctx, fqdn+"/ChapSettingsClient.Delete")
   141  		defer func() {
   142  			sc := -1
   143  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   144  				sc = result.FutureAPI.Response().StatusCode
   145  			}
   146  			tracing.EndSpan(ctx, sc, err)
   147  		}()
   148  	}
   149  	if err := validation.Validate([]validation.Validation{
   150  		{TargetValue: managerName,
   151  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   152  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   153  		return result, validation.NewError("storsimple.ChapSettingsClient", "Delete", err.Error())
   154  	}
   155  
   156  	req, err := client.DeletePreparer(ctx, deviceName, chapUserName, resourceGroupName, managerName)
   157  	if err != nil {
   158  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "Delete", nil, "Failure preparing request")
   159  		return
   160  	}
   161  
   162  	result, err = client.DeleteSender(req)
   163  	if err != nil {
   164  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "Delete", result.Response(), "Failure sending request")
   165  		return
   166  	}
   167  
   168  	return
   169  }
   170  
   171  // DeletePreparer prepares the Delete request.
   172  func (client ChapSettingsClient) DeletePreparer(ctx context.Context, deviceName string, chapUserName string, resourceGroupName string, managerName string) (*http.Request, error) {
   173  	pathParameters := map[string]interface{}{
   174  		"chapUserName":      autorest.Encode("path", chapUserName),
   175  		"deviceName":        autorest.Encode("path", deviceName),
   176  		"managerName":       autorest.Encode("path", managerName),
   177  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   178  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   179  	}
   180  
   181  	const APIVersion = "2016-10-01"
   182  	queryParameters := map[string]interface{}{
   183  		"api-version": APIVersion,
   184  	}
   185  
   186  	preparer := autorest.CreatePreparer(
   187  		autorest.AsDelete(),
   188  		autorest.WithBaseURL(client.BaseURI),
   189  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/chapSettings/{chapUserName}", pathParameters),
   190  		autorest.WithQueryParameters(queryParameters))
   191  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   192  }
   193  
   194  // DeleteSender sends the Delete request. The method will close the
   195  // http.Response Body if it receives an error.
   196  func (client ChapSettingsClient) DeleteSender(req *http.Request) (future ChapSettingsDeleteFuture, err error) {
   197  	var resp *http.Response
   198  	future.FutureAPI = &azure.Future{}
   199  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   200  	if err != nil {
   201  		return
   202  	}
   203  	var azf azure.Future
   204  	azf, err = azure.NewFutureFromResponse(resp)
   205  	future.FutureAPI = &azf
   206  	future.Result = future.result
   207  	return
   208  }
   209  
   210  // DeleteResponder handles the response to the Delete request. The method always
   211  // closes the http.Response Body.
   212  func (client ChapSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   213  	err = autorest.Respond(
   214  		resp,
   215  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   216  		autorest.ByClosing())
   217  	result.Response = resp
   218  	return
   219  }
   220  
   221  // Get returns the properties of the specified chap setting name.
   222  // Parameters:
   223  // deviceName - the device name.
   224  // chapUserName - the user name of chap to be fetched.
   225  // resourceGroupName - the resource group name
   226  // managerName - the manager name
   227  func (client ChapSettingsClient) Get(ctx context.Context, deviceName string, chapUserName string, resourceGroupName string, managerName string) (result ChapSettings, err error) {
   228  	if tracing.IsEnabled() {
   229  		ctx = tracing.StartSpan(ctx, fqdn+"/ChapSettingsClient.Get")
   230  		defer func() {
   231  			sc := -1
   232  			if result.Response.Response != nil {
   233  				sc = result.Response.Response.StatusCode
   234  			}
   235  			tracing.EndSpan(ctx, sc, err)
   236  		}()
   237  	}
   238  	if err := validation.Validate([]validation.Validation{
   239  		{TargetValue: managerName,
   240  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   241  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   242  		return result, validation.NewError("storsimple.ChapSettingsClient", "Get", err.Error())
   243  	}
   244  
   245  	req, err := client.GetPreparer(ctx, deviceName, chapUserName, resourceGroupName, managerName)
   246  	if err != nil {
   247  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "Get", nil, "Failure preparing request")
   248  		return
   249  	}
   250  
   251  	resp, err := client.GetSender(req)
   252  	if err != nil {
   253  		result.Response = autorest.Response{Response: resp}
   254  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "Get", resp, "Failure sending request")
   255  		return
   256  	}
   257  
   258  	result, err = client.GetResponder(resp)
   259  	if err != nil {
   260  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "Get", resp, "Failure responding to request")
   261  		return
   262  	}
   263  
   264  	return
   265  }
   266  
   267  // GetPreparer prepares the Get request.
   268  func (client ChapSettingsClient) GetPreparer(ctx context.Context, deviceName string, chapUserName string, resourceGroupName string, managerName string) (*http.Request, error) {
   269  	pathParameters := map[string]interface{}{
   270  		"chapUserName":      autorest.Encode("path", chapUserName),
   271  		"deviceName":        autorest.Encode("path", deviceName),
   272  		"managerName":       autorest.Encode("path", managerName),
   273  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   274  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   275  	}
   276  
   277  	const APIVersion = "2016-10-01"
   278  	queryParameters := map[string]interface{}{
   279  		"api-version": APIVersion,
   280  	}
   281  
   282  	preparer := autorest.CreatePreparer(
   283  		autorest.AsGet(),
   284  		autorest.WithBaseURL(client.BaseURI),
   285  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/chapSettings/{chapUserName}", pathParameters),
   286  		autorest.WithQueryParameters(queryParameters))
   287  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   288  }
   289  
   290  // GetSender sends the Get request. The method will close the
   291  // http.Response Body if it receives an error.
   292  func (client ChapSettingsClient) GetSender(req *http.Request) (*http.Response, error) {
   293  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   294  }
   295  
   296  // GetResponder handles the response to the Get request. The method always
   297  // closes the http.Response Body.
   298  func (client ChapSettingsClient) GetResponder(resp *http.Response) (result ChapSettings, err error) {
   299  	err = autorest.Respond(
   300  		resp,
   301  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   302  		autorest.ByUnmarshallingJSON(&result),
   303  		autorest.ByClosing())
   304  	result.Response = autorest.Response{Response: resp}
   305  	return
   306  }
   307  
   308  // ListByDevice retrieves all the chap settings in a device.
   309  // Parameters:
   310  // deviceName - the name of the device.
   311  // resourceGroupName - the resource group name
   312  // managerName - the manager name
   313  func (client ChapSettingsClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (result ChapSettingsList, err error) {
   314  	if tracing.IsEnabled() {
   315  		ctx = tracing.StartSpan(ctx, fqdn+"/ChapSettingsClient.ListByDevice")
   316  		defer func() {
   317  			sc := -1
   318  			if result.Response.Response != nil {
   319  				sc = result.Response.Response.StatusCode
   320  			}
   321  			tracing.EndSpan(ctx, sc, err)
   322  		}()
   323  	}
   324  	if err := validation.Validate([]validation.Validation{
   325  		{TargetValue: managerName,
   326  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   327  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   328  		return result, validation.NewError("storsimple.ChapSettingsClient", "ListByDevice", err.Error())
   329  	}
   330  
   331  	req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName)
   332  	if err != nil {
   333  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "ListByDevice", nil, "Failure preparing request")
   334  		return
   335  	}
   336  
   337  	resp, err := client.ListByDeviceSender(req)
   338  	if err != nil {
   339  		result.Response = autorest.Response{Response: resp}
   340  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "ListByDevice", resp, "Failure sending request")
   341  		return
   342  	}
   343  
   344  	result, err = client.ListByDeviceResponder(resp)
   345  	if err != nil {
   346  		err = autorest.NewErrorWithError(err, "storsimple.ChapSettingsClient", "ListByDevice", resp, "Failure responding to request")
   347  		return
   348  	}
   349  
   350  	return
   351  }
   352  
   353  // ListByDevicePreparer prepares the ListByDevice request.
   354  func (client ChapSettingsClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (*http.Request, error) {
   355  	pathParameters := map[string]interface{}{
   356  		"deviceName":        autorest.Encode("path", deviceName),
   357  		"managerName":       autorest.Encode("path", managerName),
   358  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   359  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   360  	}
   361  
   362  	const APIVersion = "2016-10-01"
   363  	queryParameters := map[string]interface{}{
   364  		"api-version": APIVersion,
   365  	}
   366  
   367  	preparer := autorest.CreatePreparer(
   368  		autorest.AsGet(),
   369  		autorest.WithBaseURL(client.BaseURI),
   370  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/chapSettings", pathParameters),
   371  		autorest.WithQueryParameters(queryParameters))
   372  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   373  }
   374  
   375  // ListByDeviceSender sends the ListByDevice request. The method will close the
   376  // http.Response Body if it receives an error.
   377  func (client ChapSettingsClient) ListByDeviceSender(req *http.Request) (*http.Response, error) {
   378  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   379  }
   380  
   381  // ListByDeviceResponder handles the response to the ListByDevice request. The method always
   382  // closes the http.Response Body.
   383  func (client ChapSettingsClient) ListByDeviceResponder(resp *http.Response) (result ChapSettingsList, err error) {
   384  	err = autorest.Respond(
   385  		resp,
   386  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   387  		autorest.ByUnmarshallingJSON(&result),
   388  		autorest.ByClosing())
   389  	result.Response = autorest.Response{Response: resp}
   390  	return
   391  }
   392  

View as plain text