...

Source file src/github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac/deletedapplications.go

Documentation: github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac

     1  package graphrbac
     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/to"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // DeletedApplicationsClient is the the Graph RBAC Management Client
    19  type DeletedApplicationsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewDeletedApplicationsClient creates an instance of the DeletedApplicationsClient client.
    24  func NewDeletedApplicationsClient(tenantID string) DeletedApplicationsClient {
    25  	return NewDeletedApplicationsClientWithBaseURI(DefaultBaseURI, tenantID)
    26  }
    27  
    28  // NewDeletedApplicationsClientWithBaseURI creates an instance of the DeletedApplicationsClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewDeletedApplicationsClientWithBaseURI(baseURI string, tenantID string) DeletedApplicationsClient {
    32  	return DeletedApplicationsClient{NewWithBaseURI(baseURI, tenantID)}
    33  }
    34  
    35  // HardDelete hard-delete an application.
    36  // Parameters:
    37  // applicationObjectID - application object ID.
    38  func (client DeletedApplicationsClient) HardDelete(ctx context.Context, applicationObjectID string) (result autorest.Response, err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/DeletedApplicationsClient.HardDelete")
    41  		defer func() {
    42  			sc := -1
    43  			if result.Response != nil {
    44  				sc = result.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	req, err := client.HardDeletePreparer(ctx, applicationObjectID)
    50  	if err != nil {
    51  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "HardDelete", nil, "Failure preparing request")
    52  		return
    53  	}
    54  
    55  	resp, err := client.HardDeleteSender(req)
    56  	if err != nil {
    57  		result.Response = resp
    58  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "HardDelete", resp, "Failure sending request")
    59  		return
    60  	}
    61  
    62  	result, err = client.HardDeleteResponder(resp)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "HardDelete", resp, "Failure responding to request")
    65  		return
    66  	}
    67  
    68  	return
    69  }
    70  
    71  // HardDeletePreparer prepares the HardDelete request.
    72  func (client DeletedApplicationsClient) HardDeletePreparer(ctx context.Context, applicationObjectID string) (*http.Request, error) {
    73  	pathParameters := map[string]interface{}{
    74  		"applicationObjectId": autorest.Encode("path", applicationObjectID),
    75  		"tenantID":            autorest.Encode("path", client.TenantID),
    76  	}
    77  
    78  	const APIVersion = "1.6"
    79  	queryParameters := map[string]interface{}{
    80  		"api-version": APIVersion,
    81  	}
    82  
    83  	preparer := autorest.CreatePreparer(
    84  		autorest.AsDelete(),
    85  		autorest.WithBaseURL(client.BaseURI),
    86  		autorest.WithPathParameters("/{tenantID}/deletedApplications/{applicationObjectId}", pathParameters),
    87  		autorest.WithQueryParameters(queryParameters))
    88  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    89  }
    90  
    91  // HardDeleteSender sends the HardDelete request. The method will close the
    92  // http.Response Body if it receives an error.
    93  func (client DeletedApplicationsClient) HardDeleteSender(req *http.Request) (*http.Response, error) {
    94  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    95  }
    96  
    97  // HardDeleteResponder handles the response to the HardDelete request. The method always
    98  // closes the http.Response Body.
    99  func (client DeletedApplicationsClient) HardDeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   100  	err = autorest.Respond(
   101  		resp,
   102  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   103  		autorest.ByClosing())
   104  	result.Response = resp
   105  	return
   106  }
   107  
   108  // List gets a list of deleted applications in the directory.
   109  // Parameters:
   110  // filter - the filter to apply to the operation.
   111  func (client DeletedApplicationsClient) List(ctx context.Context, filter string) (result ApplicationListResultPage, err error) {
   112  	if tracing.IsEnabled() {
   113  		ctx = tracing.StartSpan(ctx, fqdn+"/DeletedApplicationsClient.List")
   114  		defer func() {
   115  			sc := -1
   116  			if result.alr.Response.Response != nil {
   117  				sc = result.alr.Response.Response.StatusCode
   118  			}
   119  			tracing.EndSpan(ctx, sc, err)
   120  		}()
   121  	}
   122  	result.fn = func(ctx context.Context, lastResult ApplicationListResult) (ApplicationListResult, error) {
   123  		if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 {
   124  			return ApplicationListResult{}, nil
   125  		}
   126  		return client.ListNext(ctx, *lastResult.OdataNextLink)
   127  	}
   128  	req, err := client.ListPreparer(ctx, filter)
   129  	if err != nil {
   130  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "List", nil, "Failure preparing request")
   131  		return
   132  	}
   133  
   134  	resp, err := client.ListSender(req)
   135  	if err != nil {
   136  		result.alr.Response = autorest.Response{Response: resp}
   137  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "List", resp, "Failure sending request")
   138  		return
   139  	}
   140  
   141  	result.alr, err = client.ListResponder(resp)
   142  	if err != nil {
   143  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "List", resp, "Failure responding to request")
   144  		return
   145  	}
   146  	if result.alr.hasNextLink() && result.alr.IsEmpty() {
   147  		err = result.NextWithContext(ctx)
   148  		return
   149  	}
   150  
   151  	return
   152  }
   153  
   154  // ListPreparer prepares the List request.
   155  func (client DeletedApplicationsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) {
   156  	pathParameters := map[string]interface{}{
   157  		"tenantID": autorest.Encode("path", client.TenantID),
   158  	}
   159  
   160  	const APIVersion = "1.6"
   161  	queryParameters := map[string]interface{}{
   162  		"api-version": APIVersion,
   163  	}
   164  	if len(filter) > 0 {
   165  		queryParameters["$filter"] = autorest.Encode("query", filter)
   166  	}
   167  
   168  	preparer := autorest.CreatePreparer(
   169  		autorest.AsGet(),
   170  		autorest.WithBaseURL(client.BaseURI),
   171  		autorest.WithPathParameters("/{tenantID}/deletedApplications", pathParameters),
   172  		autorest.WithQueryParameters(queryParameters))
   173  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   174  }
   175  
   176  // ListSender sends the List request. The method will close the
   177  // http.Response Body if it receives an error.
   178  func (client DeletedApplicationsClient) ListSender(req *http.Request) (*http.Response, error) {
   179  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   180  }
   181  
   182  // ListResponder handles the response to the List request. The method always
   183  // closes the http.Response Body.
   184  func (client DeletedApplicationsClient) ListResponder(resp *http.Response) (result ApplicationListResult, err error) {
   185  	err = autorest.Respond(
   186  		resp,
   187  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   188  		autorest.ByUnmarshallingJSON(&result),
   189  		autorest.ByClosing())
   190  	result.Response = autorest.Response{Response: resp}
   191  	return
   192  }
   193  
   194  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   195  func (client DeletedApplicationsClient) ListComplete(ctx context.Context, filter string) (result ApplicationListResultIterator, err error) {
   196  	if tracing.IsEnabled() {
   197  		ctx = tracing.StartSpan(ctx, fqdn+"/DeletedApplicationsClient.List")
   198  		defer func() {
   199  			sc := -1
   200  			if result.Response().Response.Response != nil {
   201  				sc = result.page.Response().Response.Response.StatusCode
   202  			}
   203  			tracing.EndSpan(ctx, sc, err)
   204  		}()
   205  	}
   206  	result.page, err = client.List(ctx, filter)
   207  	return
   208  }
   209  
   210  // ListNext gets a list of deleted applications in the directory.
   211  // Parameters:
   212  // nextLink - next link for the list operation.
   213  func (client DeletedApplicationsClient) ListNext(ctx context.Context, nextLink string) (result ApplicationListResult, err error) {
   214  	if tracing.IsEnabled() {
   215  		ctx = tracing.StartSpan(ctx, fqdn+"/DeletedApplicationsClient.ListNext")
   216  		defer func() {
   217  			sc := -1
   218  			if result.Response.Response != nil {
   219  				sc = result.Response.Response.StatusCode
   220  			}
   221  			tracing.EndSpan(ctx, sc, err)
   222  		}()
   223  	}
   224  	req, err := client.ListNextPreparer(ctx, nextLink)
   225  	if err != nil {
   226  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "ListNext", nil, "Failure preparing request")
   227  		return
   228  	}
   229  
   230  	resp, err := client.ListNextSender(req)
   231  	if err != nil {
   232  		result.Response = autorest.Response{Response: resp}
   233  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "ListNext", resp, "Failure sending request")
   234  		return
   235  	}
   236  
   237  	result, err = client.ListNextResponder(resp)
   238  	if err != nil {
   239  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "ListNext", resp, "Failure responding to request")
   240  		return
   241  	}
   242  
   243  	return
   244  }
   245  
   246  // ListNextPreparer prepares the ListNext request.
   247  func (client DeletedApplicationsClient) ListNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) {
   248  	pathParameters := map[string]interface{}{
   249  		"nextLink": nextLink,
   250  		"tenantID": autorest.Encode("path", client.TenantID),
   251  	}
   252  
   253  	const APIVersion = "1.6"
   254  	queryParameters := map[string]interface{}{
   255  		"api-version": APIVersion,
   256  	}
   257  
   258  	preparer := autorest.CreatePreparer(
   259  		autorest.AsGet(),
   260  		autorest.WithBaseURL(client.BaseURI),
   261  		autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters),
   262  		autorest.WithQueryParameters(queryParameters))
   263  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   264  }
   265  
   266  // ListNextSender sends the ListNext request. The method will close the
   267  // http.Response Body if it receives an error.
   268  func (client DeletedApplicationsClient) ListNextSender(req *http.Request) (*http.Response, error) {
   269  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   270  }
   271  
   272  // ListNextResponder handles the response to the ListNext request. The method always
   273  // closes the http.Response Body.
   274  func (client DeletedApplicationsClient) ListNextResponder(resp *http.Response) (result ApplicationListResult, err error) {
   275  	err = autorest.Respond(
   276  		resp,
   277  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   278  		autorest.ByUnmarshallingJSON(&result),
   279  		autorest.ByClosing())
   280  	result.Response = autorest.Response{Response: resp}
   281  	return
   282  }
   283  
   284  // Restore restores the deleted application in the directory.
   285  // Parameters:
   286  // objectID - application object ID.
   287  func (client DeletedApplicationsClient) Restore(ctx context.Context, objectID string) (result Application, err error) {
   288  	if tracing.IsEnabled() {
   289  		ctx = tracing.StartSpan(ctx, fqdn+"/DeletedApplicationsClient.Restore")
   290  		defer func() {
   291  			sc := -1
   292  			if result.Response.Response != nil {
   293  				sc = result.Response.Response.StatusCode
   294  			}
   295  			tracing.EndSpan(ctx, sc, err)
   296  		}()
   297  	}
   298  	req, err := client.RestorePreparer(ctx, objectID)
   299  	if err != nil {
   300  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "Restore", nil, "Failure preparing request")
   301  		return
   302  	}
   303  
   304  	resp, err := client.RestoreSender(req)
   305  	if err != nil {
   306  		result.Response = autorest.Response{Response: resp}
   307  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "Restore", resp, "Failure sending request")
   308  		return
   309  	}
   310  
   311  	result, err = client.RestoreResponder(resp)
   312  	if err != nil {
   313  		err = autorest.NewErrorWithError(err, "graphrbac.DeletedApplicationsClient", "Restore", resp, "Failure responding to request")
   314  		return
   315  	}
   316  
   317  	return
   318  }
   319  
   320  // RestorePreparer prepares the Restore request.
   321  func (client DeletedApplicationsClient) RestorePreparer(ctx context.Context, objectID string) (*http.Request, error) {
   322  	pathParameters := map[string]interface{}{
   323  		"objectId": autorest.Encode("path", objectID),
   324  		"tenantID": autorest.Encode("path", client.TenantID),
   325  	}
   326  
   327  	const APIVersion = "1.6"
   328  	queryParameters := map[string]interface{}{
   329  		"api-version": APIVersion,
   330  	}
   331  
   332  	preparer := autorest.CreatePreparer(
   333  		autorest.AsPost(),
   334  		autorest.WithBaseURL(client.BaseURI),
   335  		autorest.WithPathParameters("/{tenantID}/deletedApplications/{objectId}/restore", pathParameters),
   336  		autorest.WithQueryParameters(queryParameters))
   337  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   338  }
   339  
   340  // RestoreSender sends the Restore request. The method will close the
   341  // http.Response Body if it receives an error.
   342  func (client DeletedApplicationsClient) RestoreSender(req *http.Request) (*http.Response, error) {
   343  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   344  }
   345  
   346  // RestoreResponder handles the response to the Restore request. The method always
   347  // closes the http.Response Body.
   348  func (client DeletedApplicationsClient) RestoreResponder(resp *http.Response) (result Application, err error) {
   349  	err = autorest.Respond(
   350  		resp,
   351  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   352  		autorest.ByUnmarshallingJSON(&result),
   353  		autorest.ByClosing())
   354  	result.Response = autorest.Response{Response: resp}
   355  	return
   356  }
   357  

View as plain text