...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/synapse/2020-08-01-preview/accesscontrol/roledefinitions.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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // RoleDefinitionsClient is the client for the RoleDefinitions methods of the Accesscontrol service.
    18  type RoleDefinitionsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewRoleDefinitionsClient creates an instance of the RoleDefinitionsClient client.
    23  func NewRoleDefinitionsClient(endpoint string) RoleDefinitionsClient {
    24  	return RoleDefinitionsClient{New(endpoint)}
    25  }
    26  
    27  // GetRoleDefinitionByID get role definition by role definition Id.
    28  // Parameters:
    29  // roleDefinitionID - synapse Built-In Role Definition Id.
    30  func (client RoleDefinitionsClient) GetRoleDefinitionByID(ctx context.Context, roleDefinitionID string) (result SynapseRoleDefinition, err error) {
    31  	if tracing.IsEnabled() {
    32  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleDefinitionsClient.GetRoleDefinitionByID")
    33  		defer func() {
    34  			sc := -1
    35  			if result.Response.Response != nil {
    36  				sc = result.Response.Response.StatusCode
    37  			}
    38  			tracing.EndSpan(ctx, sc, err)
    39  		}()
    40  	}
    41  	req, err := client.GetRoleDefinitionByIDPreparer(ctx, roleDefinitionID)
    42  	if err != nil {
    43  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "GetRoleDefinitionByID", nil, "Failure preparing request")
    44  		return
    45  	}
    46  
    47  	resp, err := client.GetRoleDefinitionByIDSender(req)
    48  	if err != nil {
    49  		result.Response = autorest.Response{Response: resp}
    50  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "GetRoleDefinitionByID", resp, "Failure sending request")
    51  		return
    52  	}
    53  
    54  	result, err = client.GetRoleDefinitionByIDResponder(resp)
    55  	if err != nil {
    56  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "GetRoleDefinitionByID", resp, "Failure responding to request")
    57  		return
    58  	}
    59  
    60  	return
    61  }
    62  
    63  // GetRoleDefinitionByIDPreparer prepares the GetRoleDefinitionByID request.
    64  func (client RoleDefinitionsClient) GetRoleDefinitionByIDPreparer(ctx context.Context, roleDefinitionID string) (*http.Request, error) {
    65  	urlParameters := map[string]interface{}{
    66  		"endpoint": client.Endpoint,
    67  	}
    68  
    69  	pathParameters := map[string]interface{}{
    70  		"roleDefinitionId": autorest.Encode("path", roleDefinitionID),
    71  	}
    72  
    73  	const APIVersion = "2020-08-01-preview"
    74  	queryParameters := map[string]interface{}{
    75  		"api-version": APIVersion,
    76  	}
    77  
    78  	preparer := autorest.CreatePreparer(
    79  		autorest.AsGet(),
    80  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
    81  		autorest.WithPathParameters("/roleDefinitions/{roleDefinitionId}", pathParameters),
    82  		autorest.WithQueryParameters(queryParameters))
    83  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    84  }
    85  
    86  // GetRoleDefinitionByIDSender sends the GetRoleDefinitionByID request. The method will close the
    87  // http.Response Body if it receives an error.
    88  func (client RoleDefinitionsClient) GetRoleDefinitionByIDSender(req *http.Request) (*http.Response, error) {
    89  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    90  }
    91  
    92  // GetRoleDefinitionByIDResponder handles the response to the GetRoleDefinitionByID request. The method always
    93  // closes the http.Response Body.
    94  func (client RoleDefinitionsClient) GetRoleDefinitionByIDResponder(resp *http.Response) (result SynapseRoleDefinition, err error) {
    95  	err = autorest.Respond(
    96  		resp,
    97  		azure.WithErrorUnlessStatusCode(http.StatusOK),
    98  		autorest.ByUnmarshallingJSON(&result),
    99  		autorest.ByClosing())
   100  	result.Response = autorest.Response{Response: resp}
   101  	return
   102  }
   103  
   104  // ListRoleDefinitions list role definitions.
   105  // Parameters:
   106  // isBuiltIn - is a Synapse Built-In Role or not.
   107  // scope - scope of the Synapse Built-in Role.
   108  func (client RoleDefinitionsClient) ListRoleDefinitions(ctx context.Context, isBuiltIn *bool, scope string) (result ListSynapseRoleDefinition, err error) {
   109  	if tracing.IsEnabled() {
   110  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleDefinitionsClient.ListRoleDefinitions")
   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.ListRoleDefinitionsPreparer(ctx, isBuiltIn, scope)
   120  	if err != nil {
   121  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "ListRoleDefinitions", nil, "Failure preparing request")
   122  		return
   123  	}
   124  
   125  	resp, err := client.ListRoleDefinitionsSender(req)
   126  	if err != nil {
   127  		result.Response = autorest.Response{Response: resp}
   128  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "ListRoleDefinitions", resp, "Failure sending request")
   129  		return
   130  	}
   131  
   132  	result, err = client.ListRoleDefinitionsResponder(resp)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "ListRoleDefinitions", resp, "Failure responding to request")
   135  		return
   136  	}
   137  
   138  	return
   139  }
   140  
   141  // ListRoleDefinitionsPreparer prepares the ListRoleDefinitions request.
   142  func (client RoleDefinitionsClient) ListRoleDefinitionsPreparer(ctx context.Context, isBuiltIn *bool, scope string) (*http.Request, error) {
   143  	urlParameters := map[string]interface{}{
   144  		"endpoint": client.Endpoint,
   145  	}
   146  
   147  	const APIVersion = "2020-08-01-preview"
   148  	queryParameters := map[string]interface{}{
   149  		"api-version": APIVersion,
   150  	}
   151  	if isBuiltIn != nil {
   152  		queryParameters["isBuiltIn"] = autorest.Encode("query", *isBuiltIn)
   153  	}
   154  	if len(scope) > 0 {
   155  		queryParameters["scope"] = autorest.Encode("query", scope)
   156  	}
   157  
   158  	preparer := autorest.CreatePreparer(
   159  		autorest.AsGet(),
   160  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
   161  		autorest.WithPath("/roleDefinitions"),
   162  		autorest.WithQueryParameters(queryParameters))
   163  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   164  }
   165  
   166  // ListRoleDefinitionsSender sends the ListRoleDefinitions request. The method will close the
   167  // http.Response Body if it receives an error.
   168  func (client RoleDefinitionsClient) ListRoleDefinitionsSender(req *http.Request) (*http.Response, error) {
   169  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   170  }
   171  
   172  // ListRoleDefinitionsResponder handles the response to the ListRoleDefinitions request. The method always
   173  // closes the http.Response Body.
   174  func (client RoleDefinitionsClient) ListRoleDefinitionsResponder(resp *http.Response) (result ListSynapseRoleDefinition, err error) {
   175  	err = autorest.Respond(
   176  		resp,
   177  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   178  		autorest.ByUnmarshallingJSON(&result.Value),
   179  		autorest.ByClosing())
   180  	result.Response = autorest.Response{Response: resp}
   181  	return
   182  }
   183  
   184  // ListScopes list rbac scopes.
   185  func (client RoleDefinitionsClient) ListScopes(ctx context.Context) (result ListString, err error) {
   186  	if tracing.IsEnabled() {
   187  		ctx = tracing.StartSpan(ctx, fqdn+"/RoleDefinitionsClient.ListScopes")
   188  		defer func() {
   189  			sc := -1
   190  			if result.Response.Response != nil {
   191  				sc = result.Response.Response.StatusCode
   192  			}
   193  			tracing.EndSpan(ctx, sc, err)
   194  		}()
   195  	}
   196  	req, err := client.ListScopesPreparer(ctx)
   197  	if err != nil {
   198  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "ListScopes", nil, "Failure preparing request")
   199  		return
   200  	}
   201  
   202  	resp, err := client.ListScopesSender(req)
   203  	if err != nil {
   204  		result.Response = autorest.Response{Response: resp}
   205  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "ListScopes", resp, "Failure sending request")
   206  		return
   207  	}
   208  
   209  	result, err = client.ListScopesResponder(resp)
   210  	if err != nil {
   211  		err = autorest.NewErrorWithError(err, "accesscontrol.RoleDefinitionsClient", "ListScopes", resp, "Failure responding to request")
   212  		return
   213  	}
   214  
   215  	return
   216  }
   217  
   218  // ListScopesPreparer prepares the ListScopes request.
   219  func (client RoleDefinitionsClient) ListScopesPreparer(ctx context.Context) (*http.Request, error) {
   220  	urlParameters := map[string]interface{}{
   221  		"endpoint": client.Endpoint,
   222  	}
   223  
   224  	const APIVersion = "2020-08-01-preview"
   225  	queryParameters := map[string]interface{}{
   226  		"api-version": APIVersion,
   227  	}
   228  
   229  	preparer := autorest.CreatePreparer(
   230  		autorest.AsGet(),
   231  		autorest.WithCustomBaseURL("{endpoint}", urlParameters),
   232  		autorest.WithPath("/rbacScopes"),
   233  		autorest.WithQueryParameters(queryParameters))
   234  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   235  }
   236  
   237  // ListScopesSender sends the ListScopes request. The method will close the
   238  // http.Response Body if it receives an error.
   239  func (client RoleDefinitionsClient) ListScopesSender(req *http.Request) (*http.Response, error) {
   240  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   241  }
   242  
   243  // ListScopesResponder handles the response to the ListScopes request. The method always
   244  // closes the http.Response Body.
   245  func (client RoleDefinitionsClient) ListScopesResponder(resp *http.Response) (result ListString, err error) {
   246  	err = autorest.Respond(
   247  		resp,
   248  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   249  		autorest.ByUnmarshallingJSON(&result.Value),
   250  		autorest.ByClosing())
   251  	result.Response = autorest.Response{Response: resp}
   252  	return
   253  }
   254  

View as plain text