...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/synapse/2020-08-01-preview/accesscontrol/roleassignments.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/synapse/2020-08-01-preview/accesscontrol

     1  package accesscontrol
     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  // RoleAssignmentsClient is the client for the RoleAssignments methods of the Accesscontrol service.
    19  type RoleAssignmentsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewRoleAssignmentsClient creates an instance of the RoleAssignmentsClient client.
    24  func NewRoleAssignmentsClient(endpoint string) RoleAssignmentsClient {
    25  	return RoleAssignmentsClient{New(endpoint)}
    26  }
    27  
    28  // CheckPrincipalAccess check if the given principalId has access to perform list of actions at a given scope.
    29  // Parameters:
    30  // request - details of scope, list of actions and principal.
    31  func (client RoleAssignmentsClient) CheckPrincipalAccess(ctx context.Context, request CheckPrincipalAccessRequest) (result CheckPrincipalAccessResponse, err error) {
    32  	if tracing.IsEnabled() {
    33  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleAssignmentsClient.CheckPrincipalAccess")
    34  		defer func() {
    35  			sc := -1
    36  			if result.Response.Response != nil {
    37  				sc = result.Response.Response.StatusCode
    38  			}
    39  			tracing.EndSpan(ctx, sc, err)
    40  		}()
    41  	}
    42  	if err := validation.Validate([]validation.Validation{
    43  		{TargetValue: request,
    44  			Constraints: []validation.Constraint{{Target: "request.Subject", Name: validation.Null, Rule: true,
    45  				Chain: []validation.Constraint{{Target: "request.Subject.PrincipalID", Name: validation.Null, Rule: true, Chain: nil}}},
    46  				{Target: "request.Actions", Name: validation.Null, Rule: true, Chain: nil},
    47  				{Target: "request.Scope", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    48  		return result, validation.NewError("accesscontrol.RoleAssignmentsClient", "CheckPrincipalAccess", err.Error())
    49  	}
    50  
    51  	req, err := client.CheckPrincipalAccessPreparer(ctx, request)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "CheckPrincipalAccess", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.CheckPrincipalAccessSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "CheckPrincipalAccess", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.CheckPrincipalAccessResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "CheckPrincipalAccess", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // CheckPrincipalAccessPreparer prepares the CheckPrincipalAccess request.
    74  func (client RoleAssignmentsClient) CheckPrincipalAccessPreparer(ctx context.Context, request CheckPrincipalAccessRequest) (*http.Request, error) {
    75  	urlParameters := map[string]interface{}{
    76  		"endpoint": client.Endpoint,
    77  	}
    78  
    79  	const APIVersion = "2020-08-01-preview"
    80  	queryParameters := map[string]interface{}{
    81  		"api-version": APIVersion,
    82  	}
    83  
    84  	preparer := autorest.CreatePreparer(
    85  		autorest.AsContentType("application/json; charset=utf-8"),
    86  		autorest.AsPost(),
    87  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
    88  		autorest.WithPath("/checkAccessSynapseRbac"),
    89  		autorest.WithJSON(request),
    90  		autorest.WithQueryParameters(queryParameters))
    91  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    92  }
    93  
    94  // CheckPrincipalAccessSender sends the CheckPrincipalAccess request. The method will close the
    95  // http.Response Body if it receives an error.
    96  func (client RoleAssignmentsClient) CheckPrincipalAccessSender(req *http.Request) (*http.Response, error) {
    97  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    98  }
    99  
   100  // CheckPrincipalAccessResponder handles the response to the CheckPrincipalAccess request. The method always
   101  // closes the http.Response Body.
   102  func (client RoleAssignmentsClient) CheckPrincipalAccessResponder(resp *http.Response) (result CheckPrincipalAccessResponse, err error) {
   103  	err = autorest.Respond(
   104  		resp,
   105  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   106  		autorest.ByUnmarshallingJSON(&result),
   107  		autorest.ByClosing())
   108  	result.Response = autorest.Response{Response: resp}
   109  	return
   110  }
   111  
   112  // CreateRoleAssignment create role assignment.
   113  // Parameters:
   114  // request - details of role id, scope and object id.
   115  // roleAssignmentID - the ID of the role assignment.
   116  func (client RoleAssignmentsClient) CreateRoleAssignment(ctx context.Context, request RoleAssignmentRequest, roleAssignmentID string) (result RoleAssignmentDetails, err error) {
   117  	if tracing.IsEnabled() {
   118  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleAssignmentsClient.CreateRoleAssignment")
   119  		defer func() {
   120  			sc := -1
   121  			if result.Response.Response != nil {
   122  				sc = result.Response.Response.StatusCode
   123  			}
   124  			tracing.EndSpan(ctx, sc, err)
   125  		}()
   126  	}
   127  	if err := validation.Validate([]validation.Validation{
   128  		{TargetValue: request,
   129  			Constraints: []validation.Constraint{{Target: "request.RoleID", Name: validation.Null, Rule: true, Chain: nil},
   130  				{Target: "request.PrincipalID", Name: validation.Null, Rule: true, Chain: nil},
   131  				{Target: "request.Scope", Name: validation.Null, Rule: true, Chain: nil}}},
   132  		{TargetValue: roleAssignmentID,
   133  			Constraints: []validation.Constraint{{Target: "roleAssignmentID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   134  		return result, validation.NewError("accesscontrol.RoleAssignmentsClient", "CreateRoleAssignment", err.Error())
   135  	}
   136  
   137  	req, err := client.CreateRoleAssignmentPreparer(ctx, request, roleAssignmentID)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "CreateRoleAssignment", nil, "Failure preparing request")
   140  		return
   141  	}
   142  
   143  	resp, err := client.CreateRoleAssignmentSender(req)
   144  	if err != nil {
   145  		result.Response = autorest.Response{Response: resp}
   146  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "CreateRoleAssignment", resp, "Failure sending request")
   147  		return
   148  	}
   149  
   150  	result, err = client.CreateRoleAssignmentResponder(resp)
   151  	if err != nil {
   152  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "CreateRoleAssignment", resp, "Failure responding to request")
   153  		return
   154  	}
   155  
   156  	return
   157  }
   158  
   159  // CreateRoleAssignmentPreparer prepares the CreateRoleAssignment request.
   160  func (client RoleAssignmentsClient) CreateRoleAssignmentPreparer(ctx context.Context, request RoleAssignmentRequest, roleAssignmentID string) (*http.Request, error) {
   161  	urlParameters := map[string]interface{}{
   162  		"endpoint": client.Endpoint,
   163  	}
   164  
   165  	pathParameters := map[string]interface{}{
   166  		"roleAssignmentId": autorest.Encode("path", roleAssignmentID),
   167  	}
   168  
   169  	const APIVersion = "2020-08-01-preview"
   170  	queryParameters := map[string]interface{}{
   171  		"api-version": APIVersion,
   172  	}
   173  
   174  	preparer := autorest.CreatePreparer(
   175  		autorest.AsContentType("application/json; charset=utf-8"),
   176  		autorest.AsPut(),
   177  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
   178  		autorest.WithPathParameters("/roleAssignments/{roleAssignmentId}", pathParameters),
   179  		autorest.WithJSON(request),
   180  		autorest.WithQueryParameters(queryParameters))
   181  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   182  }
   183  
   184  // CreateRoleAssignmentSender sends the CreateRoleAssignment request. The method will close the
   185  // http.Response Body if it receives an error.
   186  func (client RoleAssignmentsClient) CreateRoleAssignmentSender(req *http.Request) (*http.Response, error) {
   187  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   188  }
   189  
   190  // CreateRoleAssignmentResponder handles the response to the CreateRoleAssignment request. The method always
   191  // closes the http.Response Body.
   192  func (client RoleAssignmentsClient) CreateRoleAssignmentResponder(resp *http.Response) (result RoleAssignmentDetails, err error) {
   193  	err = autorest.Respond(
   194  		resp,
   195  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   196  		autorest.ByUnmarshallingJSON(&result),
   197  		autorest.ByClosing())
   198  	result.Response = autorest.Response{Response: resp}
   199  	return
   200  }
   201  
   202  // DeleteRoleAssignmentByID delete role assignment by role assignment Id.
   203  // Parameters:
   204  // roleAssignmentID - the ID of the role assignment.
   205  // scope - scope of the Synapse Built-in Role.
   206  func (client RoleAssignmentsClient) DeleteRoleAssignmentByID(ctx context.Context, roleAssignmentID string, scope string) (result autorest.Response, err error) {
   207  	if tracing.IsEnabled() {
   208  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleAssignmentsClient.DeleteRoleAssignmentByID")
   209  		defer func() {
   210  			sc := -1
   211  			if result.Response != nil {
   212  				sc = result.Response.StatusCode
   213  			}
   214  			tracing.EndSpan(ctx, sc, err)
   215  		}()
   216  	}
   217  	if err := validation.Validate([]validation.Validation{
   218  		{TargetValue: roleAssignmentID,
   219  			Constraints: []validation.Constraint{{Target: "roleAssignmentID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   220  		return result, validation.NewError("accesscontrol.RoleAssignmentsClient", "DeleteRoleAssignmentByID", err.Error())
   221  	}
   222  
   223  	req, err := client.DeleteRoleAssignmentByIDPreparer(ctx, roleAssignmentID, scope)
   224  	if err != nil {
   225  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "DeleteRoleAssignmentByID", nil, "Failure preparing request")
   226  		return
   227  	}
   228  
   229  	resp, err := client.DeleteRoleAssignmentByIDSender(req)
   230  	if err != nil {
   231  		result.Response = resp
   232  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "DeleteRoleAssignmentByID", resp, "Failure sending request")
   233  		return
   234  	}
   235  
   236  	result, err = client.DeleteRoleAssignmentByIDResponder(resp)
   237  	if err != nil {
   238  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "DeleteRoleAssignmentByID", resp, "Failure responding to request")
   239  		return
   240  	}
   241  
   242  	return
   243  }
   244  
   245  // DeleteRoleAssignmentByIDPreparer prepares the DeleteRoleAssignmentByID request.
   246  func (client RoleAssignmentsClient) DeleteRoleAssignmentByIDPreparer(ctx context.Context, roleAssignmentID string, scope string) (*http.Request, error) {
   247  	urlParameters := map[string]interface{}{
   248  		"endpoint": client.Endpoint,
   249  	}
   250  
   251  	pathParameters := map[string]interface{}{
   252  		"roleAssignmentId": autorest.Encode("path", roleAssignmentID),
   253  	}
   254  
   255  	const APIVersion = "2020-08-01-preview"
   256  	queryParameters := map[string]interface{}{
   257  		"api-version": APIVersion,
   258  	}
   259  	if len(scope) > 0 {
   260  		queryParameters["scope"] = autorest.Encode("query", scope)
   261  	}
   262  
   263  	preparer := autorest.CreatePreparer(
   264  		autorest.AsDelete(),
   265  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
   266  		autorest.WithPathParameters("/roleAssignments/{roleAssignmentId}", pathParameters),
   267  		autorest.WithQueryParameters(queryParameters))
   268  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   269  }
   270  
   271  // DeleteRoleAssignmentByIDSender sends the DeleteRoleAssignmentByID request. The method will close the
   272  // http.Response Body if it receives an error.
   273  func (client RoleAssignmentsClient) DeleteRoleAssignmentByIDSender(req *http.Request) (*http.Response, error) {
   274  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   275  }
   276  
   277  // DeleteRoleAssignmentByIDResponder handles the response to the DeleteRoleAssignmentByID request. The method always
   278  // closes the http.Response Body.
   279  func (client RoleAssignmentsClient) DeleteRoleAssignmentByIDResponder(resp *http.Response) (result autorest.Response, err error) {
   280  	err = autorest.Respond(
   281  		resp,
   282  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   283  		autorest.ByClosing())
   284  	result.Response = resp
   285  	return
   286  }
   287  
   288  // GetRoleAssignmentByID get role assignment by role assignment Id.
   289  // Parameters:
   290  // roleAssignmentID - the ID of the role assignment.
   291  func (client RoleAssignmentsClient) GetRoleAssignmentByID(ctx context.Context, roleAssignmentID string) (result RoleAssignmentDetails, err error) {
   292  	if tracing.IsEnabled() {
   293  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleAssignmentsClient.GetRoleAssignmentByID")
   294  		defer func() {
   295  			sc := -1
   296  			if result.Response.Response != nil {
   297  				sc = result.Response.Response.StatusCode
   298  			}
   299  			tracing.EndSpan(ctx, sc, err)
   300  		}()
   301  	}
   302  	if err := validation.Validate([]validation.Validation{
   303  		{TargetValue: roleAssignmentID,
   304  			Constraints: []validation.Constraint{{Target: "roleAssignmentID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   305  		return result, validation.NewError("accesscontrol.RoleAssignmentsClient", "GetRoleAssignmentByID", err.Error())
   306  	}
   307  
   308  	req, err := client.GetRoleAssignmentByIDPreparer(ctx, roleAssignmentID)
   309  	if err != nil {
   310  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "GetRoleAssignmentByID", nil, "Failure preparing request")
   311  		return
   312  	}
   313  
   314  	resp, err := client.GetRoleAssignmentByIDSender(req)
   315  	if err != nil {
   316  		result.Response = autorest.Response{Response: resp}
   317  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "GetRoleAssignmentByID", resp, "Failure sending request")
   318  		return
   319  	}
   320  
   321  	result, err = client.GetRoleAssignmentByIDResponder(resp)
   322  	if err != nil {
   323  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "GetRoleAssignmentByID", resp, "Failure responding to request")
   324  		return
   325  	}
   326  
   327  	return
   328  }
   329  
   330  // GetRoleAssignmentByIDPreparer prepares the GetRoleAssignmentByID request.
   331  func (client RoleAssignmentsClient) GetRoleAssignmentByIDPreparer(ctx context.Context, roleAssignmentID string) (*http.Request, error) {
   332  	urlParameters := map[string]interface{}{
   333  		"endpoint": client.Endpoint,
   334  	}
   335  
   336  	pathParameters := map[string]interface{}{
   337  		"roleAssignmentId": autorest.Encode("path", roleAssignmentID),
   338  	}
   339  
   340  	const APIVersion = "2020-08-01-preview"
   341  	queryParameters := map[string]interface{}{
   342  		"api-version": APIVersion,
   343  	}
   344  
   345  	preparer := autorest.CreatePreparer(
   346  		autorest.AsGet(),
   347  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
   348  		autorest.WithPathParameters("/roleAssignments/{roleAssignmentId}", pathParameters),
   349  		autorest.WithQueryParameters(queryParameters))
   350  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   351  }
   352  
   353  // GetRoleAssignmentByIDSender sends the GetRoleAssignmentByID request. The method will close the
   354  // http.Response Body if it receives an error.
   355  func (client RoleAssignmentsClient) GetRoleAssignmentByIDSender(req *http.Request) (*http.Response, error) {
   356  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   357  }
   358  
   359  // GetRoleAssignmentByIDResponder handles the response to the GetRoleAssignmentByID request. The method always
   360  // closes the http.Response Body.
   361  func (client RoleAssignmentsClient) GetRoleAssignmentByIDResponder(resp *http.Response) (result RoleAssignmentDetails, err error) {
   362  	err = autorest.Respond(
   363  		resp,
   364  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   365  		autorest.ByUnmarshallingJSON(&result),
   366  		autorest.ByClosing())
   367  	result.Response = autorest.Response{Response: resp}
   368  	return
   369  }
   370  
   371  // ListRoleAssignments list role assignments.
   372  // Parameters:
   373  // roleID - synapse Built-In Role Id.
   374  // principalID - object ID of the AAD principal or security-group.
   375  // scope - scope of the Synapse Built-in Role.
   376  // continuationToken - continuation token.
   377  func (client RoleAssignmentsClient) ListRoleAssignments(ctx context.Context, roleID string, principalID string, scope string, continuationToken string) (result RoleAssignmentDetailsList, err error) {
   378  	if tracing.IsEnabled() {
   379  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleAssignmentsClient.ListRoleAssignments")
   380  		defer func() {
   381  			sc := -1
   382  			if result.Response.Response != nil {
   383  				sc = result.Response.Response.StatusCode
   384  			}
   385  			tracing.EndSpan(ctx, sc, err)
   386  		}()
   387  	}
   388  	req, err := client.ListRoleAssignmentsPreparer(ctx, roleID, principalID, scope, continuationToken)
   389  	if err != nil {
   390  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "ListRoleAssignments", nil, "Failure preparing request")
   391  		return
   392  	}
   393  
   394  	resp, err := client.ListRoleAssignmentsSender(req)
   395  	if err != nil {
   396  		result.Response = autorest.Response{Response: resp}
   397  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "ListRoleAssignments", resp, "Failure sending request")
   398  		return
   399  	}
   400  
   401  	result, err = client.ListRoleAssignmentsResponder(resp)
   402  	if err != nil {
   403  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleAssignmentsClient", "ListRoleAssignments", resp, "Failure responding to request")
   404  		return
   405  	}
   406  
   407  	return
   408  }
   409  
   410  // ListRoleAssignmentsPreparer prepares the ListRoleAssignments request.
   411  func (client RoleAssignmentsClient) ListRoleAssignmentsPreparer(ctx context.Context, roleID string, principalID string, scope string, continuationToken string) (*http.Request, error) {
   412  	urlParameters := map[string]interface{}{
   413  		"endpoint": client.Endpoint,
   414  	}
   415  
   416  	const APIVersion = "2020-08-01-preview"
   417  	queryParameters := map[string]interface{}{
   418  		"api-version": APIVersion,
   419  	}
   420  	if len(roleID) > 0 {
   421  		queryParameters["roleId"] = autorest.Encode("query", roleID)
   422  	}
   423  	if len(principalID) > 0 {
   424  		queryParameters["principalId"] = autorest.Encode("query", principalID)
   425  	}
   426  	if len(scope) > 0 {
   427  		queryParameters["scope"] = autorest.Encode("query", scope)
   428  	}
   429  
   430  	preparer := autorest.CreatePreparer(
   431  		autorest.AsGet(),
   432  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
   433  		autorest.WithPath("/roleAssignments"),
   434  		autorest.WithQueryParameters(queryParameters))
   435  	if len(continuationToken) > 0 {
   436  		preparer = autorest.DecoratePreparer(preparer,
   437  			autorest.WithHeader("x-ms-continuation", autorest.String(continuationToken)))
   438  	}
   439  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   440  }
   441  
   442  // ListRoleAssignmentsSender sends the ListRoleAssignments request. The method will close the
   443  // http.Response Body if it receives an error.
   444  func (client RoleAssignmentsClient) ListRoleAssignmentsSender(req *http.Request) (*http.Response, error) {
   445  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   446  }
   447  
   448  // ListRoleAssignmentsResponder handles the response to the ListRoleAssignments request. The method always
   449  // closes the http.Response Body.
   450  func (client RoleAssignmentsClient) ListRoleAssignmentsResponder(resp *http.Response) (result RoleAssignmentDetailsList, err error) {
   451  	err = autorest.Respond(
   452  		resp,
   453  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   454  		autorest.ByUnmarshallingJSON(&result),
   455  		autorest.ByClosing())
   456  	result.Response = autorest.Response{Response: resp}
   457  	return
   458  }
   459  

View as plain text