...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.0/luis/authoring/permissions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v2.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/tracing"
    14  	"github.com/gofrs/uuid"
    15  	"net/http"
    16  )
    17  
    18  // PermissionsClient is the client for the Permissions methods of the Authoring service.
    19  type PermissionsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewPermissionsClient creates an instance of the PermissionsClient client.
    24  func NewPermissionsClient(endpoint string) PermissionsClient {
    25  	return PermissionsClient{New(endpoint)}
    26  }
    27  
    28  // Add adds a user to the allowed list of users to access this LUIS application. Users are added using their email
    29  // address.
    30  // Parameters:
    31  // appID - the application ID.
    32  // userToAdd - a model containing the user's email address.
    33  func (client PermissionsClient) Add(ctx context.Context, appID uuid.UUID, userToAdd UserCollaborator) (result OperationStatus, err error) {
    34  	if tracing.IsEnabled() {
    35  		ctx = tracing.StartSpan(ctx, fqdn+"/PermissionsClient.Add")
    36  		defer func() {
    37  			sc := -1
    38  			if result.Response.Response != nil {
    39  				sc = result.Response.Response.StatusCode
    40  			}
    41  			tracing.EndSpan(ctx, sc, err)
    42  		}()
    43  	}
    44  	req, err := client.AddPreparer(ctx, appID, userToAdd)
    45  	if err != nil {
    46  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Add", nil, "Failure preparing request")
    47  		return
    48  	}
    49  
    50  	resp, err := client.AddSender(req)
    51  	if err != nil {
    52  		result.Response = autorest.Response{Response: resp}
    53  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Add", resp, "Failure sending request")
    54  		return
    55  	}
    56  
    57  	result, err = client.AddResponder(resp)
    58  	if err != nil {
    59  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Add", resp, "Failure responding to request")
    60  		return
    61  	}
    62  
    63  	return
    64  }
    65  
    66  // AddPreparer prepares the Add request.
    67  func (client PermissionsClient) AddPreparer(ctx context.Context, appID uuid.UUID, userToAdd UserCollaborator) (*http.Request, error) {
    68  	urlParameters := map[string]interface{}{
    69  		"Endpoint": client.Endpoint,
    70  	}
    71  
    72  	pathParameters := map[string]interface{}{
    73  		"appId": autorest.Encode("path", appID),
    74  	}
    75  
    76  	preparer := autorest.CreatePreparer(
    77  		autorest.AsContentType("application/json; charset=utf-8"),
    78  		autorest.AsPost(),
    79  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
    80  		autorest.WithPathParameters("/apps/{appId}/permissions", pathParameters),
    81  		autorest.WithJSON(userToAdd))
    82  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    83  }
    84  
    85  // AddSender sends the Add request. The method will close the
    86  // http.Response Body if it receives an error.
    87  func (client PermissionsClient) AddSender(req *http.Request) (*http.Response, error) {
    88  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    89  }
    90  
    91  // AddResponder handles the response to the Add request. The method always
    92  // closes the http.Response Body.
    93  func (client PermissionsClient) AddResponder(resp *http.Response) (result OperationStatus, err error) {
    94  	err = autorest.Respond(
    95  		resp,
    96  		azure.WithErrorUnlessStatusCode(http.StatusOK),
    97  		autorest.ByUnmarshallingJSON(&result),
    98  		autorest.ByClosing())
    99  	result.Response = autorest.Response{Response: resp}
   100  	return
   101  }
   102  
   103  // Delete removes a user from the allowed list of users to access this LUIS application. Users are removed using their
   104  // email address.
   105  // Parameters:
   106  // appID - the application ID.
   107  // userToDelete - a model containing the user's email address.
   108  func (client PermissionsClient) Delete(ctx context.Context, appID uuid.UUID, userToDelete UserCollaborator) (result OperationStatus, err error) {
   109  	if tracing.IsEnabled() {
   110  		ctx = tracing.StartSpan(ctx, fqdn+"/PermissionsClient.Delete")
   111  		defer func() {
   112  			sc := -1
   113  			if result.Response.Response != nil {
   114  				sc = result.Response.Response.StatusCode
   115  			}
   116  			tracing.EndSpan(ctx, sc, err)
   117  		}()
   118  	}
   119  	req, err := client.DeletePreparer(ctx, appID, userToDelete)
   120  	if err != nil {
   121  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Delete", nil, "Failure preparing request")
   122  		return
   123  	}
   124  
   125  	resp, err := client.DeleteSender(req)
   126  	if err != nil {
   127  		result.Response = autorest.Response{Response: resp}
   128  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Delete", resp, "Failure sending request")
   129  		return
   130  	}
   131  
   132  	result, err = client.DeleteResponder(resp)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Delete", resp, "Failure responding to request")
   135  		return
   136  	}
   137  
   138  	return
   139  }
   140  
   141  // DeletePreparer prepares the Delete request.
   142  func (client PermissionsClient) DeletePreparer(ctx context.Context, appID uuid.UUID, userToDelete UserCollaborator) (*http.Request, error) {
   143  	urlParameters := map[string]interface{}{
   144  		"Endpoint": client.Endpoint,
   145  	}
   146  
   147  	pathParameters := map[string]interface{}{
   148  		"appId": autorest.Encode("path", appID),
   149  	}
   150  
   151  	preparer := autorest.CreatePreparer(
   152  		autorest.AsContentType("application/json; charset=utf-8"),
   153  		autorest.AsDelete(),
   154  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   155  		autorest.WithPathParameters("/apps/{appId}/permissions", pathParameters),
   156  		autorest.WithJSON(userToDelete))
   157  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   158  }
   159  
   160  // DeleteSender sends the Delete request. The method will close the
   161  // http.Response Body if it receives an error.
   162  func (client PermissionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   163  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   164  }
   165  
   166  // DeleteResponder handles the response to the Delete request. The method always
   167  // closes the http.Response Body.
   168  func (client PermissionsClient) DeleteResponder(resp *http.Response) (result OperationStatus, err error) {
   169  	err = autorest.Respond(
   170  		resp,
   171  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   172  		autorest.ByUnmarshallingJSON(&result),
   173  		autorest.ByClosing())
   174  	result.Response = autorest.Response{Response: resp}
   175  	return
   176  }
   177  
   178  // List gets the list of user emails that have permissions to access your application.
   179  // Parameters:
   180  // appID - the application ID.
   181  func (client PermissionsClient) List(ctx context.Context, appID uuid.UUID) (result UserAccessList, err error) {
   182  	if tracing.IsEnabled() {
   183  		ctx = tracing.StartSpan(ctx, fqdn+"/PermissionsClient.List")
   184  		defer func() {
   185  			sc := -1
   186  			if result.Response.Response != nil {
   187  				sc = result.Response.Response.StatusCode
   188  			}
   189  			tracing.EndSpan(ctx, sc, err)
   190  		}()
   191  	}
   192  	req, err := client.ListPreparer(ctx, appID)
   193  	if err != nil {
   194  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "List", nil, "Failure preparing request")
   195  		return
   196  	}
   197  
   198  	resp, err := client.ListSender(req)
   199  	if err != nil {
   200  		result.Response = autorest.Response{Response: resp}
   201  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "List", resp, "Failure sending request")
   202  		return
   203  	}
   204  
   205  	result, err = client.ListResponder(resp)
   206  	if err != nil {
   207  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "List", resp, "Failure responding to request")
   208  		return
   209  	}
   210  
   211  	return
   212  }
   213  
   214  // ListPreparer prepares the List request.
   215  func (client PermissionsClient) ListPreparer(ctx context.Context, appID uuid.UUID) (*http.Request, error) {
   216  	urlParameters := map[string]interface{}{
   217  		"Endpoint": client.Endpoint,
   218  	}
   219  
   220  	pathParameters := map[string]interface{}{
   221  		"appId": autorest.Encode("path", appID),
   222  	}
   223  
   224  	preparer := autorest.CreatePreparer(
   225  		autorest.AsGet(),
   226  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   227  		autorest.WithPathParameters("/apps/{appId}/permissions", pathParameters))
   228  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   229  }
   230  
   231  // ListSender sends the List request. The method will close the
   232  // http.Response Body if it receives an error.
   233  func (client PermissionsClient) ListSender(req *http.Request) (*http.Response, error) {
   234  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   235  }
   236  
   237  // ListResponder handles the response to the List request. The method always
   238  // closes the http.Response Body.
   239  func (client PermissionsClient) ListResponder(resp *http.Response) (result UserAccessList, err error) {
   240  	err = autorest.Respond(
   241  		resp,
   242  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   243  		autorest.ByUnmarshallingJSON(&result),
   244  		autorest.ByClosing())
   245  	result.Response = autorest.Response{Response: resp}
   246  	return
   247  }
   248  
   249  // Update replaces the current user access list with the new list sent in the body. If an empty list is sent, all
   250  // access to other users will be removed.
   251  // Parameters:
   252  // appID - the application ID.
   253  // collaborators - a model containing a list of user email addresses.
   254  func (client PermissionsClient) Update(ctx context.Context, appID uuid.UUID, collaborators CollaboratorsArray) (result OperationStatus, err error) {
   255  	if tracing.IsEnabled() {
   256  		ctx = tracing.StartSpan(ctx, fqdn+"/PermissionsClient.Update")
   257  		defer func() {
   258  			sc := -1
   259  			if result.Response.Response != nil {
   260  				sc = result.Response.Response.StatusCode
   261  			}
   262  			tracing.EndSpan(ctx, sc, err)
   263  		}()
   264  	}
   265  	req, err := client.UpdatePreparer(ctx, appID, collaborators)
   266  	if err != nil {
   267  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Update", nil, "Failure preparing request")
   268  		return
   269  	}
   270  
   271  	resp, err := client.UpdateSender(req)
   272  	if err != nil {
   273  		result.Response = autorest.Response{Response: resp}
   274  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Update", resp, "Failure sending request")
   275  		return
   276  	}
   277  
   278  	result, err = client.UpdateResponder(resp)
   279  	if err != nil {
   280  		err = autorest.NewErrorWithError(err, "authoring.PermissionsClient", "Update", resp, "Failure responding to request")
   281  		return
   282  	}
   283  
   284  	return
   285  }
   286  
   287  // UpdatePreparer prepares the Update request.
   288  func (client PermissionsClient) UpdatePreparer(ctx context.Context, appID uuid.UUID, collaborators CollaboratorsArray) (*http.Request, error) {
   289  	urlParameters := map[string]interface{}{
   290  		"Endpoint": client.Endpoint,
   291  	}
   292  
   293  	pathParameters := map[string]interface{}{
   294  		"appId": autorest.Encode("path", appID),
   295  	}
   296  
   297  	preparer := autorest.CreatePreparer(
   298  		autorest.AsContentType("application/json; charset=utf-8"),
   299  		autorest.AsPut(),
   300  		autorest.WithCustomBaseURL("{Endpoint}/luis/api/v2.0", urlParameters),
   301  		autorest.WithPathParameters("/apps/{appId}/permissions", pathParameters),
   302  		autorest.WithJSON(collaborators))
   303  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   304  }
   305  
   306  // UpdateSender sends the Update request. The method will close the
   307  // http.Response Body if it receives an error.
   308  func (client PermissionsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   309  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   310  }
   311  
   312  // UpdateResponder handles the response to the Update request. The method always
   313  // closes the http.Response Body.
   314  func (client PermissionsClient) UpdateResponder(resp *http.Response) (result OperationStatus, err error) {
   315  	err = autorest.Respond(
   316  		resp,
   317  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   318  		autorest.ByUnmarshallingJSON(&result),
   319  		autorest.ByClosing())
   320  	result.Response = autorest.Response{Response: resp}
   321  	return
   322  }
   323  

View as plain text