...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v3.0/luis/authoring/azureaccounts.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v3.0/luis/authoring

     1  package authoring
     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  	"github.com/gofrs/uuid"
    16  	"net/http"
    17  )
    18  
    19  // AzureAccountsClient is the client for the AzureAccounts methods of the Authoring service.
    20  type AzureAccountsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewAzureAccountsClient creates an instance of the AzureAccountsClient client.
    25  func NewAzureAccountsClient(endpoint string) AzureAccountsClient {
    26  	return AzureAccountsClient{New(endpoint)}
    27  }
    28  
    29  // AssignToApp assigns an Azure account to the application.
    30  // Parameters:
    31  // appID - the application ID.
    32  // armToken - the custom arm token header to use; containing the user's ARM token used to validate azure
    33  // accounts information.
    34  // azureAccountInfoObject - the Azure account information object.
    35  func (client AzureAccountsClient) AssignToApp(ctx context.Context, appID uuid.UUID, armToken string, azureAccountInfoObject *AzureAccountInfoObject) (result OperationStatus, err error) {
    36  	if tracing.IsEnabled() {
    37  		ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.AssignToApp")
    38  		defer func() {
    39  			sc := -1
    40  			if result.Response.Response != nil {
    41  				sc = result.Response.Response.StatusCode
    42  			}
    43  			tracing.EndSpan(ctx, sc, err)
    44  		}()
    45  	}
    46  	if err := validation.Validate([]validation.Validation{
    47  		{TargetValue: azureAccountInfoObject,
    48  			Constraints: []validation.Constraint{{Target: "azureAccountInfoObject", Name: validation.Null, Rule: false,
    49  				Chain: []validation.Constraint{{Target: "azureAccountInfoObject.AzureSubscriptionID", Name: validation.Null, Rule: true, Chain: nil},
    50  					{Target: "azureAccountInfoObject.ResourceGroup", Name: validation.Null, Rule: true, Chain: nil},
    51  					{Target: "azureAccountInfoObject.AccountName", Name: validation.Null, Rule: true, Chain: nil},
    52  				}}}}}); err != nil {
    53  		return result, validation.NewError("authoring.AzureAccountsClient", "AssignToApp", err.Error())
    54  	}
    55  
    56  	req, err := client.AssignToAppPreparer(ctx, appID, armToken, azureAccountInfoObject)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "AssignToApp", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	resp, err := client.AssignToAppSender(req)
    63  	if err != nil {
    64  		result.Response = autorest.Response{Response: resp}
    65  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "AssignToApp", resp, "Failure sending request")
    66  		return
    67  	}
    68  
    69  	result, err = client.AssignToAppResponder(resp)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "AssignToApp", resp, "Failure responding to request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // AssignToAppPreparer prepares the AssignToApp request.
    79  func (client AzureAccountsClient) AssignToAppPreparer(ctx context.Context, appID uuid.UUID, armToken string, azureAccountInfoObject *AzureAccountInfoObject) (*http.Request, error) {
    80  	urlParameters := map[string]interface{}{
    81  		"Endpoint": client.Endpoint,
    82  	}
    83  
    84  	pathParameters := map[string]interface{}{
    85  		"appId": autorest.Encode("path", appID),
    86  	}
    87  
    88  	preparer := autorest.CreatePreparer(
    89  		autorest.AsContentType("application/json; charset=utf-8"),
    90  		autorest.AsPost(),
    91  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
    92  		autorest.WithPathParameters("/apps/{appId}/azureaccounts", pathParameters))
    93  	if azureAccountInfoObject != nil {
    94  		preparer = autorest.DecoratePreparer(preparer,
    95  			autorest.WithJSON(azureAccountInfoObject))
    96  	}
    97  	if len(armToken) > 0 {
    98  		preparer = autorest.DecoratePreparer(preparer,
    99  			autorest.WithHeader("ArmToken", autorest.String(armToken)))
   100  	}
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // AssignToAppSender sends the AssignToApp request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client AzureAccountsClient) AssignToAppSender(req *http.Request) (*http.Response, error) {
   107  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   108  }
   109  
   110  // AssignToAppResponder handles the response to the AssignToApp request. The method always
   111  // closes the http.Response Body.
   112  func (client AzureAccountsClient) AssignToAppResponder(resp *http.Response) (result OperationStatus, err error) {
   113  	err = autorest.Respond(
   114  		resp,
   115  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   116  		autorest.ByUnmarshallingJSON(&result),
   117  		autorest.ByClosing())
   118  	result.Response = autorest.Response{Response: resp}
   119  	return
   120  }
   121  
   122  // GetAssigned gets the LUIS Azure accounts assigned to the application for the user using his ARM token.
   123  // Parameters:
   124  // appID - the application ID.
   125  // armToken - the custom arm token header to use; containing the user's ARM token used to validate azure
   126  // accounts information.
   127  func (client AzureAccountsClient) GetAssigned(ctx context.Context, appID uuid.UUID, armToken string) (result ListAzureAccountInfoObject, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.GetAssigned")
   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.GetAssignedPreparer(ctx, appID, armToken)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "GetAssigned", nil, "Failure preparing request")
   141  		return
   142  	}
   143  
   144  	resp, err := client.GetAssignedSender(req)
   145  	if err != nil {
   146  		result.Response = autorest.Response{Response: resp}
   147  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "GetAssigned", resp, "Failure sending request")
   148  		return
   149  	}
   150  
   151  	result, err = client.GetAssignedResponder(resp)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "GetAssigned", resp, "Failure responding to request")
   154  		return
   155  	}
   156  
   157  	return
   158  }
   159  
   160  // GetAssignedPreparer prepares the GetAssigned request.
   161  func (client AzureAccountsClient) GetAssignedPreparer(ctx context.Context, appID uuid.UUID, armToken string) (*http.Request, error) {
   162  	urlParameters := map[string]interface{}{
   163  		"Endpoint": client.Endpoint,
   164  	}
   165  
   166  	pathParameters := map[string]interface{}{
   167  		"appId": autorest.Encode("path", appID),
   168  	}
   169  
   170  	preparer := autorest.CreatePreparer(
   171  		autorest.AsGet(),
   172  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
   173  		autorest.WithPathParameters("/apps/{appId}/azureaccounts", pathParameters))
   174  	if len(armToken) > 0 {
   175  		preparer = autorest.DecoratePreparer(preparer,
   176  			autorest.WithHeader("ArmToken", autorest.String(armToken)))
   177  	}
   178  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   179  }
   180  
   181  // GetAssignedSender sends the GetAssigned request. The method will close the
   182  // http.Response Body if it receives an error.
   183  func (client AzureAccountsClient) GetAssignedSender(req *http.Request) (*http.Response, error) {
   184  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   185  }
   186  
   187  // GetAssignedResponder handles the response to the GetAssigned request. The method always
   188  // closes the http.Response Body.
   189  func (client AzureAccountsClient) GetAssignedResponder(resp *http.Response) (result ListAzureAccountInfoObject, err error) {
   190  	err = autorest.Respond(
   191  		resp,
   192  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   193  		autorest.ByUnmarshallingJSON(&result.Value),
   194  		autorest.ByClosing())
   195  	result.Response = autorest.Response{Response: resp}
   196  	return
   197  }
   198  
   199  // ListUserLUISAccounts gets the LUIS Azure accounts for the user using his ARM token.
   200  // Parameters:
   201  // armToken - the custom arm token header to use; containing the user's ARM token used to validate azure
   202  // accounts information.
   203  func (client AzureAccountsClient) ListUserLUISAccounts(ctx context.Context, armToken string) (result ListAzureAccountInfoObject, err error) {
   204  	if tracing.IsEnabled() {
   205  		ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.ListUserLUISAccounts")
   206  		defer func() {
   207  			sc := -1
   208  			if result.Response.Response != nil {
   209  				sc = result.Response.Response.StatusCode
   210  			}
   211  			tracing.EndSpan(ctx, sc, err)
   212  		}()
   213  	}
   214  	req, err := client.ListUserLUISAccountsPreparer(ctx, armToken)
   215  	if err != nil {
   216  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "ListUserLUISAccounts", nil, "Failure preparing request")
   217  		return
   218  	}
   219  
   220  	resp, err := client.ListUserLUISAccountsSender(req)
   221  	if err != nil {
   222  		result.Response = autorest.Response{Response: resp}
   223  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "ListUserLUISAccounts", resp, "Failure sending request")
   224  		return
   225  	}
   226  
   227  	result, err = client.ListUserLUISAccountsResponder(resp)
   228  	if err != nil {
   229  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "ListUserLUISAccounts", resp, "Failure responding to request")
   230  		return
   231  	}
   232  
   233  	return
   234  }
   235  
   236  // ListUserLUISAccountsPreparer prepares the ListUserLUISAccounts request.
   237  func (client AzureAccountsClient) ListUserLUISAccountsPreparer(ctx context.Context, armToken string) (*http.Request, error) {
   238  	urlParameters := map[string]interface{}{
   239  		"Endpoint": client.Endpoint,
   240  	}
   241  
   242  	preparer := autorest.CreatePreparer(
   243  		autorest.AsGet(),
   244  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
   245  		autorest.WithPath("/azureaccounts"))
   246  	if len(armToken) > 0 {
   247  		preparer = autorest.DecoratePreparer(preparer,
   248  			autorest.WithHeader("ArmToken", autorest.String(armToken)))
   249  	}
   250  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   251  }
   252  
   253  // ListUserLUISAccountsSender sends the ListUserLUISAccounts request. The method will close the
   254  // http.Response Body if it receives an error.
   255  func (client AzureAccountsClient) ListUserLUISAccountsSender(req *http.Request) (*http.Response, error) {
   256  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   257  }
   258  
   259  // ListUserLUISAccountsResponder handles the response to the ListUserLUISAccounts request. The method always
   260  // closes the http.Response Body.
   261  func (client AzureAccountsClient) ListUserLUISAccountsResponder(resp *http.Response) (result ListAzureAccountInfoObject, err error) {
   262  	err = autorest.Respond(
   263  		resp,
   264  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   265  		autorest.ByUnmarshallingJSON(&result.Value),
   266  		autorest.ByClosing())
   267  	result.Response = autorest.Response{Response: resp}
   268  	return
   269  }
   270  
   271  // RemoveFromApp removes assigned Azure account from the application.
   272  // Parameters:
   273  // appID - the application ID.
   274  // armToken - the custom arm token header to use; containing the user's ARM token used to validate azure
   275  // accounts information.
   276  // azureAccountInfoObject - the Azure account information object.
   277  func (client AzureAccountsClient) RemoveFromApp(ctx context.Context, appID uuid.UUID, armToken string, azureAccountInfoObject *AzureAccountInfoObject) (result OperationStatus, err error) {
   278  	if tracing.IsEnabled() {
   279  		ctx = tracing.StartSpan(ctx, fqdn+"/AzureAccountsClient.RemoveFromApp")
   280  		defer func() {
   281  			sc := -1
   282  			if result.Response.Response != nil {
   283  				sc = result.Response.Response.StatusCode
   284  			}
   285  			tracing.EndSpan(ctx, sc, err)
   286  		}()
   287  	}
   288  	if err := validation.Validate([]validation.Validation{
   289  		{TargetValue: azureAccountInfoObject,
   290  			Constraints: []validation.Constraint{{Target: "azureAccountInfoObject", Name: validation.Null, Rule: false,
   291  				Chain: []validation.Constraint{{Target: "azureAccountInfoObject.AzureSubscriptionID", Name: validation.Null, Rule: true, Chain: nil},
   292  					{Target: "azureAccountInfoObject.ResourceGroup", Name: validation.Null, Rule: true, Chain: nil},
   293  					{Target: "azureAccountInfoObject.AccountName", Name: validation.Null, Rule: true, Chain: nil},
   294  				}}}}}); err != nil {
   295  		return result, validation.NewError("authoring.AzureAccountsClient", "RemoveFromApp", err.Error())
   296  	}
   297  
   298  	req, err := client.RemoveFromAppPreparer(ctx, appID, armToken, azureAccountInfoObject)
   299  	if err != nil {
   300  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "RemoveFromApp", nil, "Failure preparing request")
   301  		return
   302  	}
   303  
   304  	resp, err := client.RemoveFromAppSender(req)
   305  	if err != nil {
   306  		result.Response = autorest.Response{Response: resp}
   307  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "RemoveFromApp", resp, "Failure sending request")
   308  		return
   309  	}
   310  
   311  	result, err = client.RemoveFromAppResponder(resp)
   312  	if err != nil {
   313  		err = autorest.NewErrorWithError(err, "authoring.AzureAccountsClient", "RemoveFromApp", resp, "Failure responding to request")
   314  		return
   315  	}
   316  
   317  	return
   318  }
   319  
   320  // RemoveFromAppPreparer prepares the RemoveFromApp request.
   321  func (client AzureAccountsClient) RemoveFromAppPreparer(ctx context.Context, appID uuid.UUID, armToken string, azureAccountInfoObject *AzureAccountInfoObject) (*http.Request, error) {
   322  	urlParameters := map[string]interface{}{
   323  		"Endpoint": client.Endpoint,
   324  	}
   325  
   326  	pathParameters := map[string]interface{}{
   327  		"appId": autorest.Encode("path", appID),
   328  	}
   329  
   330  	preparer := autorest.CreatePreparer(
   331  		autorest.AsContentType("application/json; charset=utf-8"),
   332  		autorest.AsDelete(),
   333  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
   334  		autorest.WithPathParameters("/apps/{appId}/azureaccounts", pathParameters))
   335  	if azureAccountInfoObject != nil {
   336  		preparer = autorest.DecoratePreparer(preparer,
   337  			autorest.WithJSON(azureAccountInfoObject))
   338  	}
   339  	if len(armToken) > 0 {
   340  		preparer = autorest.DecoratePreparer(preparer,
   341  			autorest.WithHeader("ArmToken", autorest.String(armToken)))
   342  	}
   343  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   344  }
   345  
   346  // RemoveFromAppSender sends the RemoveFromApp request. The method will close the
   347  // http.Response Body if it receives an error.
   348  func (client AzureAccountsClient) RemoveFromAppSender(req *http.Request) (*http.Response, error) {
   349  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   350  }
   351  
   352  // RemoveFromAppResponder handles the response to the RemoveFromApp request. The method always
   353  // closes the http.Response Body.
   354  func (client AzureAccountsClient) RemoveFromAppResponder(resp *http.Response) (result OperationStatus, err error) {
   355  	err = autorest.Respond(
   356  		resp,
   357  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   358  		autorest.ByUnmarshallingJSON(&result),
   359  		autorest.ByClosing())
   360  	result.Response = autorest.Response{Response: resp}
   361  	return
   362  }
   363  

View as plain text