...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb/notebookworkspaces.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2021-04-01-preview/documentdb

     1  package documentdb
     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  // NotebookWorkspacesClient is the client for the NotebookWorkspaces methods of the Documentdb service.
    19  type NotebookWorkspacesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewNotebookWorkspacesClient creates an instance of the NotebookWorkspacesClient client.
    24  func NewNotebookWorkspacesClient(subscriptionID string) NotebookWorkspacesClient {
    25  	return NewNotebookWorkspacesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewNotebookWorkspacesClientWithBaseURI creates an instance of the NotebookWorkspacesClient 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 NewNotebookWorkspacesClientWithBaseURI(baseURI string, subscriptionID string) NotebookWorkspacesClient {
    32  	return NotebookWorkspacesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates the notebook workspace for a Cosmos DB account.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // accountName - cosmos DB database account name.
    39  // notebookCreateUpdateParameters - the notebook workspace to create for the current database account.
    40  func (client NotebookWorkspacesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, accountName string, notebookCreateUpdateParameters NotebookWorkspaceCreateUpdateParameters) (result NotebookWorkspacesCreateOrUpdateFuture, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/NotebookWorkspacesClient.CreateOrUpdate")
    43  		defer func() {
    44  			sc := -1
    45  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    46  				sc = result.FutureAPI.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},
    57  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    58  		{TargetValue: accountName,
    59  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    60  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
    61  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
    62  		return result, validation.NewError("documentdb.NotebookWorkspacesClient", "CreateOrUpdate", err.Error())
    63  	}
    64  
    65  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, accountName, notebookCreateUpdateParameters)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "CreateOrUpdate", nil, "Failure preparing request")
    68  		return
    69  	}
    70  
    71  	result, err = client.CreateOrUpdateSender(req)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    81  func (client NotebookWorkspacesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, notebookCreateUpdateParameters NotebookWorkspaceCreateUpdateParameters) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"accountName":           autorest.Encode("path", accountName),
    84  		"notebookWorkspaceName": autorest.Encode("path", "default"),
    85  		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
    86  		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
    87  	}
    88  
    89  	const APIVersion = "2021-04-01-preview"
    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.DocumentDB/databaseAccounts/{accountName}/notebookWorkspaces/{notebookWorkspaceName}", pathParameters),
    99  		autorest.WithJSON(notebookCreateUpdateParameters),
   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 NotebookWorkspacesClient) CreateOrUpdateSender(req *http.Request) (future NotebookWorkspacesCreateOrUpdateFuture, 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 NotebookWorkspacesClient) CreateOrUpdateResponder(resp *http.Response) (result NotebookWorkspace, err error) {
   123  	err = autorest.Respond(
   124  		resp,
   125  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   126  		autorest.ByUnmarshallingJSON(&result),
   127  		autorest.ByClosing())
   128  	result.Response = autorest.Response{Response: resp}
   129  	return
   130  }
   131  
   132  // Delete deletes the notebook workspace for a Cosmos DB account.
   133  // Parameters:
   134  // resourceGroupName - the name of the resource group. The name is case insensitive.
   135  // accountName - cosmos DB database account name.
   136  func (client NotebookWorkspacesClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result NotebookWorkspacesDeleteFuture, err error) {
   137  	if tracing.IsEnabled() {
   138  		ctx = tracing.StartSpan(ctx, fqdn+"/NotebookWorkspacesClient.Delete")
   139  		defer func() {
   140  			sc := -1
   141  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   142  				sc = result.FutureAPI.Response().StatusCode
   143  			}
   144  			tracing.EndSpan(ctx, sc, err)
   145  		}()
   146  	}
   147  	if err := validation.Validate([]validation.Validation{
   148  		{TargetValue: client.SubscriptionID,
   149  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   150  		{TargetValue: resourceGroupName,
   151  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   152  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   153  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   154  		{TargetValue: accountName,
   155  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   156  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   157  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   158  		return result, validation.NewError("documentdb.NotebookWorkspacesClient", "Delete", err.Error())
   159  	}
   160  
   161  	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "Delete", nil, "Failure preparing request")
   164  		return
   165  	}
   166  
   167  	result, err = client.DeleteSender(req)
   168  	if err != nil {
   169  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "Delete", result.Response(), "Failure sending request")
   170  		return
   171  	}
   172  
   173  	return
   174  }
   175  
   176  // DeletePreparer prepares the Delete request.
   177  func (client NotebookWorkspacesClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   178  	pathParameters := map[string]interface{}{
   179  		"accountName":           autorest.Encode("path", accountName),
   180  		"notebookWorkspaceName": autorest.Encode("path", "default"),
   181  		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
   182  		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
   183  	}
   184  
   185  	const APIVersion = "2021-04-01-preview"
   186  	queryParameters := map[string]interface{}{
   187  		"api-version": APIVersion,
   188  	}
   189  
   190  	preparer := autorest.CreatePreparer(
   191  		autorest.AsDelete(),
   192  		autorest.WithBaseURL(client.BaseURI),
   193  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/notebookWorkspaces/{notebookWorkspaceName}", pathParameters),
   194  		autorest.WithQueryParameters(queryParameters))
   195  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   196  }
   197  
   198  // DeleteSender sends the Delete request. The method will close the
   199  // http.Response Body if it receives an error.
   200  func (client NotebookWorkspacesClient) DeleteSender(req *http.Request) (future NotebookWorkspacesDeleteFuture, err error) {
   201  	var resp *http.Response
   202  	future.FutureAPI = &azure.Future{}
   203  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   204  	if err != nil {
   205  		return
   206  	}
   207  	var azf azure.Future
   208  	azf, err = azure.NewFutureFromResponse(resp)
   209  	future.FutureAPI = &azf
   210  	future.Result = future.result
   211  	return
   212  }
   213  
   214  // DeleteResponder handles the response to the Delete request. The method always
   215  // closes the http.Response Body.
   216  func (client NotebookWorkspacesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   217  	err = autorest.Respond(
   218  		resp,
   219  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   220  		autorest.ByClosing())
   221  	result.Response = resp
   222  	return
   223  }
   224  
   225  // Get gets the notebook workspace for a Cosmos DB account.
   226  // Parameters:
   227  // resourceGroupName - the name of the resource group. The name is case insensitive.
   228  // accountName - cosmos DB database account name.
   229  func (client NotebookWorkspacesClient) Get(ctx context.Context, resourceGroupName string, accountName string) (result NotebookWorkspace, err error) {
   230  	if tracing.IsEnabled() {
   231  		ctx = tracing.StartSpan(ctx, fqdn+"/NotebookWorkspacesClient.Get")
   232  		defer func() {
   233  			sc := -1
   234  			if result.Response.Response != nil {
   235  				sc = result.Response.Response.StatusCode
   236  			}
   237  			tracing.EndSpan(ctx, sc, err)
   238  		}()
   239  	}
   240  	if err := validation.Validate([]validation.Validation{
   241  		{TargetValue: client.SubscriptionID,
   242  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   243  		{TargetValue: resourceGroupName,
   244  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   245  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   246  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   247  		{TargetValue: accountName,
   248  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   249  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   250  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   251  		return result, validation.NewError("documentdb.NotebookWorkspacesClient", "Get", err.Error())
   252  	}
   253  
   254  	req, err := client.GetPreparer(ctx, resourceGroupName, accountName)
   255  	if err != nil {
   256  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "Get", nil, "Failure preparing request")
   257  		return
   258  	}
   259  
   260  	resp, err := client.GetSender(req)
   261  	if err != nil {
   262  		result.Response = autorest.Response{Response: resp}
   263  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "Get", resp, "Failure sending request")
   264  		return
   265  	}
   266  
   267  	result, err = client.GetResponder(resp)
   268  	if err != nil {
   269  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "Get", resp, "Failure responding to request")
   270  		return
   271  	}
   272  
   273  	return
   274  }
   275  
   276  // GetPreparer prepares the Get request.
   277  func (client NotebookWorkspacesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   278  	pathParameters := map[string]interface{}{
   279  		"accountName":           autorest.Encode("path", accountName),
   280  		"notebookWorkspaceName": autorest.Encode("path", "default"),
   281  		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
   282  		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
   283  	}
   284  
   285  	const APIVersion = "2021-04-01-preview"
   286  	queryParameters := map[string]interface{}{
   287  		"api-version": APIVersion,
   288  	}
   289  
   290  	preparer := autorest.CreatePreparer(
   291  		autorest.AsGet(),
   292  		autorest.WithBaseURL(client.BaseURI),
   293  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/notebookWorkspaces/{notebookWorkspaceName}", pathParameters),
   294  		autorest.WithQueryParameters(queryParameters))
   295  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   296  }
   297  
   298  // GetSender sends the Get request. The method will close the
   299  // http.Response Body if it receives an error.
   300  func (client NotebookWorkspacesClient) GetSender(req *http.Request) (*http.Response, error) {
   301  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   302  }
   303  
   304  // GetResponder handles the response to the Get request. The method always
   305  // closes the http.Response Body.
   306  func (client NotebookWorkspacesClient) GetResponder(resp *http.Response) (result NotebookWorkspace, err error) {
   307  	err = autorest.Respond(
   308  		resp,
   309  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   310  		autorest.ByUnmarshallingJSON(&result),
   311  		autorest.ByClosing())
   312  	result.Response = autorest.Response{Response: resp}
   313  	return
   314  }
   315  
   316  // ListByDatabaseAccount gets the notebook workspace resources of an existing Cosmos DB account.
   317  // Parameters:
   318  // resourceGroupName - the name of the resource group. The name is case insensitive.
   319  // accountName - cosmos DB database account name.
   320  func (client NotebookWorkspacesClient) ListByDatabaseAccount(ctx context.Context, resourceGroupName string, accountName string) (result NotebookWorkspaceListResult, err error) {
   321  	if tracing.IsEnabled() {
   322  		ctx = tracing.StartSpan(ctx, fqdn+"/NotebookWorkspacesClient.ListByDatabaseAccount")
   323  		defer func() {
   324  			sc := -1
   325  			if result.Response.Response != nil {
   326  				sc = result.Response.Response.StatusCode
   327  			}
   328  			tracing.EndSpan(ctx, sc, err)
   329  		}()
   330  	}
   331  	if err := validation.Validate([]validation.Validation{
   332  		{TargetValue: client.SubscriptionID,
   333  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   334  		{TargetValue: resourceGroupName,
   335  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   336  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   337  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   338  		{TargetValue: accountName,
   339  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   340  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   341  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   342  		return result, validation.NewError("documentdb.NotebookWorkspacesClient", "ListByDatabaseAccount", err.Error())
   343  	}
   344  
   345  	req, err := client.ListByDatabaseAccountPreparer(ctx, resourceGroupName, accountName)
   346  	if err != nil {
   347  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "ListByDatabaseAccount", nil, "Failure preparing request")
   348  		return
   349  	}
   350  
   351  	resp, err := client.ListByDatabaseAccountSender(req)
   352  	if err != nil {
   353  		result.Response = autorest.Response{Response: resp}
   354  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "ListByDatabaseAccount", resp, "Failure sending request")
   355  		return
   356  	}
   357  
   358  	result, err = client.ListByDatabaseAccountResponder(resp)
   359  	if err != nil {
   360  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "ListByDatabaseAccount", resp, "Failure responding to request")
   361  		return
   362  	}
   363  
   364  	return
   365  }
   366  
   367  // ListByDatabaseAccountPreparer prepares the ListByDatabaseAccount request.
   368  func (client NotebookWorkspacesClient) ListByDatabaseAccountPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   369  	pathParameters := map[string]interface{}{
   370  		"accountName":       autorest.Encode("path", accountName),
   371  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   372  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   373  	}
   374  
   375  	const APIVersion = "2021-04-01-preview"
   376  	queryParameters := map[string]interface{}{
   377  		"api-version": APIVersion,
   378  	}
   379  
   380  	preparer := autorest.CreatePreparer(
   381  		autorest.AsGet(),
   382  		autorest.WithBaseURL(client.BaseURI),
   383  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/notebookWorkspaces", pathParameters),
   384  		autorest.WithQueryParameters(queryParameters))
   385  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   386  }
   387  
   388  // ListByDatabaseAccountSender sends the ListByDatabaseAccount request. The method will close the
   389  // http.Response Body if it receives an error.
   390  func (client NotebookWorkspacesClient) ListByDatabaseAccountSender(req *http.Request) (*http.Response, error) {
   391  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   392  }
   393  
   394  // ListByDatabaseAccountResponder handles the response to the ListByDatabaseAccount request. The method always
   395  // closes the http.Response Body.
   396  func (client NotebookWorkspacesClient) ListByDatabaseAccountResponder(resp *http.Response) (result NotebookWorkspaceListResult, err error) {
   397  	err = autorest.Respond(
   398  		resp,
   399  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   400  		autorest.ByUnmarshallingJSON(&result),
   401  		autorest.ByClosing())
   402  	result.Response = autorest.Response{Response: resp}
   403  	return
   404  }
   405  
   406  // ListConnectionInfo retrieves the connection info for the notebook workspace
   407  // Parameters:
   408  // resourceGroupName - the name of the resource group. The name is case insensitive.
   409  // accountName - cosmos DB database account name.
   410  func (client NotebookWorkspacesClient) ListConnectionInfo(ctx context.Context, resourceGroupName string, accountName string) (result NotebookWorkspaceConnectionInfoResult, err error) {
   411  	if tracing.IsEnabled() {
   412  		ctx = tracing.StartSpan(ctx, fqdn+"/NotebookWorkspacesClient.ListConnectionInfo")
   413  		defer func() {
   414  			sc := -1
   415  			if result.Response.Response != nil {
   416  				sc = result.Response.Response.StatusCode
   417  			}
   418  			tracing.EndSpan(ctx, sc, err)
   419  		}()
   420  	}
   421  	if err := validation.Validate([]validation.Validation{
   422  		{TargetValue: client.SubscriptionID,
   423  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   424  		{TargetValue: resourceGroupName,
   425  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   426  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   427  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   428  		{TargetValue: accountName,
   429  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   430  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   431  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   432  		return result, validation.NewError("documentdb.NotebookWorkspacesClient", "ListConnectionInfo", err.Error())
   433  	}
   434  
   435  	req, err := client.ListConnectionInfoPreparer(ctx, resourceGroupName, accountName)
   436  	if err != nil {
   437  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "ListConnectionInfo", nil, "Failure preparing request")
   438  		return
   439  	}
   440  
   441  	resp, err := client.ListConnectionInfoSender(req)
   442  	if err != nil {
   443  		result.Response = autorest.Response{Response: resp}
   444  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "ListConnectionInfo", resp, "Failure sending request")
   445  		return
   446  	}
   447  
   448  	result, err = client.ListConnectionInfoResponder(resp)
   449  	if err != nil {
   450  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "ListConnectionInfo", resp, "Failure responding to request")
   451  		return
   452  	}
   453  
   454  	return
   455  }
   456  
   457  // ListConnectionInfoPreparer prepares the ListConnectionInfo request.
   458  func (client NotebookWorkspacesClient) ListConnectionInfoPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   459  	pathParameters := map[string]interface{}{
   460  		"accountName":           autorest.Encode("path", accountName),
   461  		"notebookWorkspaceName": autorest.Encode("path", "default"),
   462  		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
   463  		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
   464  	}
   465  
   466  	const APIVersion = "2021-04-01-preview"
   467  	queryParameters := map[string]interface{}{
   468  		"api-version": APIVersion,
   469  	}
   470  
   471  	preparer := autorest.CreatePreparer(
   472  		autorest.AsPost(),
   473  		autorest.WithBaseURL(client.BaseURI),
   474  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/notebookWorkspaces/{notebookWorkspaceName}/listConnectionInfo", pathParameters),
   475  		autorest.WithQueryParameters(queryParameters))
   476  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   477  }
   478  
   479  // ListConnectionInfoSender sends the ListConnectionInfo request. The method will close the
   480  // http.Response Body if it receives an error.
   481  func (client NotebookWorkspacesClient) ListConnectionInfoSender(req *http.Request) (*http.Response, error) {
   482  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   483  }
   484  
   485  // ListConnectionInfoResponder handles the response to the ListConnectionInfo request. The method always
   486  // closes the http.Response Body.
   487  func (client NotebookWorkspacesClient) ListConnectionInfoResponder(resp *http.Response) (result NotebookWorkspaceConnectionInfoResult, err error) {
   488  	err = autorest.Respond(
   489  		resp,
   490  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   491  		autorest.ByUnmarshallingJSON(&result),
   492  		autorest.ByClosing())
   493  	result.Response = autorest.Response{Response: resp}
   494  	return
   495  }
   496  
   497  // RegenerateAuthToken regenerates the auth token for the notebook workspace
   498  // Parameters:
   499  // resourceGroupName - the name of the resource group. The name is case insensitive.
   500  // accountName - cosmos DB database account name.
   501  func (client NotebookWorkspacesClient) RegenerateAuthToken(ctx context.Context, resourceGroupName string, accountName string) (result NotebookWorkspacesRegenerateAuthTokenFuture, err error) {
   502  	if tracing.IsEnabled() {
   503  		ctx = tracing.StartSpan(ctx, fqdn+"/NotebookWorkspacesClient.RegenerateAuthToken")
   504  		defer func() {
   505  			sc := -1
   506  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   507  				sc = result.FutureAPI.Response().StatusCode
   508  			}
   509  			tracing.EndSpan(ctx, sc, err)
   510  		}()
   511  	}
   512  	if err := validation.Validate([]validation.Validation{
   513  		{TargetValue: client.SubscriptionID,
   514  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   515  		{TargetValue: resourceGroupName,
   516  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   517  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   518  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   519  		{TargetValue: accountName,
   520  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   521  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   522  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   523  		return result, validation.NewError("documentdb.NotebookWorkspacesClient", "RegenerateAuthToken", err.Error())
   524  	}
   525  
   526  	req, err := client.RegenerateAuthTokenPreparer(ctx, resourceGroupName, accountName)
   527  	if err != nil {
   528  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "RegenerateAuthToken", nil, "Failure preparing request")
   529  		return
   530  	}
   531  
   532  	result, err = client.RegenerateAuthTokenSender(req)
   533  	if err != nil {
   534  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "RegenerateAuthToken", result.Response(), "Failure sending request")
   535  		return
   536  	}
   537  
   538  	return
   539  }
   540  
   541  // RegenerateAuthTokenPreparer prepares the RegenerateAuthToken request.
   542  func (client NotebookWorkspacesClient) RegenerateAuthTokenPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   543  	pathParameters := map[string]interface{}{
   544  		"accountName":           autorest.Encode("path", accountName),
   545  		"notebookWorkspaceName": autorest.Encode("path", "default"),
   546  		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
   547  		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
   548  	}
   549  
   550  	const APIVersion = "2021-04-01-preview"
   551  	queryParameters := map[string]interface{}{
   552  		"api-version": APIVersion,
   553  	}
   554  
   555  	preparer := autorest.CreatePreparer(
   556  		autorest.AsPost(),
   557  		autorest.WithBaseURL(client.BaseURI),
   558  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/notebookWorkspaces/{notebookWorkspaceName}/regenerateAuthToken", pathParameters),
   559  		autorest.WithQueryParameters(queryParameters))
   560  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   561  }
   562  
   563  // RegenerateAuthTokenSender sends the RegenerateAuthToken request. The method will close the
   564  // http.Response Body if it receives an error.
   565  func (client NotebookWorkspacesClient) RegenerateAuthTokenSender(req *http.Request) (future NotebookWorkspacesRegenerateAuthTokenFuture, err error) {
   566  	var resp *http.Response
   567  	future.FutureAPI = &azure.Future{}
   568  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   569  	if err != nil {
   570  		return
   571  	}
   572  	var azf azure.Future
   573  	azf, err = azure.NewFutureFromResponse(resp)
   574  	future.FutureAPI = &azf
   575  	future.Result = future.result
   576  	return
   577  }
   578  
   579  // RegenerateAuthTokenResponder handles the response to the RegenerateAuthToken request. The method always
   580  // closes the http.Response Body.
   581  func (client NotebookWorkspacesClient) RegenerateAuthTokenResponder(resp *http.Response) (result autorest.Response, err error) {
   582  	err = autorest.Respond(
   583  		resp,
   584  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   585  		autorest.ByClosing())
   586  	result.Response = resp
   587  	return
   588  }
   589  
   590  // Start starts the notebook workspace
   591  // Parameters:
   592  // resourceGroupName - the name of the resource group. The name is case insensitive.
   593  // accountName - cosmos DB database account name.
   594  func (client NotebookWorkspacesClient) Start(ctx context.Context, resourceGroupName string, accountName string) (result NotebookWorkspacesStartFuture, err error) {
   595  	if tracing.IsEnabled() {
   596  		ctx = tracing.StartSpan(ctx, fqdn+"/NotebookWorkspacesClient.Start")
   597  		defer func() {
   598  			sc := -1
   599  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   600  				sc = result.FutureAPI.Response().StatusCode
   601  			}
   602  			tracing.EndSpan(ctx, sc, err)
   603  		}()
   604  	}
   605  	if err := validation.Validate([]validation.Validation{
   606  		{TargetValue: client.SubscriptionID,
   607  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   608  		{TargetValue: resourceGroupName,
   609  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   610  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   611  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   612  		{TargetValue: accountName,
   613  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   614  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
   615  				{Target: "accountName", Name: validation.Pattern, Rule: `^[a-z0-9]+(-[a-z0-9]+)*`, Chain: nil}}}}); err != nil {
   616  		return result, validation.NewError("documentdb.NotebookWorkspacesClient", "Start", err.Error())
   617  	}
   618  
   619  	req, err := client.StartPreparer(ctx, resourceGroupName, accountName)
   620  	if err != nil {
   621  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "Start", nil, "Failure preparing request")
   622  		return
   623  	}
   624  
   625  	result, err = client.StartSender(req)
   626  	if err != nil {
   627  		err = autorest.NewErrorWithError(err, "documentdb.NotebookWorkspacesClient", "Start", result.Response(), "Failure sending request")
   628  		return
   629  	}
   630  
   631  	return
   632  }
   633  
   634  // StartPreparer prepares the Start request.
   635  func (client NotebookWorkspacesClient) StartPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   636  	pathParameters := map[string]interface{}{
   637  		"accountName":           autorest.Encode("path", accountName),
   638  		"notebookWorkspaceName": autorest.Encode("path", "default"),
   639  		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
   640  		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
   641  	}
   642  
   643  	const APIVersion = "2021-04-01-preview"
   644  	queryParameters := map[string]interface{}{
   645  		"api-version": APIVersion,
   646  	}
   647  
   648  	preparer := autorest.CreatePreparer(
   649  		autorest.AsPost(),
   650  		autorest.WithBaseURL(client.BaseURI),
   651  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/notebookWorkspaces/{notebookWorkspaceName}/start", pathParameters),
   652  		autorest.WithQueryParameters(queryParameters))
   653  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   654  }
   655  
   656  // StartSender sends the Start request. The method will close the
   657  // http.Response Body if it receives an error.
   658  func (client NotebookWorkspacesClient) StartSender(req *http.Request) (future NotebookWorkspacesStartFuture, err error) {
   659  	var resp *http.Response
   660  	future.FutureAPI = &azure.Future{}
   661  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   662  	if err != nil {
   663  		return
   664  	}
   665  	var azf azure.Future
   666  	azf, err = azure.NewFutureFromResponse(resp)
   667  	future.FutureAPI = &azf
   668  	future.Result = future.result
   669  	return
   670  }
   671  
   672  // StartResponder handles the response to the Start request. The method always
   673  // closes the http.Response Body.
   674  func (client NotebookWorkspacesClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
   675  	err = autorest.Respond(
   676  		resp,
   677  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   678  		autorest.ByClosing())
   679  	result.Response = resp
   680  	return
   681  }
   682  

View as plain text