Merge lp:~jtv/gwacl/unexport-x509 into lp:gwacl
- unexport-x509
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Jeroen T. Vermeulen |
Approved revision: | 62 |
Merged at revision: | 63 |
Proposed branch: | lp:~jtv/gwacl/unexport-x509 |
Merge into: | lp:gwacl |
Diff against target: |
518 lines (+73/-73) 6 files modified
managementapi.go (+2/-2) managementapi_test.go (+7/-7) x509dispatcher.go (+20/-20) x509dispatcher_test.go (+7/-7) x509session.go (+9/-9) x509session_test.go (+28/-28) |
To merge this branch: | bzr merge lp:~jtv/gwacl/unexport-x509 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Julian Edwards (community) | Approve | ||
Review via email: mp+155409@code.launchpad.net |
Commit message
Un-export the X509 classes. They're an implementation detail, completely hidden from the gwacl API.
Description of the change
Cleaning up the public API that we expose for gwacl.
I regret the size of this diff. Just un-exporting some identifiers is a huge amount of pointless diff in Go. I figured for that very reason it'd be best to get this behind us as soon as possible, with a minimum of development going on for it to interfere with.
For what it's worth, the un-exporting of these items is the *only* thing that happens in this branch. It's a mechanical change: X509Request / X509Response / X509Session structs become x509Request / x509Response / x509Session respectively, and their constructors NewX509* become newX509* (insofar as they weren't lower-cased already).
Jeroen
Julian Edwards (julian-edwards) wrote : | # |
Attempt to merge into lp:gwacl failed due to conflicts:
text conflict in managementapi_
Julian Edwards (julian-edwards) wrote : | # |
There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.
Preview Diff
1 | === modified file 'managementapi.go' | |||
2 | --- managementapi.go 2013-03-25 02:10:02 +0000 | |||
3 | +++ managementapi.go 2013-03-26 08:56:20 +0000 | |||
4 | @@ -8,13 +8,13 @@ | |||
5 | 8 | ) | 8 | ) |
6 | 9 | 9 | ||
7 | 10 | type ManagementAPI struct { | 10 | type ManagementAPI struct { |
9 | 11 | session *X509Session | 11 | session *x509Session |
10 | 12 | } | 12 | } |
11 | 13 | 13 | ||
12 | 14 | // NewManagementAPI creates an object used to interact with Windows Azure's API. | 14 | // NewManagementAPI creates an object used to interact with Windows Azure's API. |
13 | 15 | // http://msdn.microsoft.com/en-us/library/windowsazure/ff800682.aspx | 15 | // http://msdn.microsoft.com/en-us/library/windowsazure/ff800682.aspx |
14 | 16 | func NewManagementAPI(subscriptionId string, certFile string) (*ManagementAPI, error) { | 16 | func NewManagementAPI(subscriptionId string, certFile string) (*ManagementAPI, error) { |
16 | 17 | session, err := NewX509Session(subscriptionId, certFile) | 17 | session, err := newX509Session(subscriptionId, certFile) |
17 | 18 | if err != nil { | 18 | if err != nil { |
18 | 19 | return nil, err | 19 | return nil, err |
19 | 20 | } | 20 | } |
20 | 21 | 21 | ||
21 | === modified file 'managementapi_test.go' | |||
22 | --- managementapi_test.go 2013-03-26 07:00:46 +0000 | |||
23 | +++ managementapi_test.go 2013-03-26 08:56:20 +0000 | |||
24 | @@ -21,7 +21,7 @@ | |||
25 | 21 | api, err := NewManagementAPI(subscriptionId, certFile) | 21 | api, err := NewManagementAPI(subscriptionId, certFile) |
26 | 22 | 22 | ||
27 | 23 | c.Assert(err, IsNil) | 23 | c.Assert(err, IsNil) |
29 | 24 | session, err := NewX509Session(subscriptionId, certFile) | 24 | session, err := newX509Session(subscriptionId, certFile) |
30 | 25 | c.Assert(api.session.subscriptionId, DeepEquals, session.subscriptionId) | 25 | c.Assert(api.session.subscriptionId, DeepEquals, session.subscriptionId) |
31 | 26 | c.Assert(api.session.certFile, DeepEquals, session.certFile) | 26 | c.Assert(api.session.certFile, DeepEquals, session.certFile) |
32 | 27 | } | 27 | } |
33 | @@ -37,20 +37,20 @@ | |||
34 | 37 | // setUpDispatcher sets up a request dispatcher that: | 37 | // setUpDispatcher sets up a request dispatcher that: |
35 | 38 | // - records requests | 38 | // - records requests |
36 | 39 | // - returns empty responses | 39 | // - returns empty responses |
39 | 40 | func (suite *managementAPISuite) setUpDispatcher() *[]*X509Request { | 40 | func (suite *managementAPISuite) setUpDispatcher() *[]*x509Request { |
40 | 41 | fixedResponse := X509Response{ | 41 | fixedResponse := x509Response{ |
41 | 42 | StatusCode: http.StatusOK, | 42 | StatusCode: http.StatusOK, |
42 | 43 | Body: []byte{}, | 43 | Body: []byte{}, |
43 | 44 | } | 44 | } |
44 | 45 | rigFixedResponseDispatcher(&fixedResponse) | 45 | rigFixedResponseDispatcher(&fixedResponse) |
46 | 46 | recordedRequests := make([]*X509Request, 0) | 46 | recordedRequests := make([]*x509Request, 0) |
47 | 47 | rigRecordingDispatcher(&recordedRequests) | 47 | rigRecordingDispatcher(&recordedRequests) |
48 | 48 | return &recordedRequests | 48 | return &recordedRequests |
49 | 49 | } | 49 | } |
50 | 50 | 50 | ||
51 | 51 | // checkRequest asserts that the given slice contains one request, with the | 51 | // checkRequest asserts that the given slice contains one request, with the |
52 | 52 | // given characteristics. | 52 | // given characteristics. |
54 | 53 | func checkRequest(c *C, recordedRequests *[]*X509Request, URL string, payload []byte, Method string) { | 53 | func checkRequest(c *C, recordedRequests *[]*x509Request, URL string, payload []byte, Method string) { |
55 | 54 | requests := *recordedRequests | 54 | requests := *recordedRequests |
56 | 55 | c.Assert(len(requests), Equals, 1) | 55 | c.Assert(len(requests), Equals, 1) |
57 | 56 | request := requests[0] | 56 | request := requests[0] |
58 | @@ -128,8 +128,8 @@ | |||
59 | 128 | 128 | ||
60 | 129 | func (suite *managementAPISuite) TestAddStorageAccount(c *C) { | 129 | func (suite *managementAPISuite) TestAddStorageAccount(c *C) { |
61 | 130 | api := suite.makeAPI(c) | 130 | api := suite.makeAPI(c) |
64 | 131 | rigFixedResponseDispatcher(&X509Response{StatusCode: http.StatusAccepted}) | 131 | rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusAccepted}) |
65 | 132 | recordedRequests := make([]*X509Request, 0) | 132 | recordedRequests := make([]*x509Request, 0) |
66 | 133 | rigRecordingDispatcher(&recordedRequests) | 133 | rigRecordingDispatcher(&recordedRequests) |
67 | 134 | cssi := NewCreateStorageServiceInputWithLocation("name", "label", "East US") | 134 | cssi := NewCreateStorageServiceInputWithLocation("name", "label", "East US") |
68 | 135 | 135 | ||
69 | 136 | 136 | ||
70 | === modified file 'x509dispatcher.go' | |||
71 | --- x509dispatcher.go 2013-03-22 02:52:32 +0000 | |||
72 | +++ x509dispatcher.go 2013-03-26 08:56:20 +0000 | |||
73 | @@ -10,7 +10,7 @@ | |||
74 | 10 | "net/textproto" | 10 | "net/textproto" |
75 | 11 | ) | 11 | ) |
76 | 12 | 12 | ||
78 | 13 | type X509Request struct { | 13 | type x509Request struct { |
79 | 14 | APIVersion string | 14 | APIVersion string |
80 | 15 | Method string | 15 | Method string |
81 | 16 | URL string | 16 | URL string |
82 | @@ -28,20 +28,20 @@ | |||
83 | 28 | // baseAPIVersion is the default Azure API version to use. | 28 | // baseAPIVersion is the default Azure API version to use. |
84 | 29 | const baseAPIVersion = "2012-03-01" | 29 | const baseAPIVersion = "2012-03-01" |
85 | 30 | 30 | ||
87 | 31 | // newX509RequestGET initializes an X509Request for a GET. You may still need | 31 | // newX509RequestGET initializes an x509Request for a GET. You may still need |
88 | 32 | // to set further values. | 32 | // to set further values. |
91 | 33 | func newX509RequestGET(url string) *X509Request { | 33 | func newX509RequestGET(url string) *x509Request { |
92 | 34 | return &X509Request{ | 34 | return &x509Request{ |
93 | 35 | Method: "GET", | 35 | Method: "GET", |
94 | 36 | URL: url, | 36 | URL: url, |
95 | 37 | APIVersion: baseAPIVersion, | 37 | APIVersion: baseAPIVersion, |
96 | 38 | } | 38 | } |
97 | 39 | } | 39 | } |
98 | 40 | 40 | ||
100 | 41 | // newX509RequestPOST initializes an X509Request for a POST. You may still | 41 | // newX509RequestPOST initializes an x509Request for a POST. You may still |
101 | 42 | // need to set further values. | 42 | // need to set further values. |
104 | 43 | func newX509RequestPOST(url string, payload []byte, contentType string) *X509Request { | 43 | func newX509RequestPOST(url string, payload []byte, contentType string) *x509Request { |
105 | 44 | return &X509Request{ | 44 | return &x509Request{ |
106 | 45 | Method: "POST", | 45 | Method: "POST", |
107 | 46 | URL: url, | 46 | URL: url, |
108 | 47 | APIVersion: baseAPIVersion, | 47 | APIVersion: baseAPIVersion, |
109 | @@ -50,19 +50,19 @@ | |||
110 | 50 | } | 50 | } |
111 | 51 | } | 51 | } |
112 | 52 | 52 | ||
116 | 53 | // newX509RequestDELETE initializes an X509Request for a DELETE. | 53 | // newX509RequestDELETE initializes an x509Request for a DELETE. |
117 | 54 | func newX509RequestDELETE(url string) *X509Request { | 54 | func newX509RequestDELETE(url string) *x509Request { |
118 | 55 | return &X509Request{ | 55 | return &x509Request{ |
119 | 56 | Method: "DELETE", | 56 | Method: "DELETE", |
120 | 57 | URL: url, | 57 | URL: url, |
121 | 58 | APIVersion: baseAPIVersion, | 58 | APIVersion: baseAPIVersion, |
122 | 59 | } | 59 | } |
123 | 60 | } | 60 | } |
124 | 61 | 61 | ||
126 | 62 | // newX509RequestPUT initializes an X509Request for a PUT. You may still | 62 | // newX509RequestPUT initializes an x509Request for a PUT. You may still |
127 | 63 | // need to set further values. | 63 | // need to set further values. |
130 | 64 | func newX509RequestPUT(url string, payload []byte) *X509Request { | 64 | func newX509RequestPUT(url string, payload []byte) *x509Request { |
131 | 65 | return &X509Request{ | 65 | return &x509Request{ |
132 | 66 | Method: "PUT", | 66 | Method: "PUT", |
133 | 67 | URL: url, | 67 | URL: url, |
134 | 68 | APIVersion: baseAPIVersion, | 68 | APIVersion: baseAPIVersion, |
135 | @@ -70,7 +70,7 @@ | |||
136 | 70 | } | 70 | } |
137 | 71 | } | 71 | } |
138 | 72 | 72 | ||
140 | 73 | type X509Response struct { | 73 | type x509Response struct { |
141 | 74 | StatusCode int | 74 | StatusCode int |
142 | 75 | // TODO: What exactly do we get back? How will we know its encoding? | 75 | // TODO: What exactly do we get back? How will we know its encoding? |
143 | 76 | Body []byte | 76 | Body []byte |
144 | @@ -78,8 +78,8 @@ | |||
145 | 78 | Header http.Header | 78 | Header http.Header |
146 | 79 | } | 79 | } |
147 | 80 | 80 | ||
150 | 81 | func newX509Response() *X509Response { | 81 | func newX509Response() *x509Response { |
151 | 82 | return &X509Response{ | 82 | return &x509Response{ |
152 | 83 | Body: make([]byte, 0), | 83 | Body: make([]byte, 0), |
153 | 84 | RawHeader: make([]byte, 0), | 84 | RawHeader: make([]byte, 0), |
154 | 85 | } | 85 | } |
155 | @@ -120,7 +120,7 @@ | |||
156 | 120 | 120 | ||
157 | 121 | // parseHeader parses the raw header as stored in RawHeader, and uses it to | 121 | // parseHeader parses the raw header as stored in RawHeader, and uses it to |
158 | 122 | // initialize Header. | 122 | // initialize Header. |
160 | 123 | func (response *X509Response) parseHeader() error { | 123 | func (response *x509Response) parseHeader() error { |
161 | 124 | rawHeader := stripPreliminaryResponses(response.RawHeader) | 124 | rawHeader := stripPreliminaryResponses(response.RawHeader) |
162 | 125 | mimeHeader, err := stripResponseLine(rawHeader) | 125 | mimeHeader, err := stripResponseLine(rawHeader) |
163 | 126 | if err != nil { | 126 | if err != nil { |
164 | @@ -141,7 +141,7 @@ | |||
165 | 141 | return nil | 141 | return nil |
166 | 142 | } | 142 | } |
167 | 143 | 143 | ||
169 | 144 | func performX509CurlRequest(session *X509Session, request *X509Request) (*X509Response, error) { | 144 | func performX509CurlRequest(session *x509Session, request *x509Request) (*x509Response, error) { |
170 | 145 | if verbose { | 145 | if verbose { |
171 | 146 | log.Println("Performing request") | 146 | log.Println("Performing request") |
172 | 147 | log.Println("Request url: " + request.URL) | 147 | log.Println("Request url: " + request.URL) |
173 | @@ -181,7 +181,7 @@ | |||
174 | 181 | // makeCurlRequest produces a curl.CURL representing the request. | 181 | // makeCurlRequest produces a curl.CURL representing the request. |
175 | 182 | // Clean up the request by calling its Cleanup() method after you're done | 182 | // Clean up the request by calling its Cleanup() method after you're done |
176 | 183 | // with it. | 183 | // with it. |
178 | 184 | func (request *X509Request) makeCurlRequest(session *X509Session, response *X509Response) *curl.CURL { | 184 | func (request *x509Request) makeCurlRequest(session *x509Session, response *x509Response) *curl.CURL { |
179 | 185 | ch := curl.EasyInit() | 185 | ch := curl.EasyInit() |
180 | 186 | 186 | ||
181 | 187 | ch.Setopt(curl.OPT_SSLCERT, session.certFile) | 187 | ch.Setopt(curl.OPT_SSLCERT, session.certFile) |
182 | @@ -230,7 +230,7 @@ | |||
183 | 230 | 230 | ||
184 | 231 | // setCurlHTTPMethod sets up a CURL object to perform an HTTP request of | 231 | // setCurlHTTPMethod sets up a CURL object to perform an HTTP request of |
185 | 232 | // the HTTP method (GET, POST, etc.) appropriate for the request. | 232 | // the HTTP method (GET, POST, etc.) appropriate for the request. |
187 | 233 | func (request *X509Request) setCurlHTTPMethod(ch *curl.CURL) { | 233 | func (request *x509Request) setCurlHTTPMethod(ch *curl.CURL) { |
188 | 234 | switch request.Method { | 234 | switch request.Method { |
189 | 235 | case "GET": | 235 | case "GET": |
190 | 236 | // Nothing to be done. This is the default. | 236 | // Nothing to be done. This is the default. |
191 | 237 | 237 | ||
192 | === modified file 'x509dispatcher_test.go' | |||
193 | --- x509dispatcher_test.go 2013-03-22 02:06:22 +0000 | |||
194 | +++ x509dispatcher_test.go 2013-03-26 08:56:20 +0000 | |||
195 | @@ -30,7 +30,7 @@ | |||
196 | 30 | // An HTTP header contains a response line followed by a MIME header, which | 30 | // An HTTP header contains a response line followed by a MIME header, which |
197 | 31 | // parseHeader processes. | 31 | // parseHeader processes. |
198 | 32 | func (*X509DispatcherSuite) TestParseHeaderParsesHTTPHeader(c *C) { | 32 | func (*X509DispatcherSuite) TestParseHeaderParsesHTTPHeader(c *C) { |
200 | 33 | response := X509Response{} | 33 | response := x509Response{} |
201 | 34 | text := "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\n" | 34 | text := "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\n" |
202 | 35 | response.RawHeader = []byte(text) | 35 | response.RawHeader = []byte(text) |
203 | 36 | 36 | ||
204 | @@ -43,7 +43,7 @@ | |||
205 | 43 | // An HTTP response actually contains a sequence of HTTP headers, and | 43 | // An HTTP response actually contains a sequence of HTTP headers, and |
206 | 44 | // parseHeader only uses the final one. | 44 | // parseHeader only uses the final one. |
207 | 45 | func (*X509DispatcherSuite) TestParseHeaderParsesContinueResponse(c *C) { | 45 | func (*X509DispatcherSuite) TestParseHeaderParsesContinueResponse(c *C) { |
209 | 46 | response := X509Response{} | 46 | response := x509Response{} |
210 | 47 | text := "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 202 Accepted\r\nCache-Control: no-cache\r\n\r\n" | 47 | text := "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 202 Accepted\r\nCache-Control: no-cache\r\n\r\n" |
211 | 48 | response.RawHeader = []byte(text) | 48 | response.RawHeader = []byte(text) |
212 | 49 | 49 | ||
213 | @@ -58,7 +58,7 @@ | |||
214 | 58 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, nil) | 58 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, nil) |
215 | 59 | defer server.Close() | 59 | defer server.Close() |
216 | 60 | // No real certificate needed since we're testing on http, not https. | 60 | // No real certificate needed since we're testing on http, not https. |
218 | 61 | session, err := NewX509Session("subscriptionid", "cert.pem") | 61 | session, err := newX509Session("subscriptionid", "cert.pem") |
219 | 62 | c.Assert(err, IsNil) | 62 | c.Assert(err, IsNil) |
220 | 63 | path := "/foo/bar" | 63 | path := "/foo/bar" |
221 | 64 | request := newX509RequestGET(server.URL + path) | 64 | request := newX509RequestGET(server.URL + path) |
222 | @@ -80,7 +80,7 @@ | |||
223 | 80 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody) | 80 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody) |
224 | 81 | defer server.Close() | 81 | defer server.Close() |
225 | 82 | // No real certificate needed since we're testing on http, not https. | 82 | // No real certificate needed since we're testing on http, not https. |
227 | 83 | session, err := NewX509Session("subscriptionid", "cert.pem") | 83 | session, err := newX509Session("subscriptionid", "cert.pem") |
228 | 84 | c.Assert(err, IsNil) | 84 | c.Assert(err, IsNil) |
229 | 85 | path := "/foo/bar" | 85 | path := "/foo/bar" |
230 | 86 | request := newX509RequestPOST(server.URL+path, requestBody, requestContentType) | 86 | request := newX509RequestPOST(server.URL+path, requestBody, requestContentType) |
231 | @@ -102,7 +102,7 @@ | |||
232 | 102 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, []byte{}) | 102 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, []byte{}) |
233 | 103 | defer server.Close() | 103 | defer server.Close() |
234 | 104 | // No real certificate needed since we're testing on http, not https. | 104 | // No real certificate needed since we're testing on http, not https. |
236 | 105 | session, err := NewX509Session("subscriptionid", "cert.pem") | 105 | session, err := newX509Session("subscriptionid", "cert.pem") |
237 | 106 | c.Assert(err, IsNil) | 106 | c.Assert(err, IsNil) |
238 | 107 | path := "/foo/bar" | 107 | path := "/foo/bar" |
239 | 108 | request := newX509RequestDELETE(server.URL + path) | 108 | request := newX509RequestDELETE(server.URL + path) |
240 | @@ -123,7 +123,7 @@ | |||
241 | 123 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody) | 123 | server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody) |
242 | 124 | defer server.Close() | 124 | defer server.Close() |
243 | 125 | // No real certificate needed since we're testing on http, not https. | 125 | // No real certificate needed since we're testing on http, not https. |
245 | 126 | session, err := NewX509Session("subscriptionid", "cert.pem") | 126 | session, err := newX509Session("subscriptionid", "cert.pem") |
246 | 127 | c.Assert(err, IsNil) | 127 | c.Assert(err, IsNil) |
247 | 128 | path := "/foo/bar" | 128 | path := "/foo/bar" |
248 | 129 | request := newX509RequestPUT(server.URL+path, requestBody) | 129 | request := newX509RequestPUT(server.URL+path, requestBody) |
249 | @@ -149,7 +149,7 @@ | |||
250 | 149 | serveMux.HandleFunc("/", returnRequest) | 149 | serveMux.HandleFunc("/", returnRequest) |
251 | 150 | server := httptest.NewServer(serveMux) | 150 | server := httptest.NewServer(serveMux) |
252 | 151 | defer server.Close() | 151 | defer server.Close() |
254 | 152 | session, err := NewX509Session("subscriptionid", "cert.pem") | 152 | session, err := newX509Session("subscriptionid", "cert.pem") |
255 | 153 | c.Assert(err, IsNil) | 153 | c.Assert(err, IsNil) |
256 | 154 | path := "/foo/bar" | 154 | path := "/foo/bar" |
257 | 155 | request := newX509RequestGET(server.URL + path) | 155 | request := newX509RequestGET(server.URL + path) |
258 | 156 | 156 | ||
259 | === modified file 'x509session.go' | |||
260 | --- x509session.go 2013-03-20 23:53:03 +0000 | |||
261 | +++ x509session.go 2013-03-26 08:56:20 +0000 | |||
262 | @@ -8,15 +8,15 @@ | |||
263 | 8 | "net/http" | 8 | "net/http" |
264 | 9 | ) | 9 | ) |
265 | 10 | 10 | ||
267 | 11 | type X509Session struct { | 11 | type x509Session struct { |
268 | 12 | subscriptionId string | 12 | subscriptionId string |
269 | 13 | certFile string | 13 | certFile string |
270 | 14 | } | 14 | } |
271 | 15 | 15 | ||
273 | 16 | // NewX509Session creates and returns a new X509Session based on credentials | 16 | // newX509Session creates and returns a new x509Session based on credentials |
274 | 17 | // and X509 certificate files. | 17 | // and X509 certificate files. |
277 | 18 | func NewX509Session(subscriptionId string, certFile string) (*X509Session, error) { | 18 | func newX509Session(subscriptionId string, certFile string) (*x509Session, error) { |
278 | 19 | return &X509Session{subscriptionId: subscriptionId, certFile: certFile}, nil | 19 | return &x509Session{subscriptionId: subscriptionId, certFile: certFile}, nil |
279 | 20 | } | 20 | } |
280 | 21 | 21 | ||
281 | 22 | var AZURE_URL = "https://management.core.windows.net/" | 22 | var AZURE_URL = "https://management.core.windows.net/" |
282 | @@ -43,7 +43,7 @@ | |||
283 | 43 | 43 | ||
284 | 44 | // getServerError returns a ServerError matching the given server response | 44 | // getServerError returns a ServerError matching the given server response |
285 | 45 | // status, or nil if the server response indicates success. | 45 | // status, or nil if the server response indicates success. |
287 | 46 | func (session *X509Session) getServerError(status int, description string) error { | 46 | func (session *x509Session) getServerError(status int, description string) error { |
288 | 47 | if status < http.StatusOK || status >= http.StatusMultipleChoices { | 47 | if status < http.StatusOK || status >= http.StatusMultipleChoices { |
289 | 48 | failure := fmt.Errorf("%s (http status code %d)", description, status) | 48 | failure := fmt.Errorf("%s (http status code %d)", description, status) |
290 | 49 | return &ServerError{error: failure, StatusCode: status} | 49 | return &ServerError{error: failure, StatusCode: status} |
291 | @@ -55,7 +55,7 @@ | |||
292 | 55 | // It returns the response body and/or an error. If the error is a | 55 | // It returns the response body and/or an error. If the error is a |
293 | 56 | // ServerError, the returned body will be the one received from the server. | 56 | // ServerError, the returned body will be the one received from the server. |
294 | 57 | // For any other kind of error, the returned body will be nil. | 57 | // For any other kind of error, the returned body will be nil. |
296 | 58 | func (session *X509Session) get(url string) ([]byte, error) { | 58 | func (session *x509Session) get(url string) ([]byte, error) { |
297 | 59 | fullUrl := composeURL(url, session.subscriptionId) | 59 | fullUrl := composeURL(url, session.subscriptionId) |
298 | 60 | request := newX509RequestGET(fullUrl) | 60 | request := newX509RequestGET(fullUrl) |
299 | 61 | response, err := _X509Dispatcher(session, request) | 61 | response, err := _X509Dispatcher(session, request) |
300 | @@ -70,7 +70,7 @@ | |||
301 | 70 | // It returns the response body and/or an error. If the error is a | 70 | // It returns the response body and/or an error. If the error is a |
302 | 71 | // ServerError, the returned body will be the one received from the server. | 71 | // ServerError, the returned body will be the one received from the server. |
303 | 72 | // For any other kind of error, the returned body will be nil. | 72 | // For any other kind of error, the returned body will be nil. |
305 | 73 | func (session *X509Session) post(url string, body []byte, contentType string) ([]byte, error) { | 73 | func (session *x509Session) post(url string, body []byte, contentType string) ([]byte, error) { |
306 | 74 | fullUrl := composeURL(url, session.subscriptionId) | 74 | fullUrl := composeURL(url, session.subscriptionId) |
307 | 75 | request := newX509RequestPOST(fullUrl, body, contentType) | 75 | request := newX509RequestPOST(fullUrl, body, contentType) |
308 | 76 | response, err := _X509Dispatcher(session, request) | 76 | response, err := _X509Dispatcher(session, request) |
309 | @@ -82,7 +82,7 @@ | |||
310 | 82 | } | 82 | } |
311 | 83 | 83 | ||
312 | 84 | // delete performs a DELETE request to the Azure management API. | 84 | // delete performs a DELETE request to the Azure management API. |
314 | 85 | func (session *X509Session) delete(url string) error { | 85 | func (session *x509Session) delete(url string) error { |
315 | 86 | fullUrl := composeURL(url, session.subscriptionId) | 86 | fullUrl := composeURL(url, session.subscriptionId) |
316 | 87 | request := newX509RequestDELETE(fullUrl) | 87 | request := newX509RequestDELETE(fullUrl) |
317 | 88 | response, err := _X509Dispatcher(session, request) | 88 | response, err := _X509Dispatcher(session, request) |
318 | @@ -93,7 +93,7 @@ | |||
319 | 93 | } | 93 | } |
320 | 94 | 94 | ||
321 | 95 | // put performs a PUT request to the Azure management API. | 95 | // put performs a PUT request to the Azure management API. |
323 | 96 | func (session *X509Session) put(url string, body []byte) error { | 96 | func (session *x509Session) put(url string, body []byte) error { |
324 | 97 | fullUrl := composeURL(url, session.subscriptionId) | 97 | fullUrl := composeURL(url, session.subscriptionId) |
325 | 98 | request := newX509RequestPUT(fullUrl, body) | 98 | request := newX509RequestPUT(fullUrl, body) |
326 | 99 | response, err := _X509Dispatcher(session, request) | 99 | response, err := _X509Dispatcher(session, request) |
327 | 100 | 100 | ||
328 | === modified file 'x509session_test.go' | |||
329 | --- x509session_test.go 2013-03-20 23:53:03 +0000 | |||
330 | +++ x509session_test.go 2013-03-26 08:56:20 +0000 | |||
331 | @@ -18,7 +18,7 @@ | |||
332 | 18 | ) | 18 | ) |
333 | 19 | 19 | ||
334 | 20 | type X509SessionSuite struct { | 20 | type X509SessionSuite struct { |
336 | 21 | oldDispatcher func(*X509Session, *X509Request) (*X509Response, error) | 21 | oldDispatcher func(*x509Session, *x509Request) (*x509Response, error) |
337 | 22 | } | 22 | } |
338 | 23 | 23 | ||
339 | 24 | var _ = Suite(&X509SessionSuite{}) | 24 | var _ = Suite(&X509SessionSuite{}) |
340 | @@ -29,9 +29,9 @@ | |||
341 | 29 | // If you also want the dispatcher to return a particular result, rig it for | 29 | // If you also want the dispatcher to return a particular result, rig it for |
342 | 30 | // that result first (using one of the other rig...Dispatcher functions) and | 30 | // that result first (using one of the other rig...Dispatcher functions) and |
343 | 31 | // then chain the recording dispatcher in front of it. | 31 | // then chain the recording dispatcher in front of it. |
345 | 32 | func rigRecordingDispatcher(record *[]*X509Request) { | 32 | func rigRecordingDispatcher(record *[]*x509Request) { |
346 | 33 | previousDispatcher := _X509Dispatcher | 33 | previousDispatcher := _X509Dispatcher |
348 | 34 | _X509Dispatcher = func(session *X509Session, request *X509Request) (*X509Response, error) { | 34 | _X509Dispatcher = func(session *x509Session, request *x509Request) (*x509Response, error) { |
349 | 35 | *record = append(*record, request) | 35 | *record = append(*record, request) |
350 | 36 | return previousDispatcher(session, request) | 36 | return previousDispatcher(session, request) |
351 | 37 | } | 37 | } |
352 | @@ -39,8 +39,8 @@ | |||
353 | 39 | 39 | ||
354 | 40 | // rigFixedResponseDispatcher sets up a request dispatcher that always returns | 40 | // rigFixedResponseDispatcher sets up a request dispatcher that always returns |
355 | 41 | // a prepared response. | 41 | // a prepared response. |
358 | 42 | func rigFixedResponseDispatcher(response *X509Response) { | 42 | func rigFixedResponseDispatcher(response *x509Response) { |
359 | 43 | _X509Dispatcher = func(*X509Session, *X509Request) (*X509Response, error) { | 43 | _X509Dispatcher = func(*x509Session, *x509Request) (*x509Response, error) { |
360 | 44 | return response, nil | 44 | return response, nil |
361 | 45 | } | 45 | } |
362 | 46 | } | 46 | } |
363 | @@ -48,7 +48,7 @@ | |||
364 | 48 | // rigFailingDispatcher sets up a request dispatcher that returns a given | 48 | // rigFailingDispatcher sets up a request dispatcher that returns a given |
365 | 49 | // error. | 49 | // error. |
366 | 50 | func rigFailingDispatcher(failure error) { | 50 | func rigFailingDispatcher(failure error) { |
368 | 51 | _X509Dispatcher = func(*X509Session, *X509Request) (*X509Response, error) { | 51 | _X509Dispatcher = func(*x509Session, *x509Request) (*x509Response, error) { |
369 | 52 | return nil, failure | 52 | return nil, failure |
370 | 53 | } | 53 | } |
371 | 54 | } | 54 | } |
372 | @@ -125,14 +125,14 @@ | |||
373 | 125 | } | 125 | } |
374 | 126 | 126 | ||
375 | 127 | func (suite *X509SessionSuite) TestNewX509SessionCreation(c *C) { | 127 | func (suite *X509SessionSuite) TestNewX509SessionCreation(c *C) { |
377 | 128 | _, err := NewX509Session("subscriptionid", "azure.pem") | 128 | _, err := newX509Session("subscriptionid", "azure.pem") |
378 | 129 | c.Assert(err, IsNil) | 129 | c.Assert(err, IsNil) |
379 | 130 | } | 130 | } |
380 | 131 | 131 | ||
381 | 132 | func (suite *X509SessionSuite) TestGetServerErrorProducesServerError(c *C) { | 132 | func (suite *X509SessionSuite) TestGetServerErrorProducesServerError(c *C) { |
382 | 133 | msg := "huhwhat" | 133 | msg := "huhwhat" |
383 | 134 | status := http.StatusNotFound | 134 | status := http.StatusNotFound |
385 | 135 | session, err := NewX509Session("subscriptionid", "azure.pem") | 135 | session, err := newX509Session("subscriptionid", "azure.pem") |
386 | 136 | c.Assert(err, IsNil) | 136 | c.Assert(err, IsNil) |
387 | 137 | 137 | ||
388 | 138 | err = session.getServerError(status, msg) | 138 | err = session.getServerError(status, msg) |
389 | @@ -148,7 +148,7 @@ | |||
390 | 148 | http.StatusOK, | 148 | http.StatusOK, |
391 | 149 | http.StatusNoContent, | 149 | http.StatusNoContent, |
392 | 150 | } | 150 | } |
394 | 151 | session, err := NewX509Session("subscriptionid", "azure.pem") | 151 | session, err := newX509Session("subscriptionid", "azure.pem") |
395 | 152 | c.Assert(err, IsNil) | 152 | c.Assert(err, IsNil) |
396 | 153 | 153 | ||
397 | 154 | for _, status := range goodCodes { | 154 | for _, status := range goodCodes { |
398 | @@ -166,7 +166,7 @@ | |||
399 | 166 | http.StatusInternalServerError, | 166 | http.StatusInternalServerError, |
400 | 167 | http.StatusNotImplemented, | 167 | http.StatusNotImplemented, |
401 | 168 | } | 168 | } |
403 | 169 | session, err := NewX509Session("subscriptionid", "azure.pem") | 169 | session, err := newX509Session("subscriptionid", "azure.pem") |
404 | 170 | c.Assert(err, IsNil) | 170 | c.Assert(err, IsNil) |
405 | 171 | 171 | ||
406 | 172 | for _, status := range badCodes { | 172 | for _, status := range badCodes { |
407 | @@ -177,15 +177,15 @@ | |||
408 | 177 | func (suite *X509SessionSuite) TestGetIssuesRequest(c *C) { | 177 | func (suite *X509SessionSuite) TestGetIssuesRequest(c *C) { |
409 | 178 | subscriptionID := "subscriptionID" | 178 | subscriptionID := "subscriptionID" |
410 | 179 | uri := "resource" | 179 | uri := "resource" |
412 | 180 | session, err := NewX509Session(subscriptionID, "cert.pem") | 180 | session, err := newX509Session(subscriptionID, "cert.pem") |
413 | 181 | c.Assert(err, IsNil) | 181 | c.Assert(err, IsNil) |
414 | 182 | // Record incoming requests, and have them return a given reply. | 182 | // Record incoming requests, and have them return a given reply. |
416 | 183 | fixedResponse := X509Response{ | 183 | fixedResponse := x509Response{ |
417 | 184 | StatusCode: http.StatusOK, | 184 | StatusCode: http.StatusOK, |
418 | 185 | Body: []byte("Response body"), | 185 | Body: []byte("Response body"), |
419 | 186 | } | 186 | } |
420 | 187 | rigFixedResponseDispatcher(&fixedResponse) | 187 | rigFixedResponseDispatcher(&fixedResponse) |
422 | 188 | recordedRequests := make([]*X509Request, 0) | 188 | recordedRequests := make([]*x509Request, 0) |
423 | 189 | rigRecordingDispatcher(&recordedRequests) | 189 | rigRecordingDispatcher(&recordedRequests) |
424 | 190 | 190 | ||
425 | 191 | receivedBody, err := session.get(uri) | 191 | receivedBody, err := session.get(uri) |
426 | @@ -199,7 +199,7 @@ | |||
427 | 199 | } | 199 | } |
428 | 200 | 200 | ||
429 | 201 | func (suite *X509SessionSuite) TestGetReportsClientSideError(c *C) { | 201 | func (suite *X509SessionSuite) TestGetReportsClientSideError(c *C) { |
431 | 202 | session, err := NewX509Session("subscriptionid", "cert.pem") | 202 | session, err := newX509Session("subscriptionid", "cert.pem") |
432 | 203 | msg := "could not dispatch request" | 203 | msg := "could not dispatch request" |
433 | 204 | rigFailingDispatcher(fmt.Errorf(msg)) | 204 | rigFailingDispatcher(fmt.Errorf(msg)) |
434 | 205 | 205 | ||
435 | @@ -211,8 +211,8 @@ | |||
436 | 211 | } | 211 | } |
437 | 212 | 212 | ||
438 | 213 | func (suite *X509SessionSuite) TestGetReportsServerSideError(c *C) { | 213 | func (suite *X509SessionSuite) TestGetReportsServerSideError(c *C) { |
441 | 214 | session, err := NewX509Session("subscriptionid", "cert.pem") | 214 | session, err := newX509Session("subscriptionid", "cert.pem") |
442 | 215 | fixedResponse := X509Response{ | 215 | fixedResponse := x509Response{ |
443 | 216 | StatusCode: http.StatusForbidden, | 216 | StatusCode: http.StatusForbidden, |
444 | 217 | Body: []byte("Body"), | 217 | Body: []byte("Body"), |
445 | 218 | } | 218 | } |
446 | @@ -231,15 +231,15 @@ | |||
447 | 231 | uri := "resource" | 231 | uri := "resource" |
448 | 232 | requestBody := []byte("Request body") | 232 | requestBody := []byte("Request body") |
449 | 233 | requestContentType := "bogusContentType" | 233 | requestContentType := "bogusContentType" |
451 | 234 | session, err := NewX509Session(subscriptionID, "cert.pem") | 234 | session, err := newX509Session(subscriptionID, "cert.pem") |
452 | 235 | c.Assert(err, IsNil) | 235 | c.Assert(err, IsNil) |
453 | 236 | // Record incoming requests, and have them return a given reply. | 236 | // Record incoming requests, and have them return a given reply. |
455 | 237 | fixedResponse := X509Response{ | 237 | fixedResponse := x509Response{ |
456 | 238 | StatusCode: http.StatusOK, | 238 | StatusCode: http.StatusOK, |
457 | 239 | Body: []byte("Response body"), | 239 | Body: []byte("Response body"), |
458 | 240 | } | 240 | } |
459 | 241 | rigFixedResponseDispatcher(&fixedResponse) | 241 | rigFixedResponseDispatcher(&fixedResponse) |
461 | 242 | recordedRequests := make([]*X509Request, 0) | 242 | recordedRequests := make([]*x509Request, 0) |
462 | 243 | rigRecordingDispatcher(&recordedRequests) | 243 | rigRecordingDispatcher(&recordedRequests) |
463 | 244 | 244 | ||
464 | 245 | receivedBody, err := session.post(uri, requestBody, requestContentType) | 245 | receivedBody, err := session.post(uri, requestBody, requestContentType) |
465 | @@ -255,7 +255,7 @@ | |||
466 | 255 | } | 255 | } |
467 | 256 | 256 | ||
468 | 257 | func (suite *X509SessionSuite) TestPostReportsClientSideError(c *C) { | 257 | func (suite *X509SessionSuite) TestPostReportsClientSideError(c *C) { |
470 | 258 | session, err := NewX509Session("subscriptionid", "cert.pem") | 258 | session, err := newX509Session("subscriptionid", "cert.pem") |
471 | 259 | msg := "could not dispatch request" | 259 | msg := "could not dispatch request" |
472 | 260 | rigFailingDispatcher(fmt.Errorf(msg)) | 260 | rigFailingDispatcher(fmt.Errorf(msg)) |
473 | 261 | 261 | ||
474 | @@ -267,8 +267,8 @@ | |||
475 | 267 | } | 267 | } |
476 | 268 | 268 | ||
477 | 269 | func (suite *X509SessionSuite) TestPostReportsServerSideError(c *C) { | 269 | func (suite *X509SessionSuite) TestPostReportsServerSideError(c *C) { |
480 | 270 | session, err := NewX509Session("subscriptionid", "cert.pem") | 270 | session, err := newX509Session("subscriptionid", "cert.pem") |
481 | 271 | fixedResponse := X509Response{ | 271 | fixedResponse := x509Response{ |
482 | 272 | StatusCode: http.StatusForbidden, | 272 | StatusCode: http.StatusForbidden, |
483 | 273 | Body: []byte("Body"), | 273 | Body: []byte("Body"), |
484 | 274 | } | 274 | } |
485 | @@ -285,12 +285,12 @@ | |||
486 | 285 | func (suite *X509SessionSuite) TestDeleteIssuesRequest(c *C) { | 285 | func (suite *X509SessionSuite) TestDeleteIssuesRequest(c *C) { |
487 | 286 | subscriptionID := "subscriptionID" | 286 | subscriptionID := "subscriptionID" |
488 | 287 | uri := "resource" | 287 | uri := "resource" |
490 | 288 | session, err := NewX509Session(subscriptionID, "cert.pem") | 288 | session, err := newX509Session(subscriptionID, "cert.pem") |
491 | 289 | c.Assert(err, IsNil) | 289 | c.Assert(err, IsNil) |
492 | 290 | // Record incoming requests, and have them return a given reply. | 290 | // Record incoming requests, and have them return a given reply. |
494 | 291 | fixedResponse := X509Response{StatusCode: http.StatusOK} | 291 | fixedResponse := x509Response{StatusCode: http.StatusOK} |
495 | 292 | rigFixedResponseDispatcher(&fixedResponse) | 292 | rigFixedResponseDispatcher(&fixedResponse) |
497 | 293 | recordedRequests := make([]*X509Request, 0) | 293 | recordedRequests := make([]*x509Request, 0) |
498 | 294 | rigRecordingDispatcher(&recordedRequests) | 294 | rigRecordingDispatcher(&recordedRequests) |
499 | 295 | 295 | ||
500 | 296 | err = session.delete(uri) | 296 | err = session.delete(uri) |
501 | @@ -306,14 +306,14 @@ | |||
502 | 306 | subscriptionID := "subscriptionID" | 306 | subscriptionID := "subscriptionID" |
503 | 307 | uri := "resource" | 307 | uri := "resource" |
504 | 308 | requestBody := []byte("Request body") | 308 | requestBody := []byte("Request body") |
506 | 309 | session, err := NewX509Session(subscriptionID, "cert.pem") | 309 | session, err := newX509Session(subscriptionID, "cert.pem") |
507 | 310 | c.Assert(err, IsNil) | 310 | c.Assert(err, IsNil) |
508 | 311 | // Record incoming requests, and have them return a given reply. | 311 | // Record incoming requests, and have them return a given reply. |
510 | 312 | fixedResponse := X509Response{ | 312 | fixedResponse := x509Response{ |
511 | 313 | StatusCode: http.StatusOK, | 313 | StatusCode: http.StatusOK, |
512 | 314 | } | 314 | } |
513 | 315 | rigFixedResponseDispatcher(&fixedResponse) | 315 | rigFixedResponseDispatcher(&fixedResponse) |
515 | 316 | recordedRequests := make([]*X509Request, 0) | 316 | recordedRequests := make([]*x509Request, 0) |
516 | 317 | rigRecordingDispatcher(&recordedRequests) | 317 | rigRecordingDispatcher(&recordedRequests) |
517 | 318 | 318 | ||
518 | 319 | err = session.put(uri, requestBody) | 319 | err = session.put(uri, requestBody) |
"Just un-exporting some identifiers is a huge amount of pointless diff in Go"
Sigh :/