~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/azure/internal/ad/serviceprincipals.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
//
 
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.
 
8
 
 
9
package ad
 
10
 
 
11
import (
 
12
        "net/http"
 
13
 
 
14
        "github.com/Azure/go-autorest/autorest"
 
15
        "github.com/Azure/go-autorest/autorest/azure"
 
16
)
 
17
 
 
18
type ServicePrincipalsClient struct {
 
19
        ManagementClient
 
20
}
 
21
 
 
22
func (client ServicePrincipalsClient) Create(parameters ServicePrincipalCreateParameters, cancel <-chan struct{}) (result ServicePrincipal, err error) {
 
23
        req, err := client.CreatePreparer(parameters, cancel)
 
24
        if err != nil {
 
25
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "Create", nil, "Failure preparing request")
 
26
        }
 
27
 
 
28
        resp, err := client.CreateSender(req)
 
29
        if err != nil {
 
30
                result.Response = autorest.Response{Response: resp}
 
31
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "Create", nil, "Failure sending request")
 
32
        }
 
33
 
 
34
        result, err = client.CreateResponder(resp)
 
35
        if err != nil {
 
36
                err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "Create", nil, "Failure responding to request")
 
37
        }
 
38
 
 
39
        return
 
40
}
 
41
 
 
42
func (client ServicePrincipalsClient) CreatePreparer(parameters ServicePrincipalCreateParameters, cancel <-chan struct{}) (*http.Request, error) {
 
43
        queryParameters := map[string]interface{}{
 
44
                "api-version": client.APIVersion,
 
45
        }
 
46
 
 
47
        preparer := autorest.CreatePreparer(
 
48
                autorest.AsJSON(),
 
49
                autorest.AsPost(),
 
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})
 
55
}
 
56
 
 
57
func (client ServicePrincipalsClient) CreateSender(req *http.Request) (*http.Response, error) {
 
58
        return autorest.SendWithSender(client,
 
59
                req,
 
60
                azure.DoPollForAsynchronous(client.PollingDelay))
 
61
}
 
62
 
 
63
func (client ServicePrincipalsClient) CreateResponder(resp *http.Response) (result ServicePrincipal, err error) {
 
64
        err = autorest.Respond(
 
65
                resp,
 
66
                client.ByInspecting(),
 
67
                WithOdataErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
 
68
                autorest.ByUnmarshallingJSON(&result),
 
69
                autorest.ByClosing())
 
70
        result.Response = autorest.Response{Response: resp}
 
71
        return
 
72
}
 
73
 
 
74
func (client ServicePrincipalsClient) List(filter string) (result ServicePrincipalListResult, err error) {
 
75
        req, err := client.ListPreparer(filter)
 
76
        if err != nil {
 
77
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "List", nil, "Failure preparing request")
 
78
        }
 
79
 
 
80
        resp, err := client.ListSender(req)
 
81
        if err != nil {
 
82
                result.Response = autorest.Response{Response: resp}
 
83
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "List", nil, "Failure sending request")
 
84
        }
 
85
 
 
86
        result, err = client.ListResponder(resp)
 
87
        if err != nil {
 
88
                err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "List", nil, "Failure responding to request")
 
89
        }
 
90
 
 
91
        return
 
92
}
 
93
 
 
94
func (client ServicePrincipalsClient) ListPreparer(filter string) (*http.Request, error) {
 
95
        queryParameters := map[string]interface{}{
 
96
                "api-version": client.APIVersion,
 
97
        }
 
98
        if filter != "" {
 
99
                queryParameters["$filter"] = autorest.Encode("query", filter)
 
100
        }
 
101
 
 
102
        preparer := autorest.CreatePreparer(
 
103
                autorest.AsGet(),
 
104
                autorest.WithBaseURL(client.BaseURI),
 
105
                autorest.WithPath("/servicePrincipals"),
 
106
                autorest.WithQueryParameters(queryParameters))
 
107
        return preparer.Prepare(&http.Request{})
 
108
}
 
109
 
 
110
func (client ServicePrincipalsClient) ListSender(req *http.Request) (*http.Response, error) {
 
111
        return autorest.SendWithSender(client, req)
 
112
}
 
113
 
 
114
func (client ServicePrincipalsClient) ListResponder(resp *http.Response) (result ServicePrincipalListResult, err error) {
 
115
        err = autorest.Respond(
 
116
                resp,
 
117
                client.ByInspecting(),
 
118
                WithOdataErrorUnlessStatusCode(http.StatusOK),
 
119
                autorest.ByUnmarshallingJSON(&result),
 
120
                autorest.ByClosing())
 
121
        result.Response = autorest.Response{Response: resp}
 
122
        return
 
123
}
 
