...

Source file src/github.com/Azure/azure-sdk-for-go/services/search/mgmt/2020-08-01/search/adminkeys.go

Documentation: github.com/Azure/azure-sdk-for-go/services/search/mgmt/2020-08-01/search

     1  package search
     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/tracing"
    14  	"github.com/gofrs/uuid"
    15  	"net/http"
    16  )
    17  
    18  // AdminKeysClient is the client that can be used to manage Azure Cognitive Search services and API keys.
    19  type AdminKeysClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewAdminKeysClient creates an instance of the AdminKeysClient client.
    24  func NewAdminKeysClient(subscriptionID string) AdminKeysClient {
    25  	return NewAdminKeysClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewAdminKeysClientWithBaseURI creates an instance of the AdminKeysClient 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 NewAdminKeysClientWithBaseURI(baseURI string, subscriptionID string) AdminKeysClient {
    31  	return AdminKeysClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Get gets the primary and secondary admin API keys for the specified Azure Cognitive Search service.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group within the current subscription. You can obtain this
    37  // value from the Azure Resource Manager API or the portal.
    38  // searchServiceName - the name of the Azure Cognitive Search service associated with the specified resource
    39  // group.
    40  // clientRequestID - a client-generated GUID value that identifies this request. If specified, this will be
    41  // included in response information as a way to track the request.
    42  func (client AdminKeysClient) Get(ctx context.Context, resourceGroupName string, searchServiceName string, clientRequestID *uuid.UUID) (result AdminKeyResult, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/AdminKeysClient.Get")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response.Response != nil {
    48  				sc = result.Response.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	req, err := client.GetPreparer(ctx, resourceGroupName, searchServiceName, clientRequestID)
    54  	if err != nil {
    55  		err = autorest.NewErrorWithError(err, "search.AdminKeysClient", "Get", nil, "Failure preparing request")
    56  		return
    57  	}
    58  
    59  	resp, err := client.GetSender(req)
    60  	if err != nil {
    61  		result.Response = autorest.Response{Response: resp}
    62  		err = autorest.NewErrorWithError(err, "search.AdminKeysClient", "Get", resp, "Failure sending request")
    63  		return
    64  	}
    65  
    66  	result, err = client.GetResponder(resp)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "search.AdminKeysClient", "Get", resp, "Failure responding to request")
    69  		return
    70  	}
    71  
    72  	return
    73  }
    74  
    75  // GetPreparer prepares the Get request.
    76  func (client AdminKeysClient) GetPreparer(ctx context.Context, resourceGroupName string, searchServiceName string, clientRequestID *uuid.UUID) (*http.Request, error) {
    77  	pathParameters := map[string]interface{}{
    78  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    79  		"searchServiceName": autorest.Encode("path", searchServiceName),
    80  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    81  	}
    82  
    83  	const APIVersion = "2020-08-01"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  
    88  	preparer := autorest.CreatePreparer(
    89  		autorest.AsPost(),
    90  		autorest.WithBaseURL(client.BaseURI),
    91  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/listAdminKeys", pathParameters),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	if clientRequestID != nil {
    94  		preparer = autorest.DecoratePreparer(preparer,
    95  			autorest.WithHeader("x-ms-client-request-id", autorest.String(clientRequestID)))
    96  	}
    97  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    98  }
    99  
   100  // GetSender sends the Get request. The method will close the
   101  // http.Response Body if it receives an error.
   102  func (client AdminKeysClient) GetSender(req *http.Request) (*http.Response, error) {
   103  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   104  }
   105  
   106  // GetResponder handles the response to the Get request. The method always
   107  // closes the http.Response Body.
   108  func (client AdminKeysClient) GetResponder(resp *http.Response) (result AdminKeyResult, err error) {
   109  	err = autorest.Respond(
   110  		resp,
   111  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   112  		autorest.ByUnmarshallingJSON(&result),
   113  		autorest.ByClosing())
   114  	result.Response = autorest.Response{Response: resp}
   115  	return
   116  }
   117  
   118  // Regenerate regenerates either the primary or secondary admin API key. You can only regenerate one key at a time.
   119  // Parameters:
   120  // resourceGroupName - the name of the resource group within the current subscription. You can obtain this
   121  // value from the Azure Resource Manager API or the portal.
   122  // searchServiceName - the name of the Azure Cognitive Search service associated with the specified resource
   123  // group.
   124  // keyKind - specifies which key to regenerate. Valid values include 'primary' and 'secondary'.
   125  // clientRequestID - a client-generated GUID value that identifies this request. If specified, this will be
   126  // included in response information as a way to track the request.
   127  func (client AdminKeysClient) Regenerate(ctx context.Context, resourceGroupName string, searchServiceName string, keyKind AdminKeyKind, clientRequestID *uuid.UUID) (result AdminKeyResult, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/AdminKeysClient.Regenerate")
   130  		defer func() {
   131  			sc := -1
   132  			if result.Response.Response != nil {
   133  				sc = result.Response.Response.StatusCode
   134  			}
   135  			tracing.EndSpan(ctx, sc, err)
   136  		}()
   137  	}
   138  	req, err := client.RegeneratePreparer(ctx, resourceGroupName, searchServiceName, keyKind, clientRequestID)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "search.AdminKeysClient", "Regenerate", nil, "Failure preparing request")
   141  		return
   142  	}
   143  
   144  	resp, err := client.RegenerateSender(req)
   145  	if err != nil {
   146  		result.Response = autorest.Response{Response: resp}
   147  		err = autorest.NewErrorWithError(err, "search.AdminKeysClient", "Regenerate", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result, err = client.RegenerateResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "search.AdminKeysClient", "Regenerate", resp, "Failure responding to request")
   154  		return
   155  	}
   156  
   157  	return
   158  }
   159  
   160  // RegeneratePreparer prepares the Regenerate request.
   161  func (client AdminKeysClient) RegeneratePreparer(ctx context.Context, resourceGroupName string, searchServiceName string, keyKind AdminKeyKind, clientRequestID *uuid.UUID) (*http.Request, error) {
   162  	pathParameters := map[string]interface{}{
   163  		"keyKind":           autorest.Encode("path", keyKind),
   164  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   165  		"searchServiceName": autorest.Encode("path", searchServiceName),
   166  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   167  	}
   168  
   169  	const APIVersion = "2020-08-01"
   170  	queryParameters := map[string]interface{}{
   171  		"api-version": APIVersion,
   172  	}
   173  
   174  	preparer := autorest.CreatePreparer(
   175  		autorest.AsPost(),
   176  		autorest.WithBaseURL(client.BaseURI),
   177  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/regenerateAdminKey/{keyKind}", pathParameters),
   178  		autorest.WithQueryParameters(queryParameters))
   179  	if clientRequestID != nil {
   180  		preparer = autorest.DecoratePreparer(preparer,
   181  			autorest.WithHeader("x-ms-client-request-id", autorest.String(clientRequestID)))
   182  	}
   183  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   184  }
   185  
   186  // RegenerateSender sends the Regenerate request. The method will close the
   187  // http.Response Body if it receives an error.
   188  func (client AdminKeysClient) RegenerateSender(req *http.Request) (*http.Response, error) {
   189  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   190  }
   191  
   192  // RegenerateResponder handles the response to the Regenerate request. The method always
   193  // closes the http.Response Body.
   194  func (client AdminKeysClient) RegenerateResponder(resp *http.Response) (result AdminKeyResult, err error) {
   195  	err = autorest.Respond(
   196  		resp,
   197  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   198  		autorest.ByUnmarshallingJSON(&result),
   199  		autorest.ByClosing())
   200  	result.Response = autorest.Response{Response: resp}
   201  	return
   202  }
   203  

View as plain text