| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | /* | 
					
						
							|  |  |  |  * Minio Cloud Storage, (C) 2016 Minio, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | /// Auth operations
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Login - login handler.
 | 
					
						
							|  |  |  | func (c *controllerAPIHandlers) LoginHandler(args *RPCLoginArgs, reply *RPCLoginReply) error { | 
					
						
							|  |  |  | 	jwt, err := newJWT(defaultTokenExpiry) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if err = jwt.Authenticate(args.Username, args.Password); err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	token, err := jwt.GenerateToken(args.Username) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	reply.Token = token | 
					
						
							|  |  |  | 	reply.ServerVersion = Version | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | // HealListArgs - argument for ListObjects RPC.
 | 
					
						
							|  |  |  | type HealListArgs struct { | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 	// Authentication token generated by Login.
 | 
					
						
							|  |  |  | 	GenericArgs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | 	Bucket    string | 
					
						
							|  |  |  | 	Prefix    string | 
					
						
							|  |  |  | 	Marker    string | 
					
						
							|  |  |  | 	Delimiter string | 
					
						
							|  |  |  | 	MaxKeys   int | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | // HealListReply - reply object by ListObjects RPC.
 | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | type HealListReply struct { | 
					
						
							|  |  |  | 	IsTruncated bool | 
					
						
							|  |  |  | 	NextMarker  string | 
					
						
							|  |  |  | 	Objects     []string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | // ListObjects - list all objects that needs healing.
 | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | func (c *controllerAPIHandlers) ListObjectsHealHandler(args *HealListArgs, reply *HealListReply) error { | 
					
						
							| 
									
										
										
										
											2016-08-19 05:50:50 +08:00
										 |  |  | 	objAPI := c.ObjectAPI() | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | 	if objAPI == nil { | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 		return errVolumeBusy | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !isRPCTokenValid(args.Token) { | 
					
						
							|  |  |  | 		return errInvalidToken | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 	info, err := objAPI.ListObjectsHeal(args.Bucket, args.Prefix, args.Marker, args.Delimiter, args.MaxKeys) | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	reply.IsTruncated = info.IsTruncated | 
					
						
							|  |  |  | 	reply.NextMarker = info.NextMarker | 
					
						
							|  |  |  | 	for _, obj := range info.Objects { | 
					
						
							|  |  |  | 		reply.Objects = append(reply.Objects, obj.Name) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // HealObjectArgs - argument for HealObject RPC.
 | 
					
						
							|  |  |  | type HealObjectArgs struct { | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 	// Authentication token generated by Login.
 | 
					
						
							|  |  |  | 	GenericArgs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Name of the bucket.
 | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | 	Bucket string | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Name of the object.
 | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | 	Object string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // HealObjectReply - reply by HealObject RPC.
 | 
					
						
							|  |  |  | type HealObjectReply struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // HealObject - heal the object.
 | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | func (c *controllerAPIHandlers) HealObjectHandler(args *HealObjectArgs, reply *GenericReply) error { | 
					
						
							| 
									
										
										
										
											2016-08-19 05:50:50 +08:00
										 |  |  | 	objAPI := c.ObjectAPI() | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | 	if objAPI == nil { | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 		return errVolumeBusy | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 	if !isRPCTokenValid(args.Token) { | 
					
						
							|  |  |  | 		return errInvalidToken | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return objAPI.HealObject(args.Bucket, args.Object) | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-29 10:31:59 +08:00
										 |  |  | // HealObject - heal the object.
 | 
					
						
							|  |  |  | func (c *controllerAPIHandlers) HealDiskMetadataHandler(args *GenericArgs, reply *GenericReply) error { | 
					
						
							|  |  |  | 	objAPI := c.ObjectAPI() | 
					
						
							|  |  |  | 	if objAPI == nil { | 
					
						
							|  |  |  | 		return errVolumeBusy | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if !isRPCTokenValid(args.Token) { | 
					
						
							|  |  |  | 		return errInvalidToken | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-31 10:22:27 +08:00
										 |  |  | 	err := objAPI.HealDiskMetadata() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	go func() { | 
					
						
							|  |  |  | 		globalWakeupCh <- struct{}{} | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | 	return err | 
					
						
							| 
									
										
										
										
											2016-08-29 10:31:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | // ShutdownArgs - argument for Shutdown RPC.
 | 
					
						
							|  |  |  | type ShutdownArgs struct { | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 	// Authentication token generated by Login.
 | 
					
						
							|  |  |  | 	GenericArgs | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | 	// Should the server be restarted, call active connections are served before server
 | 
					
						
							|  |  |  | 	// is restarted.
 | 
					
						
							|  |  |  | 	Restart bool | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-25 01:14:14 +08:00
										 |  |  | // Shutdown - Shutsdown the server.
 | 
					
						
							|  |  |  | func (c *controllerAPIHandlers) ShutdownHandler(args *ShutdownArgs, reply *GenericReply) error { | 
					
						
							|  |  |  | 	if !isRPCTokenValid(args.Token) { | 
					
						
							|  |  |  | 		return errInvalidToken | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if args.Restart { | 
					
						
							| 
									
										
										
										
											2016-08-22 03:06:53 +08:00
										 |  |  | 		globalShutdownSignalCh <- shutdownRestart | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		globalShutdownSignalCh <- shutdownHalt | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2016-08-18 02:36:33 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-08-31 10:22:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (c *controllerAPIHandlers) TryInitHandler(args *GenericArgs, reply *GenericReply) error { | 
					
						
							|  |  |  | 	go func() { | 
					
						
							|  |  |  | 		globalWakeupCh <- struct{}{} | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | 	*reply = GenericReply{} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |