Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1884)

Issue 38370043: state/apiserver: Charm upload through HTTP (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 5 months ago by dimitern
Modified:
10 years, 5 months ago
Reviewers:
mp+198076, rog
Visibility:
Public.

Description

state/apiserver: Charm upload through HTTP WIP: for discussion only https://code.launchpad.net/~dimitern/juju-core/220-post-charm-upload/+merge/198076 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 22
Unified diffs Side-by-side diffs Delta from patch set Stats (+295 lines, -18 lines) Patch
A [revision details] View 1 chunk +2 lines, -0 lines 0 comments Download
M state/apiserver/admin.go View 2 chunks +25 lines, -17 lines 0 comments Download
M state/apiserver/apiserver.go View 3 chunks +105 lines, -1 line 18 comments Download
M state/apiserver/server_test.go View 2 chunks +163 lines, -0 lines 4 comments Download

Messages

Total messages: 2
rog
Looks fantastic in general so far. Some minor comments below, but nothing substantive. https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go File ...
10 years, 5 months ago (2013-12-06 15:30:40 UTC) #1
dimitern
10 years, 5 months ago (2013-12-10 14:48:36 UTC) #2
Replying to comments, then closing this CL, because I realized I have to split
it in two and the prerequisite is proposed as
https://codereview.appspot.com/40160043, so I'll delete this branch and
repropose it.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go
File state/apiserver/apiserver.go (right):

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:150: mux.Handle("/charms",
http.HandlerFunc(srv.charmsHandler))
On 2013/12/06 15:30:40, rog wrote:
> you could call mux.HandleFunc directly.

Done differently, by extracting a charmsHandler as http.Handler.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:155: func (srv *Server) httpAuthenticate(w
http.ResponseWriter, r *http.Request) error {
On 2013/12/06 15:30:40, rog wrote:
> I think we should probably return the authenticated tag
> from this function, and check in the caller that it's a
> user tag (we don't want agents to be able to post charms).

Even better, now after a successful authentication I check the tag to make sure
it's a user and returning ErrBadCreds if it's not.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:180: func (srv *Server) requireHttpAuth(w
http.ResponseWriter, r *http.Request) {
On 2013/12/06 15:30:40, rog wrote:
> I think I'd call this authError or something that
> implies it's generating an authentication error.

Done.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:182: w.WriteHeader(http.StatusUnauthorized)
On 2013/12/06 15:30:40, rog wrote:
> http.Error(w, "401 Unauthorized", http.StatusUnauthorized)
> 
> would be equivalent and slightly more idiomatic.

Since I changed the response to be JSON encoded, this is done slightly
differently.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:192: http.Error(w, fmt.Sprintf("unsupported method:
%s", r.Method), http.StatusMethodNotAllowed)
On 2013/12/06 15:30:40, rog wrote:
> s/: %s/%q/ ?

Done.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:213: }
On 2013/12/06 15:30:40, rog wrote:
> Should we check that the MIME type is correct before proceeding?

Wasn't sure if I can, but I as discussed, now this is done.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:219: defer tempFile.Close()
On 2013/12/06 15:30:40, rog wrote:
> also:
> 
> defer os.Remove(tempfile.Name())

Done.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:220: buffer := make([]byte, 100000)
On 2013/12/06 15:30:40, rog wrote:
> I think you can just do:
> 
> err := io.Copy(tempFile, part)
> instead of the loop below.

Great idea! I was sure I'm overcomplicating things :) Done.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/apiserver.go#n...
state/apiserver/apiserver.go:243: }
On 2013/12/06 15:30:40, rog wrote:
> Presumably this is where we'll actually put the charm into state.

Yes, exactly.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/server_test.go
File state/apiserver/server_test.go (right):

https://codereview.appspot.com/38370043/diff/1/state/apiserver/server_test.go...
state/apiserver/server_test.go:260: func (s *charmsSuite) uploadRequest(c *gc.C,
uri string, paths ...string) (*http.Response, error) {
On 2013/12/06 15:30:40, rog wrote:
> Rather than passing file paths here, it might work
> out more nicely to pass io.Readers - then most of the
> tests below won't need to create temporary directories
> or files.

I'm not sure, I'll revisit this after all tests are done.

https://codereview.appspot.com/38370043/diff/1/state/apiserver/server_test.go...
state/apiserver/server_test.go:261: body := &bytes.Buffer{}
On 2013/12/06 15:30:40, rog wrote:
> or
> var body bytes.Buffer

Done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b