1package graphrbac
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/to"
25	"github.com/Azure/go-autorest/autorest/validation"
26	"github.com/Azure/go-autorest/tracing"
27	"net/http"
28)
29
30// ServicePrincipalsClient is the the Graph RBAC Management Client
31type ServicePrincipalsClient struct {
32	BaseClient
33}
34
35// NewServicePrincipalsClient creates an instance of the ServicePrincipalsClient client.
36func NewServicePrincipalsClient(tenantID string) ServicePrincipalsClient {
37	return NewServicePrincipalsClientWithBaseURI(DefaultBaseURI, tenantID)
38}
39
40// NewServicePrincipalsClientWithBaseURI creates an instance of the ServicePrincipalsClient client using a custom
41// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
42// stack).
43func NewServicePrincipalsClientWithBaseURI(baseURI string, tenantID string) ServicePrincipalsClient {
44	return ServicePrincipalsClient{NewWithBaseURI(baseURI, tenantID)}
45}
46
47// Create creates a service principal in the directory.
48// Parameters:
49// parameters - parameters to create a service principal.
50func (client ServicePrincipalsClient) Create(ctx context.Context, parameters ServicePrincipalCreateParameters) (result ServicePrincipal, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.Create")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	if err := validation.Validate([]validation.Validation{
62		{TargetValue: parameters,
63			Constraints: []validation.Constraint{{Target: "parameters.AppID", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
64		return result, validation.NewError("graphrbac.ServicePrincipalsClient", "Create", err.Error())
65	}
66
67	req, err := client.CreatePreparer(ctx, parameters)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Create", nil, "Failure preparing request")
70		return
71	}
72
73	resp, err := client.CreateSender(req)
74	if err != nil {
75		result.Response = autorest.Response{Response: resp}
76		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Create", resp, "Failure sending request")
77		return
78	}
79
80	result, err = client.CreateResponder(resp)
81	if err != nil {
82		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Create", resp, "Failure responding to request")
83		return
84	}
85
86	return
87}
88
89// CreatePreparer prepares the Create request.
90func (client ServicePrincipalsClient) CreatePreparer(ctx context.Context, parameters ServicePrincipalCreateParameters) (*http.Request, error) {
91	pathParameters := map[string]interface{}{
92		"tenantID": autorest.Encode("path", client.TenantID),
93	}
94
95	const APIVersion = "1.6"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsContentType("application/json; charset=utf-8"),
102		autorest.AsPost(),
103		autorest.WithBaseURL(client.BaseURI),
104		autorest.WithPathParameters("/{tenantID}/servicePrincipals", pathParameters),
105		autorest.WithJSON(parameters),
106		autorest.WithQueryParameters(queryParameters))
107	return preparer.Prepare((&http.Request{}).WithContext(ctx))
108}
109
110// CreateSender sends the Create request. The method will close the
111// http.Response Body if it receives an error.
112func (client ServicePrincipalsClient) CreateSender(req *http.Request) (*http.Response, error) {
113	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
114}
115
116// CreateResponder handles the response to the Create request. The method always
117// closes the http.Response Body.
118func (client ServicePrincipalsClient) CreateResponder(resp *http.Response) (result ServicePrincipal, err error) {
119	err = autorest.Respond(
120		resp,
121		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// Delete deletes a service principal from the directory.
129// Parameters:
130// objectID - the object ID of the service principal to delete.
131func (client ServicePrincipalsClient) Delete(ctx context.Context, objectID string) (result autorest.Response, err error) {
132	if tracing.IsEnabled() {
133		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.Delete")
134		defer func() {
135			sc := -1
136			if result.Response != nil {
137				sc = result.Response.StatusCode
138			}
139			tracing.EndSpan(ctx, sc, err)
140		}()
141	}
142	req, err := client.DeletePreparer(ctx, objectID)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Delete", nil, "Failure preparing request")
145		return
146	}
147
148	resp, err := client.DeleteSender(req)
149	if err != nil {
150		result.Response = resp
151		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Delete", resp, "Failure sending request")
152		return
153	}
154
155	result, err = client.DeleteResponder(resp)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Delete", resp, "Failure responding to request")
158		return
159	}
160
161	return
162}
163
164// DeletePreparer prepares the Delete request.
165func (client ServicePrincipalsClient) DeletePreparer(ctx context.Context, objectID string) (*http.Request, error) {
166	pathParameters := map[string]interface{}{
167		"objectId": autorest.Encode("path", objectID),
168		"tenantID": autorest.Encode("path", client.TenantID),
169	}
170
171	const APIVersion = "1.6"
172	queryParameters := map[string]interface{}{
173		"api-version": APIVersion,
174	}
175
176	preparer := autorest.CreatePreparer(
177		autorest.AsDelete(),
178		autorest.WithBaseURL(client.BaseURI),
179		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}", pathParameters),
180		autorest.WithQueryParameters(queryParameters))
181	return preparer.Prepare((&http.Request{}).WithContext(ctx))
182}
183
184// DeleteSender sends the Delete request. The method will close the
185// http.Response Body if it receives an error.
186func (client ServicePrincipalsClient) DeleteSender(req *http.Request) (*http.Response, error) {
187	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
188}
189
190// DeleteResponder handles the response to the Delete request. The method always
191// closes the http.Response Body.
192func (client ServicePrincipalsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
193	err = autorest.Respond(
194		resp,
195		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
196		autorest.ByClosing())
197	result.Response = resp
198	return
199}
200
201// Get gets service principal information from the directory. Query by objectId or pass a filter to query by appId
202// Parameters:
203// objectID - the object ID of the service principal to get.
204func (client ServicePrincipalsClient) Get(ctx context.Context, objectID string) (result ServicePrincipal, err error) {
205	if tracing.IsEnabled() {
206		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.Get")
207		defer func() {
208			sc := -1
209			if result.Response.Response != nil {
210				sc = result.Response.Response.StatusCode
211			}
212			tracing.EndSpan(ctx, sc, err)
213		}()
214	}
215	req, err := client.GetPreparer(ctx, objectID)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Get", nil, "Failure preparing request")
218		return
219	}
220
221	resp, err := client.GetSender(req)
222	if err != nil {
223		result.Response = autorest.Response{Response: resp}
224		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Get", resp, "Failure sending request")
225		return
226	}
227
228	result, err = client.GetResponder(resp)
229	if err != nil {
230		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Get", resp, "Failure responding to request")
231		return
232	}
233
234	return
235}
236
237// GetPreparer prepares the Get request.
238func (client ServicePrincipalsClient) GetPreparer(ctx context.Context, objectID string) (*http.Request, error) {
239	pathParameters := map[string]interface{}{
240		"objectId": autorest.Encode("path", objectID),
241		"tenantID": autorest.Encode("path", client.TenantID),
242	}
243
244	const APIVersion = "1.6"
245	queryParameters := map[string]interface{}{
246		"api-version": APIVersion,
247	}
248
249	preparer := autorest.CreatePreparer(
250		autorest.AsGet(),
251		autorest.WithBaseURL(client.BaseURI),
252		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}", pathParameters),
253		autorest.WithQueryParameters(queryParameters))
254	return preparer.Prepare((&http.Request{}).WithContext(ctx))
255}
256
257// GetSender sends the Get request. The method will close the
258// http.Response Body if it receives an error.
259func (client ServicePrincipalsClient) GetSender(req *http.Request) (*http.Response, error) {
260	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
261}
262
263// GetResponder handles the response to the Get request. The method always
264// closes the http.Response Body.
265func (client ServicePrincipalsClient) GetResponder(resp *http.Response) (result ServicePrincipal, err error) {
266	err = autorest.Respond(
267		resp,
268		azure.WithErrorUnlessStatusCode(http.StatusOK),
269		autorest.ByUnmarshallingJSON(&result),
270		autorest.ByClosing())
271	result.Response = autorest.Response{Response: resp}
272	return
273}
274
275// List gets a list of service principals from the current tenant.
276// Parameters:
277// filter - the filter to apply to the operation.
278func (client ServicePrincipalsClient) List(ctx context.Context, filter string) (result ServicePrincipalListResultPage, err error) {
279	if tracing.IsEnabled() {
280		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.List")
281		defer func() {
282			sc := -1
283			if result.splr.Response.Response != nil {
284				sc = result.splr.Response.Response.StatusCode
285			}
286			tracing.EndSpan(ctx, sc, err)
287		}()
288	}
289	result.fn = func(ctx context.Context, lastResult ServicePrincipalListResult) (ServicePrincipalListResult, error) {
290		if lastResult.OdataNextLink == nil || len(to.String(lastResult.OdataNextLink)) < 1 {
291			return ServicePrincipalListResult{}, nil
292		}
293		return client.ListNext(ctx, *lastResult.OdataNextLink)
294	}
295	req, err := client.ListPreparer(ctx, filter)
296	if err != nil {
297		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "List", nil, "Failure preparing request")
298		return
299	}
300
301	resp, err := client.ListSender(req)
302	if err != nil {
303		result.splr.Response = autorest.Response{Response: resp}
304		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "List", resp, "Failure sending request")
305		return
306	}
307
308	result.splr, err = client.ListResponder(resp)
309	if err != nil {
310		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "List", resp, "Failure responding to request")
311		return
312	}
313	if result.splr.hasNextLink() && result.splr.IsEmpty() {
314		err = result.NextWithContext(ctx)
315		return
316	}
317
318	return
319}
320
321// ListPreparer prepares the List request.
322func (client ServicePrincipalsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) {
323	pathParameters := map[string]interface{}{
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	if len(filter) > 0 {
332		queryParameters["$filter"] = autorest.Encode("query", filter)
333	}
334
335	preparer := autorest.CreatePreparer(
336		autorest.AsGet(),
337		autorest.WithBaseURL(client.BaseURI),
338		autorest.WithPathParameters("/{tenantID}/servicePrincipals", pathParameters),
339		autorest.WithQueryParameters(queryParameters))
340	return preparer.Prepare((&http.Request{}).WithContext(ctx))
341}
342
343// ListSender sends the List request. The method will close the
344// http.Response Body if it receives an error.
345func (client ServicePrincipalsClient) ListSender(req *http.Request) (*http.Response, error) {
346	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
347}
348
349// ListResponder handles the response to the List request. The method always
350// closes the http.Response Body.
351func (client ServicePrincipalsClient) ListResponder(resp *http.Response) (result ServicePrincipalListResult, err error) {
352	err = autorest.Respond(
353		resp,
354		azure.WithErrorUnlessStatusCode(http.StatusOK),
355		autorest.ByUnmarshallingJSON(&result),
356		autorest.ByClosing())
357	result.Response = autorest.Response{Response: resp}
358	return
359}
360
361// ListComplete enumerates all values, automatically crossing page boundaries as required.
362func (client ServicePrincipalsClient) ListComplete(ctx context.Context, filter string) (result ServicePrincipalListResultIterator, err error) {
363	if tracing.IsEnabled() {
364		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.List")
365		defer func() {
366			sc := -1
367			if result.Response().Response.Response != nil {
368				sc = result.page.Response().Response.Response.StatusCode
369			}
370			tracing.EndSpan(ctx, sc, err)
371		}()
372	}
373	result.page, err = client.List(ctx, filter)
374	return
375}
376
377// ListKeyCredentials get the keyCredentials associated with the specified service principal.
378// Parameters:
379// objectID - the object ID of the service principal for which to get keyCredentials.
380func (client ServicePrincipalsClient) ListKeyCredentials(ctx context.Context, objectID string) (result KeyCredentialListResult, err error) {
381	if tracing.IsEnabled() {
382		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.ListKeyCredentials")
383		defer func() {
384			sc := -1
385			if result.Response.Response != nil {
386				sc = result.Response.Response.StatusCode
387			}
388			tracing.EndSpan(ctx, sc, err)
389		}()
390	}
391	req, err := client.ListKeyCredentialsPreparer(ctx, objectID)
392	if err != nil {
393		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListKeyCredentials", nil, "Failure preparing request")
394		return
395	}
396
397	resp, err := client.ListKeyCredentialsSender(req)
398	if err != nil {
399		result.Response = autorest.Response{Response: resp}
400		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListKeyCredentials", resp, "Failure sending request")
401		return
402	}
403
404	result, err = client.ListKeyCredentialsResponder(resp)
405	if err != nil {
406		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListKeyCredentials", resp, "Failure responding to request")
407		return
408	}
409
410	return
411}
412
413// ListKeyCredentialsPreparer prepares the ListKeyCredentials request.
414func (client ServicePrincipalsClient) ListKeyCredentialsPreparer(ctx context.Context, objectID string) (*http.Request, error) {
415	pathParameters := map[string]interface{}{
416		"objectId": autorest.Encode("path", objectID),
417		"tenantID": autorest.Encode("path", client.TenantID),
418	}
419
420	const APIVersion = "1.6"
421	queryParameters := map[string]interface{}{
422		"api-version": APIVersion,
423	}
424
425	preparer := autorest.CreatePreparer(
426		autorest.AsGet(),
427		autorest.WithBaseURL(client.BaseURI),
428		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/keyCredentials", pathParameters),
429		autorest.WithQueryParameters(queryParameters))
430	return preparer.Prepare((&http.Request{}).WithContext(ctx))
431}
432
433// ListKeyCredentialsSender sends the ListKeyCredentials request. The method will close the
434// http.Response Body if it receives an error.
435func (client ServicePrincipalsClient) ListKeyCredentialsSender(req *http.Request) (*http.Response, error) {
436	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
437}
438
439// ListKeyCredentialsResponder handles the response to the ListKeyCredentials request. The method always
440// closes the http.Response Body.
441func (client ServicePrincipalsClient) ListKeyCredentialsResponder(resp *http.Response) (result KeyCredentialListResult, err error) {
442	err = autorest.Respond(
443		resp,
444		azure.WithErrorUnlessStatusCode(http.StatusOK),
445		autorest.ByUnmarshallingJSON(&result),
446		autorest.ByClosing())
447	result.Response = autorest.Response{Response: resp}
448	return
449}
450
451// ListNext gets a list of service principals from the current tenant.
452// Parameters:
453// nextLink - next link for the list operation.
454func (client ServicePrincipalsClient) ListNext(ctx context.Context, nextLink string) (result ServicePrincipalListResult, err error) {
455	if tracing.IsEnabled() {
456		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.ListNext")
457		defer func() {
458			sc := -1
459			if result.Response.Response != nil {
460				sc = result.Response.Response.StatusCode
461			}
462			tracing.EndSpan(ctx, sc, err)
463		}()
464	}
465	req, err := client.ListNextPreparer(ctx, nextLink)
466	if err != nil {
467		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListNext", nil, "Failure preparing request")
468		return
469	}
470
471	resp, err := client.ListNextSender(req)
472	if err != nil {
473		result.Response = autorest.Response{Response: resp}
474		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListNext", resp, "Failure sending request")
475		return
476	}
477
478	result, err = client.ListNextResponder(resp)
479	if err != nil {
480		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListNext", resp, "Failure responding to request")
481		return
482	}
483
484	return
485}
486
487// ListNextPreparer prepares the ListNext request.
488func (client ServicePrincipalsClient) ListNextPreparer(ctx context.Context, nextLink string) (*http.Request, error) {
489	pathParameters := map[string]interface{}{
490		"nextLink": nextLink,
491		"tenantID": autorest.Encode("path", client.TenantID),
492	}
493
494	const APIVersion = "1.6"
495	queryParameters := map[string]interface{}{
496		"api-version": APIVersion,
497	}
498
499	preparer := autorest.CreatePreparer(
500		autorest.AsGet(),
501		autorest.WithBaseURL(client.BaseURI),
502		autorest.WithPathParameters("/{tenantID}/{nextLink}", pathParameters),
503		autorest.WithQueryParameters(queryParameters))
504	return preparer.Prepare((&http.Request{}).WithContext(ctx))
505}
506
507// ListNextSender sends the ListNext request. The method will close the
508// http.Response Body if it receives an error.
509func (client ServicePrincipalsClient) ListNextSender(req *http.Request) (*http.Response, error) {
510	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
511}
512
513// ListNextResponder handles the response to the ListNext request. The method always
514// closes the http.Response Body.
515func (client ServicePrincipalsClient) ListNextResponder(resp *http.Response) (result ServicePrincipalListResult, err error) {
516	err = autorest.Respond(
517		resp,
518		azure.WithErrorUnlessStatusCode(http.StatusOK),
519		autorest.ByUnmarshallingJSON(&result),
520		autorest.ByClosing())
521	result.Response = autorest.Response{Response: resp}
522	return
523}
524
525// ListOwners the owners are a set of non-admin users who are allowed to modify this object.
526// Parameters:
527// objectID - the object ID of the service principal for which to get owners.
528func (client ServicePrincipalsClient) ListOwners(ctx context.Context, objectID string) (result DirectoryObjectListResultPage, err error) {
529	if tracing.IsEnabled() {
530		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.ListOwners")
531		defer func() {
532			sc := -1
533			if result.dolr.Response.Response != nil {
534				sc = result.dolr.Response.Response.StatusCode
535			}
536			tracing.EndSpan(ctx, sc, err)
537		}()
538	}
539	result.fn = client.listOwnersNextResults
540	req, err := client.ListOwnersPreparer(ctx, objectID)
541	if err != nil {
542		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListOwners", nil, "Failure preparing request")
543		return
544	}
545
546	resp, err := client.ListOwnersSender(req)
547	if err != nil {
548		result.dolr.Response = autorest.Response{Response: resp}
549		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListOwners", resp, "Failure sending request")
550		return
551	}
552
553	result.dolr, err = client.ListOwnersResponder(resp)
554	if err != nil {
555		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListOwners", resp, "Failure responding to request")
556		return
557	}
558	if result.dolr.hasNextLink() && result.dolr.IsEmpty() {
559		err = result.NextWithContext(ctx)
560		return
561	}
562
563	return
564}
565
566// ListOwnersPreparer prepares the ListOwners request.
567func (client ServicePrincipalsClient) ListOwnersPreparer(ctx context.Context, objectID string) (*http.Request, error) {
568	pathParameters := map[string]interface{}{
569		"objectId": autorest.Encode("path", objectID),
570		"tenantID": autorest.Encode("path", client.TenantID),
571	}
572
573	const APIVersion = "1.6"
574	queryParameters := map[string]interface{}{
575		"api-version": APIVersion,
576	}
577
578	preparer := autorest.CreatePreparer(
579		autorest.AsGet(),
580		autorest.WithBaseURL(client.BaseURI),
581		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/owners", pathParameters),
582		autorest.WithQueryParameters(queryParameters))
583	return preparer.Prepare((&http.Request{}).WithContext(ctx))
584}
585
586// ListOwnersSender sends the ListOwners request. The method will close the
587// http.Response Body if it receives an error.
588func (client ServicePrincipalsClient) ListOwnersSender(req *http.Request) (*http.Response, error) {
589	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
590}
591
592// ListOwnersResponder handles the response to the ListOwners request. The method always
593// closes the http.Response Body.
594func (client ServicePrincipalsClient) ListOwnersResponder(resp *http.Response) (result DirectoryObjectListResult, err error) {
595	err = autorest.Respond(
596		resp,
597		azure.WithErrorUnlessStatusCode(http.StatusOK),
598		autorest.ByUnmarshallingJSON(&result),
599		autorest.ByClosing())
600	result.Response = autorest.Response{Response: resp}
601	return
602}
603
604// listOwnersNextResults retrieves the next set of results, if any.
605func (client ServicePrincipalsClient) listOwnersNextResults(ctx context.Context, lastResults DirectoryObjectListResult) (result DirectoryObjectListResult, err error) {
606	req, err := lastResults.directoryObjectListResultPreparer(ctx)
607	if err != nil {
608		return result, autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "listOwnersNextResults", nil, "Failure preparing next results request")
609	}
610	if req == nil {
611		return
612	}
613	resp, err := client.ListOwnersSender(req)
614	if err != nil {
615		result.Response = autorest.Response{Response: resp}
616		return result, autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "listOwnersNextResults", resp, "Failure sending next results request")
617	}
618	result, err = client.ListOwnersResponder(resp)
619	if err != nil {
620		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "listOwnersNextResults", resp, "Failure responding to next results request")
621	}
622	return
623}
624
625// ListOwnersComplete enumerates all values, automatically crossing page boundaries as required.
626func (client ServicePrincipalsClient) ListOwnersComplete(ctx context.Context, objectID string) (result DirectoryObjectListResultIterator, err error) {
627	if tracing.IsEnabled() {
628		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.ListOwners")
629		defer func() {
630			sc := -1
631			if result.Response().Response.Response != nil {
632				sc = result.page.Response().Response.Response.StatusCode
633			}
634			tracing.EndSpan(ctx, sc, err)
635		}()
636	}
637	result.page, err = client.ListOwners(ctx, objectID)
638	return
639}
640
641// ListPasswordCredentials gets the passwordCredentials associated with a service principal.
642// Parameters:
643// objectID - the object ID of the service principal.
644func (client ServicePrincipalsClient) ListPasswordCredentials(ctx context.Context, objectID string) (result PasswordCredentialListResult, err error) {
645	if tracing.IsEnabled() {
646		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.ListPasswordCredentials")
647		defer func() {
648			sc := -1
649			if result.Response.Response != nil {
650				sc = result.Response.Response.StatusCode
651			}
652			tracing.EndSpan(ctx, sc, err)
653		}()
654	}
655	req, err := client.ListPasswordCredentialsPreparer(ctx, objectID)
656	if err != nil {
657		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure preparing request")
658		return
659	}
660
661	resp, err := client.ListPasswordCredentialsSender(req)
662	if err != nil {
663		result.Response = autorest.Response{Response: resp}
664		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListPasswordCredentials", resp, "Failure sending request")
665		return
666	}
667
668	result, err = client.ListPasswordCredentialsResponder(resp)
669	if err != nil {
670		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "ListPasswordCredentials", resp, "Failure responding to request")
671		return
672	}
673
674	return
675}
676
677// ListPasswordCredentialsPreparer prepares the ListPasswordCredentials request.
678func (client ServicePrincipalsClient) ListPasswordCredentialsPreparer(ctx context.Context, objectID string) (*http.Request, error) {
679	pathParameters := map[string]interface{}{
680		"objectId": autorest.Encode("path", objectID),
681		"tenantID": autorest.Encode("path", client.TenantID),
682	}
683
684	const APIVersion = "1.6"
685	queryParameters := map[string]interface{}{
686		"api-version": APIVersion,
687	}
688
689	preparer := autorest.CreatePreparer(
690		autorest.AsGet(),
691		autorest.WithBaseURL(client.BaseURI),
692		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/passwordCredentials", pathParameters),
693		autorest.WithQueryParameters(queryParameters))
694	return preparer.Prepare((&http.Request{}).WithContext(ctx))
695}
696
697// ListPasswordCredentialsSender sends the ListPasswordCredentials request. The method will close the
698// http.Response Body if it receives an error.
699func (client ServicePrincipalsClient) ListPasswordCredentialsSender(req *http.Request) (*http.Response, error) {
700	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
701}
702
703// ListPasswordCredentialsResponder handles the response to the ListPasswordCredentials request. The method always
704// closes the http.Response Body.
705func (client ServicePrincipalsClient) ListPasswordCredentialsResponder(resp *http.Response) (result PasswordCredentialListResult, err error) {
706	err = autorest.Respond(
707		resp,
708		azure.WithErrorUnlessStatusCode(http.StatusOK),
709		autorest.ByUnmarshallingJSON(&result),
710		autorest.ByClosing())
711	result.Response = autorest.Response{Response: resp}
712	return
713}
714
715// Update updates a service principal in the directory.
716// Parameters:
717// objectID - the object ID of the service principal to delete.
718// parameters - parameters to update a service principal.
719func (client ServicePrincipalsClient) Update(ctx context.Context, objectID string, parameters ServicePrincipalUpdateParameters) (result autorest.Response, err error) {
720	if tracing.IsEnabled() {
721		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.Update")
722		defer func() {
723			sc := -1
724			if result.Response != nil {
725				sc = result.Response.StatusCode
726			}
727			tracing.EndSpan(ctx, sc, err)
728		}()
729	}
730	req, err := client.UpdatePreparer(ctx, objectID, parameters)
731	if err != nil {
732		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Update", nil, "Failure preparing request")
733		return
734	}
735
736	resp, err := client.UpdateSender(req)
737	if err != nil {
738		result.Response = resp
739		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Update", resp, "Failure sending request")
740		return
741	}
742
743	result, err = client.UpdateResponder(resp)
744	if err != nil {
745		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "Update", resp, "Failure responding to request")
746		return
747	}
748
749	return
750}
751
752// UpdatePreparer prepares the Update request.
753func (client ServicePrincipalsClient) UpdatePreparer(ctx context.Context, objectID string, parameters ServicePrincipalUpdateParameters) (*http.Request, error) {
754	pathParameters := map[string]interface{}{
755		"objectId": autorest.Encode("path", objectID),
756		"tenantID": autorest.Encode("path", client.TenantID),
757	}
758
759	const APIVersion = "1.6"
760	queryParameters := map[string]interface{}{
761		"api-version": APIVersion,
762	}
763
764	preparer := autorest.CreatePreparer(
765		autorest.AsContentType("application/json; charset=utf-8"),
766		autorest.AsPatch(),
767		autorest.WithBaseURL(client.BaseURI),
768		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}", pathParameters),
769		autorest.WithJSON(parameters),
770		autorest.WithQueryParameters(queryParameters))
771	return preparer.Prepare((&http.Request{}).WithContext(ctx))
772}
773
774// UpdateSender sends the Update request. The method will close the
775// http.Response Body if it receives an error.
776func (client ServicePrincipalsClient) UpdateSender(req *http.Request) (*http.Response, error) {
777	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
778}
779
780// UpdateResponder handles the response to the Update request. The method always
781// closes the http.Response Body.
782func (client ServicePrincipalsClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
783	err = autorest.Respond(
784		resp,
785		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
786		autorest.ByClosing())
787	result.Response = resp
788	return
789}
790
791// UpdateKeyCredentials update the keyCredentials associated with a service principal.
792// Parameters:
793// objectID - the object ID for which to get service principal information.
794// parameters - parameters to update the keyCredentials of an existing service principal.
795func (client ServicePrincipalsClient) UpdateKeyCredentials(ctx context.Context, objectID string, parameters KeyCredentialsUpdateParameters) (result autorest.Response, err error) {
796	if tracing.IsEnabled() {
797		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.UpdateKeyCredentials")
798		defer func() {
799			sc := -1
800			if result.Response != nil {
801				sc = result.Response.StatusCode
802			}
803			tracing.EndSpan(ctx, sc, err)
804		}()
805	}
806	req, err := client.UpdateKeyCredentialsPreparer(ctx, objectID, parameters)
807	if err != nil {
808		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdateKeyCredentials", nil, "Failure preparing request")
809		return
810	}
811
812	resp, err := client.UpdateKeyCredentialsSender(req)
813	if err != nil {
814		result.Response = resp
815		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdateKeyCredentials", resp, "Failure sending request")
816		return
817	}
818
819	result, err = client.UpdateKeyCredentialsResponder(resp)
820	if err != nil {
821		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdateKeyCredentials", resp, "Failure responding to request")
822		return
823	}
824
825	return
826}
827
828// UpdateKeyCredentialsPreparer prepares the UpdateKeyCredentials request.
829func (client ServicePrincipalsClient) UpdateKeyCredentialsPreparer(ctx context.Context, objectID string, parameters KeyCredentialsUpdateParameters) (*http.Request, error) {
830	pathParameters := map[string]interface{}{
831		"objectId": autorest.Encode("path", objectID),
832		"tenantID": autorest.Encode("path", client.TenantID),
833	}
834
835	const APIVersion = "1.6"
836	queryParameters := map[string]interface{}{
837		"api-version": APIVersion,
838	}
839
840	preparer := autorest.CreatePreparer(
841		autorest.AsContentType("application/json; charset=utf-8"),
842		autorest.AsPatch(),
843		autorest.WithBaseURL(client.BaseURI),
844		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/keyCredentials", pathParameters),
845		autorest.WithJSON(parameters),
846		autorest.WithQueryParameters(queryParameters))
847	return preparer.Prepare((&http.Request{}).WithContext(ctx))
848}
849
850// UpdateKeyCredentialsSender sends the UpdateKeyCredentials request. The method will close the
851// http.Response Body if it receives an error.
852func (client ServicePrincipalsClient) UpdateKeyCredentialsSender(req *http.Request) (*http.Response, error) {
853	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
854}
855
856// UpdateKeyCredentialsResponder handles the response to the UpdateKeyCredentials request. The method always
857// closes the http.Response Body.
858func (client ServicePrincipalsClient) UpdateKeyCredentialsResponder(resp *http.Response) (result autorest.Response, err error) {
859	err = autorest.Respond(
860		resp,
861		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
862		autorest.ByClosing())
863	result.Response = resp
864	return
865}
866
867// UpdatePasswordCredentials updates the passwordCredentials associated with a service principal.
868// Parameters:
869// objectID - the object ID of the service principal.
870// parameters - parameters to update the passwordCredentials of an existing service principal.
871func (client ServicePrincipalsClient) UpdatePasswordCredentials(ctx context.Context, objectID string, parameters PasswordCredentialsUpdateParameters) (result autorest.Response, err error) {
872	if tracing.IsEnabled() {
873		ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.UpdatePasswordCredentials")
874		defer func() {
875			sc := -1
876			if result.Response != nil {
877				sc = result.Response.StatusCode
878			}
879			tracing.EndSpan(ctx, sc, err)
880		}()
881	}
882	req, err := client.UpdatePasswordCredentialsPreparer(ctx, objectID, parameters)
883	if err != nil {
884		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure preparing request")
885		return
886	}
887
888	resp, err := client.UpdatePasswordCredentialsSender(req)
889	if err != nil {
890		result.Response = resp
891		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdatePasswordCredentials", resp, "Failure sending request")
892		return
893	}
894
895	result, err = client.UpdatePasswordCredentialsResponder(resp)
896	if err != nil {
897		err = autorest.NewErrorWithError(err, "graphrbac.ServicePrincipalsClient", "UpdatePasswordCredentials", resp, "Failure responding to request")
898		return
899	}
900
901	return
902}
903
904// UpdatePasswordCredentialsPreparer prepares the UpdatePasswordCredentials request.
905func (client ServicePrincipalsClient) UpdatePasswordCredentialsPreparer(ctx context.Context, objectID string, parameters PasswordCredentialsUpdateParameters) (*http.Request, error) {
906	pathParameters := map[string]interface{}{
907		"objectId": autorest.Encode("path", objectID),
908		"tenantID": autorest.Encode("path", client.TenantID),
909	}
910
911	const APIVersion = "1.6"
912	queryParameters := map[string]interface{}{
913		"api-version": APIVersion,
914	}
915
916	preparer := autorest.CreatePreparer(
917		autorest.AsContentType("application/json; charset=utf-8"),
918		autorest.AsPatch(),
919		autorest.WithBaseURL(client.BaseURI),
920		autorest.WithPathParameters("/{tenantID}/servicePrincipals/{objectId}/passwordCredentials", pathParameters),
921		autorest.WithJSON(parameters),
922		autorest.WithQueryParameters(queryParameters))
923	return preparer.Prepare((&http.Request{}).WithContext(ctx))
924}
925
926// UpdatePasswordCredentialsSender sends the UpdatePasswordCredentials request. The method will close the
927// http.Response Body if it receives an error.
928func (client ServicePrincipalsClient) UpdatePasswordCredentialsSender(req *http.Request) (*http.Response, error) {
929	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
930}
931
932// UpdatePasswordCredentialsResponder handles the response to the UpdatePasswordCredentials request. The method always
933// closes the http.Response Body.
934func (client ServicePrincipalsClient) UpdatePasswordCredentialsResponder(resp *http.Response) (result autorest.Response, err error) {
935	err = autorest.Respond(
936		resp,
937		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
938		autorest.ByClosing())
939	result.Response = resp
940	return
941}
942