Merge lp:~mattyw/sharinfoo/view-access-list into lp:sharinfoo

Proposed by Matthew Williams
Status: Merged
Merged at revision: 11
Proposed branch: lp:~mattyw/sharinfoo/view-access-list
Merge into: lp:sharinfoo
Diff against target: 148 lines (+81/-1)
3 files modified
README (+15/-0)
cmd/shfoo/main.go (+35/-0)
server.go (+31/-1)
To merge this branch: bzr merge lp:~mattyw/sharinfoo/view-access-list
Reviewer Review Type Date Requested Status
Casey Marshall Needs Fixing
Cloud Engineering: Green Squad Pending
Review via email: mp+200835@code.launchpad.net

Commit message

Added support for listing the owners and readers of a file
Also added a readme

Description of the change

Added support for listing the owners and readers of a file

To post a comment you must log in.
Revision history for this message
Casey Marshall (cmars) wrote :

I'm realizing now that we should be using POST for the metadata access rather than GET. GET is not typically used with encoded form values in the request. This will fix req.ParseForm and the req.Form.Get("meta") test for the access listing.

Reading the request body in FileServer.handle also breaks the content PUT, as the request Body can only be read once.

I would recommend the following changes:

1. Don't read req.Body in FileServer.handle(...). Get rid of the "meta=1" substring check.
2. In handleMetadata, process the request as an Access query if method == POST. PUT or DELETE should still dispatch to modifyOwner/modifyReader. Update the client accordingly.

review: Needs Fixing
Revision history for this message
Andrew W. Deane (andrew-w-deane) wrote :

You want to use POST to GET info out of the server? Whats the problem with
retrieving the encoded values on the server side?

On Wed, Jan 8, 2014 at 9:20 PM, Casey Marshall <<email address hidden>
> wrote:

> Review: Needs Fixing
>
> I'm realizing now that we should be using POST for the metadata access
> rather than GET. GET is not typically used with encoded form values in the
> request. This will fix req.ParseForm and the req.Form.Get("meta") test for
> the access listing.
>
> Reading the request body in FileServer.handle also breaks the content PUT,
> as the request Body can only be read once.
>
> I would recommend the following changes:
>
> 1. Don't read req.Body in FileServer.handle(...). Get rid of the "meta=1"
> substring check.
> 2. In handleMetadata, process the request as an Access query if method ==
> POST. PUT or DELETE should still dispatch to modifyOwner/modifyReader.
> Update the client accordingly.
> --
> https://code.launchpad.net/~mattyw/sharinfoo/view-access-list/+merge/200835
> Your team Cloud Engineering: Green Squad is requested to review the
> proposed merge of lp:~mattyw/sharinfoo/view-access-list into lp:sharinfoo.
>

9. By Matthew Williams

user query string in get instead of body

10. By Matthew Williams

use query instead of path

11. By Matthew Williams

proper way of parsing the query

Revision history for this message
Casey Marshall (cmars) wrote :

