webrpc: Implement GetUIVersion json-rpc API.

master
Krishna Srinivas 9 years ago
parent 4e328d7b2c
commit bf6078df13
  1. 54
      web-definitions.go
  2. 77
      web-handlers.go

@ -16,7 +16,11 @@
package main
import "time"
import (
"time"
"github.com/minio/minio/pkg/disk"
)
// MakeBucketArgs - make bucket args.
type MakeBucketArgs struct {
@ -32,12 +36,30 @@ type ServerInfoArgs struct{}
// ListBucketsArgs - list bucket args.
type ListBucketsArgs struct{}
// DiskInfoRep - disk info reply.
type DiskInfoRep struct {
DiskInfo disk.Info `json:"diskInfo"`
UIVersion string `json:"uiVersion"`
}
// ListBucketsRep - list buckets response
type ListBucketsRep struct {
Buckets []BucketInfo `json:"buckets"`
UIVersion string `json:"uiVersion"`
}
// ListObjectsArgs - list object args.
type ListObjectsArgs struct {
BucketName string `json:"bucketName"`
Prefix string `json:"prefix"`
}
// ListObjectsRep - list objects response.
type ListObjectsRep struct {
Objects []ObjectInfo `json:"objects"`
UIVersion string `json:"uiVersion"`
}
// PutObjectURLArgs - args to generate url for upload access.
type PutObjectURLArgs struct {
TargetHost string `json:"targetHost"`
@ -45,6 +67,12 @@ type PutObjectURLArgs struct {
ObjectName string `json:"objectName"`
}
// PutObjectURLRep - reply for presigned upload url request.
type PutObjectURLRep struct {
URL string `json:"url"`
UIVersion string `json:"uiVersion"`
}
// GetObjectURLArgs - args to generate url for download access.
type GetObjectURLArgs struct {
TargetHost string `json:"targetHost"`
@ -52,6 +80,12 @@ type GetObjectURLArgs struct {
ObjectName string `json:"objectName"`
}
// GetObjectURLRep - reply for presigned download url request.
type GetObjectURLRep struct {
URL string `json:"url"`
UIVersion string `json:"uiVersion"`
}
// RemoveObjectArgs - args to remove an object
type RemoveObjectArgs struct {
TargetHost string `json:"targetHost"`
@ -59,6 +93,12 @@ type RemoveObjectArgs struct {
ObjectName string `json:"objectName"`
}
// GenericRep - reply structure for calls for which reply is success/failure
// for ex. RemoveObject MakeBucket
type GenericRep struct {
UIVersion string `json:"uiVersion"`
}
// BucketInfo container for list buckets metadata.
type BucketInfo struct {
// The name of the bucket.
@ -85,15 +125,17 @@ type LoginArgs struct {
Password string `json:"password" form:"password"`
}
// AuthToken - auth token reply.
type AuthToken struct {
Token string `json:"token" form:"token"`
// LoginRep - login reply.
type LoginRep struct {
Token string `json:"token"`
UIVersion string `json:"uiVersion"`
}
// ServerInfo - server info reply.
type ServerInfo struct {
// ServerInfoRep - server info reply.
type ServerInfoRep struct {
MinioVersion string
MinioMemory string
MinioPlatform string
MinioRuntime string
UIVersion string `json:"uiVersion"`
}

@ -52,7 +52,7 @@ func isAuthenticated(req *http.Request) bool {
}
// ServerInfo - get server info.
func (web *WebAPI) ServerInfo(r *http.Request, args *ServerInfoArgs, reply *ServerInfo) error {
func (web *WebAPI) ServerInfo(r *http.Request, args *ServerInfoArgs, reply *ServerInfoRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
@ -72,17 +72,16 @@ func (web *WebAPI) ServerInfo(r *http.Request, args *ServerInfoArgs, reply *Serv
runtime.GOOS,
runtime.GOARCH)
goruntime := fmt.Sprintf("Version: %s | CPUs: %s", runtime.Version(), strconv.Itoa(runtime.NumCPU()))
serverInfo := ServerInfo{}
serverInfo.MinioVersion = minioVersion
serverInfo.MinioMemory = mem
serverInfo.MinioPlatform = platform
serverInfo.MinioRuntime = goruntime
*reply = serverInfo
reply.MinioVersion = minioVersion
reply.MinioMemory = mem
reply.MinioPlatform = platform
reply.MinioRuntime = goruntime
reply.UIVersion = uiVersion
return nil
}
// DiskInfo - get disk statistics.
func (web *WebAPI) DiskInfo(r *http.Request, args *DiskInfoArgs, reply *disk.Info) error {
func (web *WebAPI) DiskInfo(r *http.Request, args *DiskInfoArgs, reply *DiskInfoRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
@ -90,20 +89,22 @@ func (web *WebAPI) DiskInfo(r *http.Request, args *DiskInfoArgs, reply *disk.Inf
if e != nil {
return e
}
*reply = info
reply.DiskInfo = info
reply.UIVersion = uiVersion
return nil
}
// MakeBucket - make a bucket.
func (web *WebAPI) MakeBucket(r *http.Request, args *MakeBucketArgs, reply *string) error {
func (web *WebAPI) MakeBucket(r *http.Request, args *MakeBucketArgs, reply *GenericRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
reply.UIVersion = uiVersion
return web.Client.MakeBucket(args.BucketName, "", "")
}
// ListBuckets - list buckets api.
func (web *WebAPI) ListBuckets(r *http.Request, args *ListBucketsArgs, reply *[]BucketInfo) error {
func (web *WebAPI) ListBuckets(r *http.Request, args *ListBucketsArgs, reply *ListBucketsRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
@ -112,16 +113,17 @@ func (web *WebAPI) ListBuckets(r *http.Request, args *ListBucketsArgs, reply *[]
return e
}
for _, bucket := range buckets {
*reply = append(*reply, BucketInfo{
reply.Buckets = append(reply.Buckets, BucketInfo{
Name: bucket.Name,
CreationDate: bucket.CreationDate,
})
}
reply.UIVersion = uiVersion
return nil
}
// ListObjects - list objects api.
func (web *WebAPI) ListObjects(r *http.Request, args *ListObjectsArgs, reply *[]ObjectInfo) error {
func (web *WebAPI) ListObjects(r *http.Request, args *ListObjectsArgs, reply *ListObjectsRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
@ -147,8 +149,9 @@ func (web *WebAPI) ListObjects(r *http.Request, args *ListObjectsArgs, reply *[]
}
objectInfo.ContentType = objectStatInfo.ContentType
}
*reply = append(*reply, objectInfo)
reply.Objects = append(reply.Objects, objectInfo)
}
reply.UIVersion = uiVersion
return nil
}
@ -168,7 +171,7 @@ func getTargetHost(apiAddress, targetHost string) (string, *probe.Error) {
}
// PutObjectURL - generates url for upload access.
func (web *WebAPI) PutObjectURL(r *http.Request, args *PutObjectURLArgs, reply *string) error {
func (web *WebAPI) PutObjectURL(r *http.Request, args *PutObjectURLArgs, reply *PutObjectURLRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
@ -184,12 +187,13 @@ func (web *WebAPI) PutObjectURL(r *http.Request, args *PutObjectURLArgs, reply *
if e != nil {
return e
}
*reply = signedURLStr
reply.URL = signedURLStr
reply.UIVersion = uiVersion
return nil
}
// GetObjectURL - generates url for download access.
func (web *WebAPI) GetObjectURL(r *http.Request, args *GetObjectURLArgs, reply *string) error {
func (web *WebAPI) GetObjectURL(r *http.Request, args *GetObjectURLArgs, reply *GetObjectURLRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
@ -215,26 +219,22 @@ func (web *WebAPI) GetObjectURL(r *http.Request, args *GetObjectURLArgs, reply *
if e != nil {
return e
}
*reply = signedURLStr
reply.URL = signedURLStr
reply.UIVersion = uiVersion
return nil
}
// RemoveObject - removes an object.
func (web *WebAPI) RemoveObject(r *http.Request, args *RemoveObjectArgs, reply *int) error {
func (web *WebAPI) RemoveObject(r *http.Request, args *RemoveObjectArgs, reply *GenericRep) error {
if !isAuthenticated(r) {
return errUnAuthorizedRequest
}
e := web.Client.RemoveObject(args.BucketName, args.ObjectName)
if e != nil {
return e
}
*reply = 0
return nil
reply.UIVersion = uiVersion
return web.Client.RemoveObject(args.BucketName, args.ObjectName)
}
// Login - user login handler.
func (web *WebAPI) Login(r *http.Request, args *LoginArgs, reply *AuthToken) error {
func (web *WebAPI) Login(r *http.Request, args *LoginArgs, reply *LoginRep) error {
jwt := InitJWT()
if jwt.Authenticate(args.Username, args.Password) {
token, err := jwt.GenerateToken(args.Username)
@ -242,28 +242,7 @@ func (web *WebAPI) Login(r *http.Request, args *LoginArgs, reply *AuthToken) err
return probe.WrapError(err.Trace())
}
reply.Token = token
return nil
}
return errUnAuthorizedRequest
}
// RefreshToken - refresh token handler.
func (web *WebAPI) RefreshToken(r *http.Request, args *LoginArgs, reply *AuthToken) error {
if isAuthenticated(r) {
jwt := InitJWT()
token, err := jwt.GenerateToken(args.Username)
if err != nil {
return probe.WrapError(err.Trace())
}
reply.Token = token
return nil
}
return errUnAuthorizedRequest
}
// Logout - user logout.
func (web *WebAPI) Logout(r *http.Request, arg *string, reply *string) error {
if isAuthenticated(r) {
reply.UIVersion = uiVersion
return nil
}
return errUnAuthorizedRequest

Loading…
Cancel
Save