1
// This file is based on code from Azure/azure-sdk-for-go,
2
// which is Copyright Microsoft Corporation. See the LICENSE
3
// file in this directory for details.
5
// NOTE(axw) this file contains a client for a subset of the
6
// Microsoft Graph API, which is not currently supported by
7
// the Azure SDK. When it is, this will be deleted.
14
"github.com/Azure/go-autorest/autorest"
15
"github.com/Azure/go-autorest/autorest/azure"
18
type ServicePrincipalsClient struct {
22
func (client ServicePrincipalsClient) Create(parameters ServicePrincipalCreateParameters, cancel <-chan struct{}) (result ServicePrincipal, err error) {
23
req, err := client.CreatePreparer(parameters, cancel)
25
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "Create", nil, "Failure preparing request")
28
resp, err := client.CreateSender(req)
30
result.Response = autorest.Response{Response: resp}
31
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "Create", nil, "Failure sending request")
34
result, err = client.CreateResponder(resp)
36
err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "Create", nil, "Failure responding to request")
42
func (client ServicePrincipalsClient) CreatePreparer(parameters ServicePrincipalCreateParameters, cancel <-chan struct{}) (*http.Request, error) {
43
queryParameters := map[string]interface{}{
44
"api-version": client.APIVersion,
47
preparer := autorest.CreatePreparer(
50
autorest.WithBaseURL(client.BaseURI),
51
autorest.WithPath("/servicePrincipals"),
52
autorest.WithJSON(parameters),
53
autorest.WithQueryParameters(queryParameters))
54
return preparer.Prepare(&http.Request{Cancel: cancel})
57
func (client ServicePrincipalsClient) CreateSender(req *http.Request) (*http.Response, error) {
58
return autorest.SendWithSender(client,
60
azure.DoPollForAsynchronous(client.PollingDelay))
63
func (client ServicePrincipalsClient) CreateResponder(resp *http.Response) (result ServicePrincipal, err error) {
64
err = autorest.Respond(
66
client.ByInspecting(),
67
WithOdataErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
68
autorest.ByUnmarshallingJSON(&result),
70
result.Response = autorest.Response{Response: resp}
74
func (client ServicePrincipalsClient) List(filter string) (result ServicePrincipalListResult, err error) {
75
req, err := client.ListPreparer(filter)
77
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "List", nil, "Failure preparing request")
80
resp, err := client.ListSender(req)
82
result.Response = autorest.Response{Response: resp}
83
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "List", nil, "Failure sending request")
86
result, err = client.ListResponder(resp)
88
err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "List", nil, "Failure responding to request")
94
func (client ServicePrincipalsClient) ListPreparer(filter string) (*http.Request, error) {
95
queryParameters := map[string]interface{}{
96
"api-version": client.APIVersion,
99
queryParameters["$filter"] = autorest.Encode("query", filter)
102
preparer := autorest.CreatePreparer(
104
autorest.WithBaseURL(client.BaseURI),
105
autorest.WithPath("/servicePrincipals"),
106
autorest.WithQueryParameters(queryParameters))
107
return preparer.Prepare(&http.Request{})
110
func (client ServicePrincipalsClient) ListSender(req *http.Request) (*http.Response, error) {
111
return autorest.SendWithSender(client, req)
114
func (client ServicePrincipalsClient) ListResponder(resp *http.Response) (result ServicePrincipalListResult, err error) {
115
err = autorest.Respond(
117
client.ByInspecting(),
118
WithOdataErrorUnlessStatusCode(http.StatusOK),
119
autorest.ByUnmarshallingJSON(&result),
120
autorest.ByClosing())
121
result.Response = autorest.Response{Response: resp}
125
func (client ServicePrincipalsClient) ListPasswordCredentials(objectId string) (result PasswordCredentialsListResult, err error) {
126
req, err := client.ListPasswordCredentialsPreparer(objectId)
128
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure preparing request")
131
resp, err := client.ListPasswordCredentialsSender(req)
133
result.Response = autorest.Response{Response: resp}
134
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure sending request")
137
result, err = client.ListPasswordCredentialsResponder(resp)
139
err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure responding to request")
145
func (client ServicePrincipalsClient) ListPasswordCredentialsPreparer(objectId string) (*http.Request, error) {
146
pathParameters := map[string]interface{}{
147
"objectId": autorest.Encode("path", objectId),
149
queryParameters := map[string]interface{}{
150
"api-version": client.APIVersion,
153
preparer := autorest.CreatePreparer(
155
autorest.WithBaseURL(client.BaseURI),
156
autorest.WithPathParameters("/servicePrincipals/{objectId}/passwordCredentials", pathParameters),
157
autorest.WithQueryParameters(queryParameters))
158
return preparer.Prepare(&http.Request{})
161
func (client ServicePrincipalsClient) ListPasswordCredentialsSender(req *http.Request) (*http.Response, error) {
162
return autorest.SendWithSender(client, req)
165
func (client ServicePrincipalsClient) ListPasswordCredentialsResponder(resp *http.Response) (result PasswordCredentialsListResult, err error) {
166
err = autorest.Respond(
168
client.ByInspecting(),
169
WithOdataErrorUnlessStatusCode(http.StatusOK),
170
autorest.ByUnmarshallingJSON(&result),
171
autorest.ByClosing())
172
result.Response = autorest.Response{Response: resp}
176
func (client ServicePrincipalsClient) UpdatePasswordCredentials(objectId string, parameters PasswordCredentialsUpdateParameters) (result autorest.Response, err error) {
177
req, err := client.UpdatePasswordCredentialsPreparer(objectId, parameters)
179
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure preparing request")
182
resp, err := client.UpdatePasswordCredentialsSender(req)
184
result.Response = resp
185
return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure sending request")
188
result, err = client.UpdatePasswordCredentialsResponder(resp)
190
err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure responding to request")
196
func (client ServicePrincipalsClient) UpdatePasswordCredentialsPreparer(objectId string, parameters PasswordCredentialsUpdateParameters) (*http.Request, error) {
197
pathParameters := map[string]interface{}{
198
"objectId": autorest.Encode("path", objectId),
201
queryParameters := map[string]interface{}{
202
"api-version": client.APIVersion,
205
preparer := autorest.CreatePreparer(
208
autorest.WithBaseURL(client.BaseURI),
209
autorest.WithPathParameters("/servicePrincipals/{objectId}/passwordCredentials", pathParameters),
210
autorest.WithJSON(parameters),
211
autorest.WithQueryParameters(queryParameters))
212
return preparer.Prepare(&http.Request{})
215
func (client ServicePrincipalsClient) UpdatePasswordCredentialsSender(req *http.Request) (*http.Response, error) {
216
return autorest.SendWithSender(client,
218
azure.DoPollForAsynchronous(client.PollingDelay))
221
func (client ServicePrincipalsClient) UpdatePasswordCredentialsResponder(resp *http.Response) (result autorest.Response, err error) {
222
err = autorest.Respond(
224
client.ByInspecting(),
225
WithOdataErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
226
autorest.ByClosing())
227
result.Response = resp