awd: you're absolutely correct, should be a GET. We don't need to send form data at all!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'README'
2--- README 1970-01-01 00:00:00 +0000
3+++ README 2014-01-09 12:50:37 +0000
4@@ -0,0 +1,15 @@
5+Running the server:
6+
7+$ ./shfood
8+
9+Running the client:
10+
11+First log in to SSO: ./shfoo -login email@addr
12+
13+Put a file: cat content | ./shfoo -put /some/arbitrary/path
14+
15+Get the file: ./shfoo -get /some/arbitrary/path > content
16+
17+Delete the file: ./shfoo -delete /some/arbitrary/path
18+
19+Grant read-access (if you own the file): ./shfoo -share /some/file -with email@addr
20
21=== modified file 'cmd/shfoo/main.go'
22--- cmd/shfoo/main.go 2014-01-02 18:21:18 +0000
23+++ cmd/shfoo/main.go 2014-01-09 12:50:37 +0000
24@@ -39,6 +39,7 @@
25 var share *string = flag.String("share", "", "Share read-access to content")
26 var with *string = flag.String("with", "", "Share read-access with user")
27 var addr *string = flag.String("http", "localhost:8080", "Remote sharinfoo address")
28+var access *string = flag.String("access", "", "Get list of users with access to this path")
29
30 func die(err error) {
31 log.Println(err)
32@@ -167,6 +168,38 @@
33 return err
34 }
35
36+func Access() error {
37+ authString, err := loadAuth()
38+ if err != nil {
39+ return err
40+ }
41+ query := url.Values{}
42+ query.Add("meta", "1")
43+
44+ u := url.URL{
45+ Scheme: "http",
46+ Host: *addr,
47+ Path: *access,
48+ RawQuery: query.Encode(),
49+ }
50+ req, err := http.NewRequest("GET", u.String(), nil)
51+ if err != nil {
52+ return err
53+ }
54+ req.Header.Add("Authorization", authString)
55+ resp, err := http.DefaultClient.Do(req)
56+ if err != nil {
57+ return err
58+ }
59+ if resp.StatusCode != 200 {
60+ return fmt.Errorf(resp.Status)
61+ }
62+ _, err = io.Copy(os.Stdout, resp.Body)
63+ fmt.Printf("\n")
64+ return err
65+ panic("no impl")
66+}
67+
68 func Share() error {
69 authString, err := loadAuth()
70 if err != nil {
71@@ -211,6 +244,8 @@
72 err = Get()
73 case *share != "" && *with != "":
74 err = Share()
75+ case *access != "":
76+ err = Access()
77 default:
78 err = fmt.Errorf("No action specified")
79 }
80
81=== modified file 'server.go'
82--- server.go 2014-01-07 21:43:04 +0000
83+++ server.go 2014-01-09 12:50:37 +0000
84@@ -17,10 +17,12 @@
85 package sharinfoo
86
87 import (
88+ "encoding/json"
89 "fmt"
90 "io"
91 "log"
92 "net/http"
93+ "net/url"
94 "os"
95 "strings"
96 )
97@@ -51,8 +53,13 @@
98 }
99
100 func (fs *FileServer) handle(w http.ResponseWriter, req *http.Request) {
101+ query, err := url.ParseQuery(req.URL.RawQuery)
102+ if err != nil {
103+ respError(w, err)
104+ return
105+ }
106 req.ParseForm()
107- if req.Form.Get("meta") == "1" {
108+ if req.Form.Get("meta") == "1" || query["meta"][0] == "1" {
109 fs.handleMetadata(w, req)
110 } else {
111 fs.handleContent(w, req)
112@@ -194,6 +201,21 @@
113 w.WriteHeader(http.StatusOK)
114 return
115 }
116+ if req.Method == "GET" {
117+ readers, err := fs.listOwnersAndReaders(req.Method, path, user, meta)
118+ if err != nil {
119+ respError(w, err)
120+ return
121+ }
122+ w.WriteHeader(http.StatusOK)
123+ jsonOutput, err := json.Marshal(readers)
124+ if err != nil {
125+ w.Write([]byte(fmt.Sprintf("%+v\n", readers)))
126+ return
127+ }
128+ w.Write(jsonOutput)
129+ return
130+ }
131 respError(w, fmt.Errorf("No such method supported"))
132 }
133
134@@ -209,6 +231,14 @@
135 return fmt.Errorf("Unsupported method")
136 }
137
138+func (fs *FileServer) listOwnersAndReaders(method, path, reader string, meta *SimpleMetadata) ([]map[string]bool, error) {
139+ switch method {
140+ case "GET":
141+ return []map[string]bool{meta.Owners, meta.Readers}, nil
142+ }
143+ return []map[string]bool{}, fmt.Errorf("Unsupported method")
144+}
145+
146 func (fs *FileServer) modifyReader(method, path, reader string, meta *SimpleMetadata) error {
147 switch method {
148 case "PUT":

Subscribers

People subscribed via source and target branches