web: Change /rpc to /webrpc

This commit is contained in:
Harshavardhana 2016-04-07 23:44:08 -07:00
parent bad2f2afbb
commit fbd02d530d
4 changed files with 33 additions and 44 deletions

View File

@ -148,7 +148,7 @@ func initServerConfig(c *cli.Context) {
// Check server arguments. // Check server arguments.
func checkServerSyntax(c *cli.Context) { func checkServerSyntax(c *cli.Context) {
if !c.Args().Present() || c.Args().First() == "help" { if c.Args().First() == "help" {
cli.ShowCommandHelpAndExit(c, "server", 1) cli.ShowCommandHelpAndExit(c, "server", 1)
} }
if len(c.Args()) > 2 { if len(c.Args()) > 2 {

4
vendor/vendor.json vendored
View File

@ -89,8 +89,8 @@
}, },
{ {
"path": "github.com/minio/miniobrowser", "path": "github.com/minio/miniobrowser",
"revision": "baa867d829a5c61a9f347500fc625e3eca78b0f0", "revision": "248ebb823950963e302096cdb0bb8a515eb21161",
"revisionTime": "2016-04-02T15:35:59-07:00" "revisionTime": "2016-04-08T01:34:18-07:00"
}, },
{ {
"path": "github.com/mitchellh/go-homedir", "path": "github.com/mitchellh/go-homedir",

View File

@ -51,13 +51,13 @@ func isJWTReqAuthenticated(req *http.Request) bool {
return token.Valid return token.Valid
} }
// GenericArgs - empty struct for calls that don't accept arguments // WebGenericArgs - empty struct for calls that don't accept arguments
// for ex. ServerInfo, GenerateAuth // for ex. ServerInfo, GenerateAuth
type GenericArgs struct{} type WebGenericArgs struct{}
// GenericRep - reply structure for calls for which reply is success/failure // WebGenericRep - reply structure for calls for which reply is success/failure
// for ex. RemoveObject MakeBucket // for ex. RemoveObject MakeBucket
type GenericRep struct { type WebGenericRep struct {
UIVersion string `json:"uiVersion"` UIVersion string `json:"uiVersion"`
} }
@ -71,7 +71,7 @@ type ServerInfoRep struct {
} }
// ServerInfo - get server info. // ServerInfo - get server info.
func (web *webAPI) ServerInfo(r *http.Request, args *GenericArgs, reply *ServerInfoRep) error { func (web *webAPI) ServerInfo(r *http.Request, args *WebGenericArgs, reply *ServerInfoRep) error {
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
@ -106,7 +106,7 @@ type DiskInfoRep struct {
} }
// DiskInfo - get disk statistics. // DiskInfo - get disk statistics.
func (web *webAPI) DiskInfo(r *http.Request, args *GenericArgs, reply *DiskInfoRep) error { func (web *webAPI) DiskInfo(r *http.Request, args *WebGenericArgs, reply *DiskInfoRep) error {
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
@ -125,7 +125,7 @@ type MakeBucketArgs struct {
} }
// MakeBucket - make a bucket. // MakeBucket - make a bucket.
func (web *webAPI) MakeBucket(r *http.Request, args *MakeBucketArgs, reply *GenericRep) error { func (web *webAPI) MakeBucket(r *http.Request, args *MakeBucketArgs, reply *WebGenericRep) error {
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
@ -152,7 +152,7 @@ type WebBucketInfo struct {
} }
// ListBuckets - list buckets api. // ListBuckets - list buckets api.
func (web *webAPI) ListBuckets(r *http.Request, args *GenericArgs, reply *ListBucketsRep) error { func (web *webAPI) ListBuckets(r *http.Request, args *WebGenericArgs, reply *ListBucketsRep) error {
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
@ -237,7 +237,7 @@ type RemoveObjectArgs struct {
} }
// RemoveObject - removes an object. // RemoveObject - removes an object.
func (web *webAPI) RemoveObject(r *http.Request, args *RemoveObjectArgs, reply *GenericRep) error { func (web *webAPI) RemoveObject(r *http.Request, args *RemoveObjectArgs, reply *WebGenericRep) error {
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
@ -283,7 +283,7 @@ type GenerateAuthReply struct {
UIVersion string `json:"uiVersion"` UIVersion string `json:"uiVersion"`
} }
func (web webAPI) GenerateAuth(r *http.Request, args *GenericArgs, reply *GenerateAuthReply) error { func (web webAPI) GenerateAuth(r *http.Request, args *WebGenericArgs, reply *GenerateAuthReply) error {
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
@ -344,7 +344,7 @@ type GetAuthReply struct {
} }
// GetAuth - return accessKey and secretKey credentials. // GetAuth - return accessKey and secretKey credentials.
func (web *webAPI) GetAuth(r *http.Request, args *GenericArgs, reply *GetAuthReply) error { func (web *webAPI) GetAuth(r *http.Request, args *WebGenericArgs, reply *GetAuthReply) error {
if !isJWTReqAuthenticated(r) { if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"} return &json2.Error{Message: "Unauthorized request"}
} }
@ -387,6 +387,7 @@ func (web *webAPI) Download(w http.ResponseWriter, r *http.Request) {
writeWebErrorResponse(w, errInvalidToken) writeWebErrorResponse(w, errInvalidToken)
return return
} }
// Add content disposition.
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filepath.Base(object))) w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filepath.Base(object)))
objReader, err := web.ObjectAPI.GetObject(bucket, object, 0) objReader, err := web.ObjectAPI.GetObject(bucket, object, 0)
@ -402,47 +403,35 @@ func (web *webAPI) Download(w http.ResponseWriter, r *http.Request) {
// writeWebErrorResponse - set HTTP status code and write error description to the body. // writeWebErrorResponse - set HTTP status code and write error description to the body.
func writeWebErrorResponse(w http.ResponseWriter, err error) { func writeWebErrorResponse(w http.ResponseWriter, err error) {
// Handle invalid token as a special case.
if err == errInvalidToken { if err == errInvalidToken {
w.WriteHeader(http.StatusForbidden) w.WriteHeader(http.StatusForbidden)
w.Write([]byte(err.Error())) w.Write([]byte(err.Error()))
return return
} }
// Convert error type to api error code.
var apiErrCode APIErrorCode
switch err.(type) { switch err.(type) {
case RootPathFull: case RootPathFull:
apiErr := getAPIError(ErrRootPathFull) apiErrCode = ErrRootPathFull
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
case BucketNotFound: case BucketNotFound:
apiErr := getAPIError(ErrNoSuchBucket) apiErrCode = ErrNoSuchBucket
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
case BucketNameInvalid: case BucketNameInvalid:
apiErr := getAPIError(ErrInvalidBucketName) apiErrCode = ErrInvalidBucketName
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
case BadDigest: case BadDigest:
apiErr := getAPIError(ErrBadDigest) apiErrCode = ErrBadDigest
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
case IncompleteBody: case IncompleteBody:
apiErr := getAPIError(ErrIncompleteBody) apiErrCode = ErrIncompleteBody
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
case ObjectExistsAsPrefix: case ObjectExistsAsPrefix:
apiErr := getAPIError(ErrObjectExistsAsPrefix) apiErrCode = ErrObjectExistsAsPrefix
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
case ObjectNotFound: case ObjectNotFound:
apiErr := getAPIError(ErrNoSuchKey) apiErrCode = ErrNoSuchKey
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
case ObjectNameInvalid: case ObjectNameInvalid:
apiErr := getAPIError(ErrNoSuchKey) apiErrCode = ErrNoSuchKey
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
default: default:
apiErr := getAPIError(ErrInternalError) apiErrCode = ErrInternalError
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
} }
apiErr := getAPIError(apiErrCode)
w.WriteHeader(apiErr.HTTPStatusCode)
w.Write([]byte(apiErr.Description))
} }

View File

@ -62,7 +62,7 @@ func registerWebRouter(mux *router.Router, web *webAPI) {
// Initialize a new json2 codec. // Initialize a new json2 codec.
codec := json2.NewCodec() codec := json2.NewCodec()
// Minio rpc router // Minio browser router.
webBrowserRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter() webBrowserRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter()
// Initialize json rpc handlers. // Initialize json rpc handlers.
@ -71,8 +71,8 @@ func registerWebRouter(mux *router.Router, web *webAPI) {
webRPC.RegisterCodec(codec, "application/json; charset=UTF-8") webRPC.RegisterCodec(codec, "application/json; charset=UTF-8")
webRPC.RegisterService(web, "Web") webRPC.RegisterService(web, "Web")
// RPC handler at URI - /minio/rpc // RPC handler at URI - /minio/webrpc
webBrowserRouter.Methods("POST").Path("/rpc").Handler(webRPC) webBrowserRouter.Methods("POST").Path("/webrpc").Handler(webRPC)
webBrowserRouter.Methods("PUT").Path("/upload/{bucket}/{object:.+}").HandlerFunc(web.Upload) webBrowserRouter.Methods("PUT").Path("/upload/{bucket}/{object:.+}").HandlerFunc(web.Upload)
webBrowserRouter.Methods("GET").Path("/download/{bucket}/{object:.+}").Queries("token", "").HandlerFunc(web.Download) webBrowserRouter.Methods("GET").Path("/download/{bucket}/{object:.+}").Queries("token", "").HandlerFunc(web.Download)