mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
webrpc: Implement GetUIVersion json-rpc API.
This commit is contained in:
parent
4e328d7b2c
commit
bf6078df13
@ -16,7 +16,11 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/minio/minio/pkg/disk"
|
||||||
|
)
|
||||||
|
|
||||||
// MakeBucketArgs - make bucket args.
|
// MakeBucketArgs - make bucket args.
|
||||||
type MakeBucketArgs struct {
|
type MakeBucketArgs struct {
|
||||||
@ -32,12 +36,30 @@ type ServerInfoArgs struct{}
|
|||||||
// ListBucketsArgs - list bucket args.
|
// ListBucketsArgs - list bucket args.
|
||||||
type ListBucketsArgs struct{}
|
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.
|
// ListObjectsArgs - list object args.
|
||||||
type ListObjectsArgs struct {
|
type ListObjectsArgs struct {
|
||||||
BucketName string `json:"bucketName"`
|
BucketName string `json:"bucketName"`
|
||||||
Prefix string `json:"prefix"`
|
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.
|
// PutObjectURLArgs - args to generate url for upload access.
|
||||||
type PutObjectURLArgs struct {
|
type PutObjectURLArgs struct {
|
||||||
TargetHost string `json:"targetHost"`
|
TargetHost string `json:"targetHost"`
|
||||||
@ -45,6 +67,12 @@ type PutObjectURLArgs struct {
|
|||||||
ObjectName string `json:"objectName"`
|
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.
|
// GetObjectURLArgs - args to generate url for download access.
|
||||||
type GetObjectURLArgs struct {
|
type GetObjectURLArgs struct {
|
||||||
TargetHost string `json:"targetHost"`
|
TargetHost string `json:"targetHost"`
|
||||||
@ -52,6 +80,12 @@ type GetObjectURLArgs struct {
|
|||||||
ObjectName string `json:"objectName"`
|
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
|
// RemoveObjectArgs - args to remove an object
|
||||||
type RemoveObjectArgs struct {
|
type RemoveObjectArgs struct {
|
||||||
TargetHost string `json:"targetHost"`
|
TargetHost string `json:"targetHost"`
|
||||||
@ -59,6 +93,12 @@ type RemoveObjectArgs struct {
|
|||||||
ObjectName string `json:"objectName"`
|
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.
|
// BucketInfo container for list buckets metadata.
|
||||||
type BucketInfo struct {
|
type BucketInfo struct {
|
||||||
// The name of the bucket.
|
// The name of the bucket.
|
||||||
@ -85,15 +125,17 @@ type LoginArgs struct {
|
|||||||
Password string `json:"password" form:"password"`
|
Password string `json:"password" form:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthToken - auth token reply.
|
// LoginRep - login reply.
|
||||||
type AuthToken struct {
|
type LoginRep struct {
|
||||||
Token string `json:"token" form:"token"`
|
Token string `json:"token"`
|
||||||
|
UIVersion string `json:"uiVersion"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerInfo - server info reply.
|
// ServerInfoRep - server info reply.
|
||||||
type ServerInfo struct {
|
type ServerInfoRep struct {
|
||||||
MinioVersion string
|
MinioVersion string
|
||||||
MinioMemory string
|
MinioMemory string
|
||||||
MinioPlatform string
|
MinioPlatform string
|
||||||
MinioRuntime string
|
MinioRuntime string
|
||||||
|
UIVersion string `json:"uiVersion"`
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func isAuthenticated(req *http.Request) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerInfo - get server info.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
@ -72,17 +72,16 @@ func (web *WebAPI) ServerInfo(r *http.Request, args *ServerInfoArgs, reply *Serv
|
|||||||
runtime.GOOS,
|
runtime.GOOS,
|
||||||
runtime.GOARCH)
|
runtime.GOARCH)
|
||||||
goruntime := fmt.Sprintf("Version: %s | CPUs: %s", runtime.Version(), strconv.Itoa(runtime.NumCPU()))
|
goruntime := fmt.Sprintf("Version: %s | CPUs: %s", runtime.Version(), strconv.Itoa(runtime.NumCPU()))
|
||||||
serverInfo := ServerInfo{}
|
reply.MinioVersion = minioVersion
|
||||||
serverInfo.MinioVersion = minioVersion
|
reply.MinioMemory = mem
|
||||||
serverInfo.MinioMemory = mem
|
reply.MinioPlatform = platform
|
||||||
serverInfo.MinioPlatform = platform
|
reply.MinioRuntime = goruntime
|
||||||
serverInfo.MinioRuntime = goruntime
|
reply.UIVersion = uiVersion
|
||||||
*reply = serverInfo
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiskInfo - get disk statistics.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
@ -90,20 +89,22 @@ func (web *WebAPI) DiskInfo(r *http.Request, args *DiskInfoArgs, reply *disk.Inf
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
*reply = info
|
reply.DiskInfo = info
|
||||||
|
reply.UIVersion = uiVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeBucket - make a bucket.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
|
reply.UIVersion = uiVersion
|
||||||
return web.Client.MakeBucket(args.BucketName, "", "")
|
return web.Client.MakeBucket(args.BucketName, "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListBuckets - list buckets api.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
@ -112,16 +113,17 @@ func (web *WebAPI) ListBuckets(r *http.Request, args *ListBucketsArgs, reply *[]
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
*reply = append(*reply, BucketInfo{
|
reply.Buckets = append(reply.Buckets, BucketInfo{
|
||||||
Name: bucket.Name,
|
Name: bucket.Name,
|
||||||
CreationDate: bucket.CreationDate,
|
CreationDate: bucket.CreationDate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
reply.UIVersion = uiVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListObjects - list objects api.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
@ -147,8 +149,9 @@ func (web *WebAPI) ListObjects(r *http.Request, args *ListObjectsArgs, reply *[]
|
|||||||
}
|
}
|
||||||
objectInfo.ContentType = objectStatInfo.ContentType
|
objectInfo.ContentType = objectStatInfo.ContentType
|
||||||
}
|
}
|
||||||
*reply = append(*reply, objectInfo)
|
reply.Objects = append(reply.Objects, objectInfo)
|
||||||
}
|
}
|
||||||
|
reply.UIVersion = uiVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +171,7 @@ func getTargetHost(apiAddress, targetHost string) (string, *probe.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PutObjectURL - generates url for upload access.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
@ -184,12 +187,13 @@ func (web *WebAPI) PutObjectURL(r *http.Request, args *PutObjectURLArgs, reply *
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
*reply = signedURLStr
|
reply.URL = signedURLStr
|
||||||
|
reply.UIVersion = uiVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetObjectURL - generates url for download access.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
@ -215,26 +219,22 @@ func (web *WebAPI) GetObjectURL(r *http.Request, args *GetObjectURLArgs, reply *
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
*reply = signedURLStr
|
reply.URL = signedURLStr
|
||||||
|
reply.UIVersion = uiVersion
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveObject - removes an object.
|
// 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) {
|
if !isAuthenticated(r) {
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
}
|
}
|
||||||
|
reply.UIVersion = uiVersion
|
||||||
e := web.Client.RemoveObject(args.BucketName, args.ObjectName)
|
return web.Client.RemoveObject(args.BucketName, args.ObjectName)
|
||||||
if e != nil {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
*reply = 0
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login - user login handler.
|
// 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()
|
jwt := InitJWT()
|
||||||
if jwt.Authenticate(args.Username, args.Password) {
|
if jwt.Authenticate(args.Username, args.Password) {
|
||||||
token, err := jwt.GenerateToken(args.Username)
|
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())
|
return probe.WrapError(err.Trace())
|
||||||
}
|
}
|
||||||
reply.Token = token
|
reply.Token = token
|
||||||
return nil
|
reply.UIVersion = uiVersion
|
||||||
}
|
|
||||||
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) {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errUnAuthorizedRequest
|
return errUnAuthorizedRequest
|
||||||
|
Loading…
Reference in New Issue
Block a user