|
|
@ -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 |
|
|
|