124
 
 
125
func (client ServicePrincipalsClient) ListPasswordCredentials(objectId string) (result PasswordCredentialsListResult, err error) {
 
126
        req, err := client.ListPasswordCredentialsPreparer(objectId)
 
127
        if err != nil {
 
128
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure preparing request")
 
129
        }
 
130
 
 
131
        resp, err := client.ListPasswordCredentialsSender(req)
 
132
        if err != nil {
 
133
                result.Response = autorest.Response{Response: resp}
 
134
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure sending request")
 
135
        }
 
136
 
 
137
        result, err = client.ListPasswordCredentialsResponder(resp)
 
138
        if err != nil {
 
139
                err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "ListPasswordCredentials", nil, "Failure responding to request")
 
140
        }
 
141
 
 
142
        return
 
143
}
 
144
 
 
145
func (client ServicePrincipalsClient) ListPasswordCredentialsPreparer(objectId string) (*http.Request, error) {
 
146
        pathParameters := map[string]interface{}{
 
147
                "objectId": autorest.Encode("path", objectId),
 
148
        }
 
149
        queryParameters := map[string]interface{}{
 
150
                "api-version": client.APIVersion,
 
151
        }
 
152
 
 
153
        preparer := autorest.CreatePreparer(
 
154
                autorest.AsGet(),
 
155
                autorest.WithBaseURL(client.BaseURI),
 
156
                autorest.WithPathParameters("/servicePrincipals/{objectId}/passwordCredentials", pathParameters),
 
157
                autorest.WithQueryParameters(queryParameters))
 
158
        return preparer.Prepare(&http.Request{})
 
159
}
 
160
 
 
161
func (client ServicePrincipalsClient) ListPasswordCredentialsSender(req *http.Request) (*http.Response, error) {
 
162
        return autorest.SendWithSender(client, req)
 
163
}
 
164
 
 
165
func (client ServicePrincipalsClient) ListPasswordCredentialsResponder(resp *http.Response) (result PasswordCredentialsListResult, err error) {
 
166
        err = autorest.Respond(
 
167
                resp,
 
168
                client.ByInspecting(),
 
169
                WithOdataErrorUnlessStatusCode(http.StatusOK),
 
170
                autorest.ByUnmarshallingJSON(&result),
 
171
                autorest.ByClosing())
 
172
        result.Response = autorest.Response{Response: resp}
 
173
        return
 
174
}
 
175
 
 
176
func (client ServicePrincipalsClient) UpdatePasswordCredentials(objectId string, parameters PasswordCredentialsUpdateParameters) (result autorest.Response, err error) {
 
177
        req, err := client.UpdatePasswordCredentialsPreparer(objectId, parameters)
 
178
        if err != nil {
 
179
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure preparing request")
 
180
        }
 
181
 
 
182
        resp, err := client.UpdatePasswordCredentialsSender(req)
 
183
        if err != nil {
 
184
                result.Response = resp
 
185
                return result, autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure sending request")
 
186
        }
 
187
 
 
188
        result, err = client.UpdatePasswordCredentialsResponder(resp)
 
189
        if err != nil {
 
190
                err = autorest.NewErrorWithError(err, "ad.ServicePrincipalsClient", "UpdatePasswordCredentials", nil, "Failure responding to request")
 
191
        }
 
192
 
 
193
        return
 
194
}
 
195
 
 
196
func (client ServicePrincipalsClient) UpdatePasswordCredentialsPreparer(objectId string, parameters PasswordCredentialsUpdateParameters) (*http.Request, error) {
 
197
        pathParameters := map[string]interface{}{
 
198
                "objectId": autorest.Encode("path", objectId),
 
199
        }
 
200
 
 
201
        queryParameters := map[string]interface{}{
 
202
                "api-version": client.APIVersion,
 
203
        }
 
204
 
 
205
        preparer := autorest.CreatePreparer(
 
206
                autorest.AsJSON(),
 
207
                autorest.AsPatch(),
 
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{})
 
213
}
 
214
 
 
215
func (client ServicePrincipalsClient) UpdatePasswordCredentialsSender(req *http.Request) (*http.Response, error) {
 
216
        return autorest.SendWithSender(client,
 
217
                req,
 
218
                azure.DoPollForAsynchronous(client.PollingDelay))
 
219
}
 
220
 
 
221
func (client ServicePrincipalsClient) UpdatePasswordCredentialsResponder(resp *http.Response) (result autorest.Response, err error) {
 
222
        err = autorest.Respond(
 
223
                resp,
 
224
                client.ByInspecting(),
 
225
                WithOdataErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
 
226
                autorest.ByClosing())
 
227
        result.Response = resp
 
228
        return
 
229
}