Merge lp:~mattyw/sharinfoo/no-tls-option into lp:sharinfoo

Proposed by Matthew Williams on 2014-01-20
Status: Needs review
Proposed branch: lp:~mattyw/sharinfoo/no-tls-option
Merge into: lp:sharinfoo
Diff against target: 318 lines (+50/-42)
4 files modified
client/client.go (+21/-14)
client/client_test.go (+14/-14)
cmd/shfoo/main.go (+8/-7)
tests/client_test.py (+7/-7)
To merge this branch: bzr merge lp:~mattyw/sharinfoo/no-tls-option
Reviewer Review Type Date Requested Status
Vincenzo Di Somma (community) 2014-01-20 Approve on 2014-01-20
Casey Marshall 2014-01-20 Pending
Review via email: mp+202291@code.launchpad.net

Commit message

Added an option to the client to allow communication via tls (default on). Tests use the client with tls off

Description of the change

Added an option to the client to allow communication via tls (default on). Tests use the client with tls off

To post a comment you must log in.
Vincenzo Di Somma (vds) :
review: Approve

Unmerged revisions

16. By Matthew Williams on 2014-01-20

added support for a no tls option in the client, tests use option turned on

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/client.go'
2--- client/client.go 2014-01-14 17:37:07 +0000
3+++ client/client.go 2014-01-20 11:33:24 +0000
4@@ -23,6 +23,13 @@
5 return nil
6 }
7
8+func scheme(noTls bool) string {
9+ if noTls {
10+ return "http"
11+ }
12+ return "https"
13+}
14+
15 func Login(user string) error {
16 ssoData, err := SSOLogin(user)
17 if err != nil {
18@@ -67,13 +74,13 @@
19 return string(buf), nil
20 }
21
22-func Delete(addr, path string) error {
23+func Delete(addr, path string, noTls bool) error {
24 authString, err := loadAuth()
25 if err != nil {
26 return err
27 }
28 u := url.URL{
29- Scheme: "http",
30+ Scheme: scheme(noTls),
31 Host: addr,
32 Path: path,
33 }
34@@ -93,13 +100,13 @@
35 return err
36 }
37
38-func Put(addr, path string, data []byte) error {
39+func Put(addr, path string, data []byte, noTls bool) error {
40 authString, err := loadAuth()
41 if err != nil {
42 return err
43 }
44 u := url.URL{
45- Scheme: "http",
46+ Scheme: scheme(noTls),
47 Host: addr,
48 Path: path,
49 }
50@@ -120,13 +127,13 @@
51 return err
52 }
53
54-func Get(addr, path string) ([]byte, error) {
55+func Get(addr, path string, noTls bool) ([]byte, error) {
56 authString, err := loadAuth()
57 if err != nil {
58 return nil, err
59 }
60 u := url.URL{
61- Scheme: "http",
62+ Scheme: scheme(noTls),
63 Host: addr,
64 Path: path,
65 }
66@@ -145,7 +152,7 @@
67 return ioutil.ReadAll(resp.Body)
68 }
69
70-func Access(addr, path string) ([]byte, error) {
71+func Access(addr, path string, noTls bool) ([]byte, error) {
72 authString, err := loadAuth()
73 if err != nil {
74 return nil, err
75@@ -154,7 +161,7 @@
76 query.Add("meta", "1")
77
78 u := url.URL{
79- Scheme: "http",
80+ Scheme: scheme(noTls),
81 Host: addr,
82 Path: path,
83 RawQuery: query.Encode(),
84@@ -174,13 +181,13 @@
85 return ioutil.ReadAll(resp.Body)
86 }
87
88-func Share(addr, path, with string) error {
89+func Share(addr, path, with string, noTls bool) error {
90 authString, err := loadAuth()
91 if err != nil {
92 return err
93 }
94 u := url.URL{
95- Scheme: "http",
96+ Scheme: scheme(noTls),
97 Host: addr,
98 Path: path,
99 }
100@@ -203,13 +210,13 @@
101 return err
102 }
103
104-func Sha(addr, path string) (string, error) {
105+func Sha(addr, path string, noTls bool) (string, error) {
106 authString, err := loadAuth()
107 if err != nil {
108 return "", err
109 }
110 u := url.URL{
111- Scheme: "http",
112+ Scheme: scheme(noTls),
113 Host: addr,
114 Path: path,
115 }
116@@ -229,7 +236,7 @@
117 return sha, nil
118 }
119
120-func List(addr string) ([]byte, error) {
121+func List(addr string, noTls bool) ([]byte, error) {
122 authString, err := loadAuth()
123 if err != nil {
124 return nil, err
125@@ -239,7 +246,7 @@
126 query.Add("listall", "1")
127
128 u := url.URL{
129- Scheme: "http",
130+ Scheme: scheme(noTls),
131 Host: addr,
132 Path: "/",
133 RawQuery: query.Encode(),
134
135=== modified file 'client/client_test.go'
136--- client/client_test.go 2014-01-15 14:20:35 +0000
137+++ client/client_test.go 2014-01-20 11:33:24 +0000
138@@ -22,12 +22,12 @@
139 func (s *ClientSuite) TestPutGet(c *gc.C) {
140 data := []byte("hello there")
141 path := "/test-data"
142- err := Put(addr, path, data)
143+ err := Put(addr, path, data, true)
144 c.Assert(err, gc.IsNil)
145- result, err := Get(addr, path)
146+ result, err := Get(addr, path, true)
147 c.Assert(err, gc.IsNil)
148 c.Assert(result, gc.DeepEquals, data)
149- err = Delete(addr, path)
150+ err = Delete(addr, path, true)
151 c.Assert(err, gc.IsNil)
152 }
153
154@@ -36,39 +36,39 @@
155 shareWith := "foo@foobar.com"
156 data := []byte("hello there")
157 path := "/test-share"
158- err := Put(addr, path, data)
159- c.Assert(err, gc.IsNil)
160- err = Share(addr, path, shareWith)
161- c.Assert(err, gc.IsNil)
162- owners, err := Access(addr, path)
163+ err := Put(addr, path, data, true)
164+ c.Assert(err, gc.IsNil)
165+ err = Share(addr, path, shareWith, true)
166+ c.Assert(err, gc.IsNil)
167+ owners, err := Access(addr, path, true)
168 err = json.Unmarshal(owners, &output)
169 c.Assert(err, gc.IsNil)
170 c.Assert(output[1], gc.DeepEquals, map[string]bool{shareWith: true})
171
172- err = Delete(addr, path)
173+ err = Delete(addr, path, true)
174 c.Assert(err, gc.IsNil)
175 }
176
177 func (s *ClientSuite) TestHead(c *gc.C) {
178 data := []byte("hello there")
179 path := "/test-data"
180- err := Put(addr, path, data)
181+ err := Put(addr, path, data, true)
182 c.Assert(err, gc.IsNil)
183 hasher.Write(data)
184 expected := base64.URLEncoding.EncodeToString(hasher.Sum(nil))
185
186- sha, err := Sha(addr, path)
187+ sha, err := Sha(addr, path, true)
188 c.Assert(err, gc.IsNil)
189 c.Assert(sha, gc.Equals, expected)
190 }
191
192 func (s *ClientSuite) putFile(data []byte, path string, c *gc.C) {
193- err := Put(addr, path, data)
194+ err := Put(addr, path, data, true)
195 c.Assert(err, gc.IsNil)
196 }
197
198 func (s *ClientSuite) deleteFile(path string, c *gc.C) {
199- err := Delete(addr, path)
200+ err := Delete(addr, path, true)
201 c.Assert(err, gc.IsNil)
202 }
203
204@@ -79,7 +79,7 @@
205 expected := []string{"/test-data-2", "/test-data"}
206 result := []string{}
207
208- list, err := List(addr)
209+ list, err := List(addr, true)
210 c.Assert(err, gc.IsNil)
211 s.deleteFile("/test-data", c)
212 s.deleteFile("/test-data-2", c)
213
214=== modified file 'cmd/shfoo/main.go'
215--- cmd/shfoo/main.go 2014-01-15 14:35:37 +0000
216+++ cmd/shfoo/main.go 2014-01-20 11:33:24 +0000
217@@ -36,6 +36,7 @@
218 var access *string = flag.String("access", "", "Get list of users with access to this path")
219 var sha *string = flag.String("sha", "", "Get the sha256 of the file")
220 var list *bool = flag.Bool("list", false, "List all files")
221+var noTls *bool = flag.Bool("no-tls", false, "Turn off https requests")
222
223 func die(err error) {
224 log.Println(err)
225@@ -48,36 +49,36 @@
226 case *login != "":
227 err = client.Login(*login)
228 case *del != "":
229- err = client.Delete(*addr, *del)
230+ err = client.Delete(*addr, *del, *noTls)
231 case *put != "":
232 data, err := ioutil.ReadAll(os.Stdin)
233 if err != nil {
234 log.Fatal(err)
235 }
236- err = client.Put(*addr, *put, data)
237+ err = client.Put(*addr, *put, data, *noTls)
238 case *get != "":
239- output, err := client.Get(*addr, *get)
240+ output, err := client.Get(*addr, *get, *noTls)
241 if err != nil {
242 die(err)
243 }
244 os.Stdout.Write(output)
245 case *share != "" && *with != "":
246- err = client.Share(*addr, *share, *with)
247+ err = client.Share(*addr, *share, *with, *noTls)
248 case *access != "":
249- output, err := client.Access(*addr, *access)
250+ output, err := client.Access(*addr, *access, *noTls)
251 if err != nil {
252 die(err)
253 }
254 os.Stdout.Write(output)
255 fmt.Println("")
256 case *sha != "":
257- output, err := client.Sha(*addr, *sha)
258+ output, err := client.Sha(*addr, *sha, *noTls)
259 if err != nil {
260 die(err)
261 }
262 fmt.Println(output)
263 case *list:
264- output, err := client.List(*addr)
265+ output, err := client.List(*addr, *noTls)
266 if err != nil {
267 die(err)
268 }
269
270=== modified file 'tests/client_test.py'
271--- tests/client_test.py 2014-01-15 14:35:37 +0000
272+++ tests/client_test.py 2014-01-20 11:33:24 +0000
273@@ -14,12 +14,12 @@
274
275 def put_command(src_file, dst_path):
276 out = subprocess.Popen(["cat", src_file], stdout=subprocess.PIPE)
277- return subprocess.check_call(["shfoo", "-put", "/%s" % dst_path],
278+ return subprocess.check_call(["shfoo", "-no-tls", "-put", "/%s" % dst_path],
279 stdin=out.stdout)
280
281
282 def get_command(dst_file, src_path):
283- get = subprocess.Popen(["shfoo", "-get", "/%s" % src_path],
284+ get = subprocess.Popen(["shfoo", "-no-tls", "-get", "/%s" % src_path],
285 stdout=subprocess.PIPE)
286 with open(dst_file, "w") as f:
287 for line in get.stdout:
288@@ -27,26 +27,26 @@
289
290
291 def list_command():
292- out = subprocess.Popen(["shfoo", "-list"], stdout=subprocess.PIPE)
293+ out = subprocess.Popen(["shfoo", "-no-tls", "-list"], stdout=subprocess.PIPE)
294 return out.stdout.read().strip()
295
296
297 def share_command(path, share):
298- subprocess.check_call(["shfoo", "-share", "/%s" % path, "-with", share])
299+ subprocess.check_call(["shfoo", "-no-tls", "-share", "/%s" % path, "-with", share])
300
301
302 def delete_command(path):
303- subprocess.check_call(["shfoo", "-delete", "/%s" % path])
304+ subprocess.check_call(["shfoo", "-no-tls", "-delete", "/%s" % path])
305
306
307 def sha_command(path):
308- out = subprocess.Popen(["shfoo", "-sha", "/%s" % path],
309+ out = subprocess.Popen(["shfoo", "-no-tls", "-sha", "/%s" % path],
310 stdout=subprocess.PIPE)
311 return out.stdout.read().strip()
312
313
314 def access_command(path):
315- out = subprocess.Popen(["shfoo", "-access", "/%s" % path],
316+ out = subprocess.Popen(["shfoo", "-no-tls", "-access", "/%s" % path],
317 stdout=subprocess.PIPE)
318 return json.loads(out.stdout.read())
319

Subscribers

People subscribed via source and target branches