| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016, 2017, 2018 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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-07-13 14:21:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | 	"crypto/x509" | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2018-12-19 00:26:30 +08:00
										 |  |  | 	"net" | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 	"runtime" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | 	humanize "github.com/dustin/go-humanize" | 
					
						
							| 
									
										
										
										
											2020-05-01 07:15:29 +08:00
										 |  |  | 	"github.com/minio/minio/cmd/config" | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 	"github.com/minio/minio/cmd/logger" | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	color "github.com/minio/minio/pkg/color" | 
					
						
							| 
									
										
										
										
											2018-12-14 15:37:46 +08:00
										 |  |  | 	xnet "github.com/minio/minio/pkg/net" | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Documentation links, these are part of message printing code.
 | 
					
						
							|  |  |  | const ( | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	mcQuickStartGuide      = "https://docs.min.io/docs/minio-client-quickstart-guide" | 
					
						
							|  |  |  | 	mcAdminQuickStartGuide = "https://docs.min.io/docs/minio-admin-complete-guide.html" | 
					
						
							|  |  |  | 	goQuickStartGuide      = "https://docs.min.io/docs/golang-client-quickstart-guide" | 
					
						
							|  |  |  | 	jsQuickStartGuide      = "https://docs.min.io/docs/javascript-client-quickstart-guide" | 
					
						
							|  |  |  | 	javaQuickStartGuide    = "https://docs.min.io/docs/java-client-quickstart-guide" | 
					
						
							|  |  |  | 	pyQuickStartGuide      = "https://docs.min.io/docs/python-client-quickstart-guide" | 
					
						
							|  |  |  | 	dotnetQuickStartGuide  = "https://docs.min.io/docs/dotnet-client-quickstart-guide" | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // generates format string depending on the string length and padding.
 | 
					
						
							|  |  |  | func getFormatStr(strLen int, padding int) string { | 
					
						
							|  |  |  | 	formatStr := fmt.Sprintf("%ds", strLen+padding) | 
					
						
							|  |  |  | 	return "%" + formatStr | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-29 04:03:04 +08:00
										 |  |  | func mustGetStorageInfo(objAPI ObjectLayer) StorageInfo { | 
					
						
							|  |  |  | 	storageInfo, _ := objAPI.StorageInfo(GlobalContext, false) | 
					
						
							|  |  |  | 	return storageInfo | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | func printStartupSafeModeMessage(apiEndpoints []string, err error) { | 
					
						
							|  |  |  | 	logStartupMessage(color.RedBold("Server startup failed with '%v'", err)) | 
					
						
							|  |  |  | 	logStartupMessage(color.RedBold("Server switching to safe mode")) | 
					
						
							| 
									
										
										
										
											2019-12-05 07:32:37 +08:00
										 |  |  | 	logStartupMessage(color.RedBold("Please use 'mc admin config' commands fix this issue")) | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Object layer is initialized then print StorageInfo in safe mode.
 | 
					
						
							|  |  |  | 	objAPI := newObjectLayerWithoutSafeModeFn() | 
					
						
							|  |  |  | 	if objAPI != nil { | 
					
						
							| 
									
										
										
										
											2020-05-29 04:03:04 +08:00
										 |  |  | 		if msg := getStorageInfoMsgSafeMode(mustGetStorageInfo(objAPI)); msg != "" { | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 			logStartupMessage(msg) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get saved credentials.
 | 
					
						
							|  |  |  | 	cred := globalActiveCred | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get saved region.
 | 
					
						
							|  |  |  | 	region := globalServerRegion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	strippedAPIEndpoints := stripStandardPorts(apiEndpoints) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	apiEndpointStr := strings.Join(strippedAPIEndpoints, "  ") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Colorize the message and print.
 | 
					
						
							|  |  |  | 	logStartupMessage(color.Red("Endpoint: ") + color.Bold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr))) | 
					
						
							|  |  |  | 	if color.IsTerminal() && !globalCLIContext.Anonymous { | 
					
						
							|  |  |  | 		logStartupMessage(color.Red("AccessKey: ") + color.Bold(fmt.Sprintf("%s ", cred.AccessKey))) | 
					
						
							|  |  |  | 		logStartupMessage(color.Red("SecretKey: ") + color.Bold(fmt.Sprintf("%s ", cred.SecretKey))) | 
					
						
							|  |  |  | 		if region != "" { | 
					
						
							|  |  |  | 			logStartupMessage(color.Red("Region: ") + color.Bold(fmt.Sprintf(getFormatStr(len(region), 3), region))) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Prints `mc` cli configuration message chooses
 | 
					
						
							|  |  |  | 	// first endpoint as default.
 | 
					
						
							|  |  |  | 	alias := "myminio" | 
					
						
							|  |  |  | 	endPoint := strippedAPIEndpoints[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Configure 'mc', following block prints platform specific information for minio client admin commands.
 | 
					
						
							| 
									
										
										
										
											2020-01-07 00:42:47 +08:00
										 |  |  | 	if color.IsTerminal() && !globalCLIContext.Anonymous { | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 		logStartupMessage(color.RedBold("\nCommand-line Access: ") + mcAdminQuickStartGuide) | 
					
						
							|  |  |  | 		if runtime.GOOS == globalWindowsOSName { | 
					
						
							|  |  |  | 			mcMessage := fmt.Sprintf("> mc.exe config host add %s %s %s %s --api s3v4", alias, | 
					
						
							|  |  |  | 				endPoint, cred.AccessKey, cred.SecretKey) | 
					
						
							|  |  |  | 			logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) | 
					
						
							| 
									
										
										
										
											2020-03-19 07:19:29 +08:00
										 |  |  | 			mcMessage = "> mc.exe admin config --help" | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 			logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			mcMessage := fmt.Sprintf("$ mc config host add %s %s %s %s --api s3v4", alias, | 
					
						
							|  |  |  | 				endPoint, cred.AccessKey, cred.SecretKey) | 
					
						
							|  |  |  | 			logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) | 
					
						
							| 
									
										
										
										
											2020-03-19 07:19:29 +08:00
										 |  |  | 			mcMessage = "$ mc admin config --help" | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 			logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | // Prints the formatted startup message.
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | func printStartupMessage(apiEndpoints []string) { | 
					
						
							| 
									
										
										
										
											2017-04-13 00:22:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	strippedAPIEndpoints := stripStandardPorts(apiEndpoints) | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 	// If cache layer is enabled, print cache capacity.
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	cachedObjAPI := newCachedObjectLayerFn() | 
					
						
							|  |  |  | 	if cachedObjAPI != nil { | 
					
						
							| 
									
										
										
										
											2020-04-10 00:30:02 +08:00
										 |  |  | 		printCacheStorageInfo(cachedObjAPI.StorageInfo(GlobalContext)) | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-22 19:28:13 +08:00
										 |  |  | 	// Object layer is initialized then print StorageInfo.
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	objAPI := newObjectLayerFn() | 
					
						
							| 
									
										
										
										
											2017-12-22 19:28:13 +08:00
										 |  |  | 	if objAPI != nil { | 
					
						
							| 
									
										
										
										
											2020-05-29 04:03:04 +08:00
										 |  |  | 		printStorageInfo(mustGetStorageInfo(objAPI)) | 
					
						
							| 
									
										
										
										
											2017-12-22 19:28:13 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	// Prints credential, region and browser access.
 | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 	printServerCommonMsg(strippedAPIEndpoints) | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Prints `mc` cli configuration message chooses
 | 
					
						
							|  |  |  | 	// first endpoint as default.
 | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | 	printCLIAccessMsg(strippedAPIEndpoints[0], "myminio") | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Prints documentation message.
 | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 	printObjectAPIMsg() | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	// SSL is configured reads certification chain, prints
 | 
					
						
							|  |  |  | 	// authority and expiry.
 | 
					
						
							| 
									
										
										
										
											2020-05-01 07:15:29 +08:00
										 |  |  | 	if color.IsTerminal() && !globalCLIContext.Anonymous { | 
					
						
							|  |  |  | 		if globalIsSSL { | 
					
						
							|  |  |  | 			printCertificateMsg(globalPublicCerts) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 00:26:30 +08:00
										 |  |  | // Returns true if input is not IPv4, false if it is.
 | 
					
						
							|  |  |  | func isNotIPv4(host string) bool { | 
					
						
							|  |  |  | 	h, _, err := net.SplitHostPort(host) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		h = host | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ip := net.ParseIP(h) | 
					
						
							|  |  |  | 	ok := ip.To4() != nil // This is always true of IP is IPv4
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Returns true if input is not IPv4.
 | 
					
						
							|  |  |  | 	return !ok | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | // strip api endpoints list with standard ports such as
 | 
					
						
							|  |  |  | // port "80" and "443" before displaying on the startup
 | 
					
						
							|  |  |  | // banner.  Returns a new list of API endpoints.
 | 
					
						
							|  |  |  | func stripStandardPorts(apiEndpoints []string) (newAPIEndpoints []string) { | 
					
						
							|  |  |  | 	newAPIEndpoints = make([]string, len(apiEndpoints)) | 
					
						
							|  |  |  | 	// Check all API endpoints for standard ports and strip them.
 | 
					
						
							|  |  |  | 	for i, apiEndpoint := range apiEndpoints { | 
					
						
							| 
									
										
										
										
											2019-10-31 14:39:09 +08:00
										 |  |  | 		u, err := xnet.ParseHTTPURL(apiEndpoint) | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-12-19 00:26:30 +08:00
										 |  |  | 		if globalMinioHost == "" && isNotIPv4(u.Host) { | 
					
						
							|  |  |  | 			// Skip all non-IPv4 endpoints when we bind to all interfaces.
 | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		newAPIEndpoints[i] = u.String() | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return newAPIEndpoints | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | // Prints common server startup message. Prints credential, region and browser access.
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | func printServerCommonMsg(apiEndpoints []string) { | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 	// Get saved credentials.
 | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08:00
										 |  |  | 	cred := globalActiveCred | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Get saved region.
 | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08:00
										 |  |  | 	region := globalServerRegion | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 08:43:48 +08:00
										 |  |  | 	apiEndpointStr := strings.Join(apiEndpoints, "  ") | 
					
						
							| 
									
										
										
										
											2017-06-01 00:21:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 	// Colorize the message and print.
 | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	logStartupMessage(color.Blue("Endpoint: ") + color.Bold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr))) | 
					
						
							|  |  |  | 	if color.IsTerminal() && !globalCLIContext.Anonymous { | 
					
						
							|  |  |  | 		logStartupMessage(color.Blue("AccessKey: ") + color.Bold(fmt.Sprintf("%s ", cred.AccessKey))) | 
					
						
							|  |  |  | 		logStartupMessage(color.Blue("SecretKey: ") + color.Bold(fmt.Sprintf("%s ", cred.SecretKey))) | 
					
						
							| 
									
										
										
										
											2018-10-17 04:19:12 +08:00
										 |  |  | 		if region != "" { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 			logStartupMessage(color.Blue("Region: ") + color.Bold(fmt.Sprintf(getFormatStr(len(region), 3), region))) | 
					
						
							| 
									
										
										
										
											2018-10-17 04:19:12 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 16:11:03 +08:00
										 |  |  | 	printEventNotifiers() | 
					
						
							| 
									
										
										
										
											2016-09-14 02:00:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08:00
										 |  |  | 	if globalBrowserEnabled { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 		logStartupMessage(color.Blue("\nBrowser Access:")) | 
					
						
							| 
									
										
										
										
											2019-09-22 16:24:32 +08:00
										 |  |  | 		logStartupMessage(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr)) | 
					
						
							| 
									
										
										
										
											2018-01-04 13:30:52 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 02:00:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Prints bucket notification configurations.
 | 
					
						
							|  |  |  | func printEventNotifiers() { | 
					
						
							| 
									
										
										
										
											2019-11-14 09:38:05 +08:00
										 |  |  | 	if globalNotificationSys == nil { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-22 00:38:32 +08:00
										 |  |  | 	arns := globalNotificationSys.GetARNList(true) | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 	if len(arns) == 0 { | 
					
						
							| 
									
										
										
										
											2017-05-16 09:17:02 +08:00
										 |  |  | 		return | 
					
						
							| 
									
										
										
										
											2016-09-14 02:00:40 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	arnMsg := color.Blue("SQS ARNs: ") | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 	for _, arn := range arns { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 		arnMsg += color.Bold(fmt.Sprintf(getFormatStr(len(arn), 1), arn)) | 
					
						
							| 
									
										
										
										
											2016-09-10 17:23:28 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-22 16:24:32 +08:00
										 |  |  | 	logStartupMessage(arnMsg) | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Prints startup message for command line access. Prints link to our documentation
 | 
					
						
							|  |  |  | // and custom platform specific message.
 | 
					
						
							| 
									
										
										
										
											2017-06-10 10:50:51 +08:00
										 |  |  | func printCLIAccessMsg(endPoint string, alias string) { | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 	// Get saved credentials.
 | 
					
						
							| 
									
										
										
										
											2019-10-23 13:59:13 +08:00
										 |  |  | 	cred := globalActiveCred | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Configure 'mc', following block prints platform specific information for minio client.
 | 
					
						
							| 
									
										
										
										
											2020-01-07 00:42:47 +08:00
										 |  |  | 	if color.IsTerminal() && !globalCLIContext.Anonymous { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 		logStartupMessage(color.Blue("\nCommand-line Access: ") + mcQuickStartGuide) | 
					
						
							| 
									
										
										
										
											2018-10-17 04:19:12 +08:00
										 |  |  | 		if runtime.GOOS == globalWindowsOSName { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 			mcMessage := fmt.Sprintf("$ mc.exe config host add %s %s %s %s", alias, | 
					
						
							|  |  |  | 				endPoint, cred.AccessKey, cred.SecretKey) | 
					
						
							| 
									
										
										
										
											2019-09-22 16:24:32 +08:00
										 |  |  | 			logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) | 
					
						
							| 
									
										
										
										
											2018-10-17 04:19:12 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 			mcMessage := fmt.Sprintf("$ mc config host add %s %s %s %s", alias, | 
					
						
							|  |  |  | 				endPoint, cred.AccessKey, cred.SecretKey) | 
					
						
							| 
									
										
										
										
											2019-09-22 16:24:32 +08:00
										 |  |  | 			logStartupMessage(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage)) | 
					
						
							| 
									
										
										
										
											2018-10-17 04:19:12 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Prints startup message for Object API acces, prints link to our SDK documentation.
 | 
					
						
							|  |  |  | func printObjectAPIMsg() { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	logStartupMessage(color.Blue("\nObject API (Amazon S3 compatible):")) | 
					
						
							|  |  |  | 	logStartupMessage(color.Blue("   Go: ") + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide)) | 
					
						
							|  |  |  | 	logStartupMessage(color.Blue("   Java: ") + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide)) | 
					
						
							|  |  |  | 	logStartupMessage(color.Blue("   Python: ") + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide)) | 
					
						
							|  |  |  | 	logStartupMessage(color.Blue("   JavaScript: ") + jsQuickStartGuide) | 
					
						
							|  |  |  | 	logStartupMessage(color.Blue("   .NET: ") + fmt.Sprintf(getFormatStr(len(dotnetQuickStartGuide), 6), dotnetQuickStartGuide)) | 
					
						
							| 
									
										
										
										
											2016-07-13 14:21:18 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | // Get formatted disk/storage info message.
 | 
					
						
							|  |  |  | func getStorageInfoMsgSafeMode(storageInfo StorageInfo) string { | 
					
						
							|  |  |  | 	var msg string | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 	var mcMessage string | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	if storageInfo.Backend.Type == BackendErasure { | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 		if storageInfo.Backend.OfflineDisks.Sum() > 0 { | 
					
						
							| 
									
										
										
										
											2020-04-13 09:08:27 +08:00
										 |  |  | 			mcMessage = "Use `mc admin info` to look for latest server/disk info\n" | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-22 01:02:20 +08:00
										 |  |  | 		diskInfo := fmt.Sprintf(" %d Online, %d Offline. ", storageInfo.Backend.OnlineDisks.Sum(), storageInfo.Backend.OfflineDisks.Sum()) | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 		msg += color.Red("Status:") + fmt.Sprintf(getFormatStr(len(diskInfo), 8), diskInfo) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-03-22 01:02:20 +08:00
										 |  |  | 	if len(mcMessage) > 0 { | 
					
						
							|  |  |  | 		msg = fmt.Sprintf("%s %s", mcMessage, msg) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	return msg | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | // Get formatted disk/storage info message.
 | 
					
						
							| 
									
										
										
										
											2016-10-10 14:03:10 +08:00
										 |  |  | func getStorageInfoMsg(storageInfo StorageInfo) string { | 
					
						
							| 
									
										
										
										
											2018-05-24 08:30:25 +08:00
										 |  |  | 	var msg string | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 	var mcMessage string | 
					
						
							| 
									
										
										
										
											2018-08-24 14:35:37 +08:00
										 |  |  | 	if storageInfo.Backend.Type == BackendErasure { | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 		if storageInfo.Backend.OfflineDisks.Sum() > 0 { | 
					
						
							| 
									
										
										
										
											2020-04-13 09:08:27 +08:00
										 |  |  | 			mcMessage = "Use `mc admin info` to look for latest server/disk info\n" | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-22 01:02:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		diskInfo := fmt.Sprintf(" %d Online, %d Offline. ", storageInfo.Backend.OnlineDisks.Sum(), storageInfo.Backend.OfflineDisks.Sum()) | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 		msg += color.Blue("Status:") + fmt.Sprintf(getFormatStr(len(diskInfo), 8), diskInfo) | 
					
						
							| 
									
										
										
										
											2020-03-22 01:02:20 +08:00
										 |  |  | 		if len(mcMessage) > 0 { | 
					
						
							|  |  |  | 			msg = fmt.Sprintf("%s %s", mcMessage, msg) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return msg | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Prints startup message of storage capacity and erasure information.
 | 
					
						
							| 
									
										
										
										
											2016-10-10 14:03:10 +08:00
										 |  |  | func printStorageInfo(storageInfo StorageInfo) { | 
					
						
							| 
									
										
										
										
											2018-05-24 08:30:25 +08:00
										 |  |  | 	if msg := getStorageInfoMsg(storageInfo); msg != "" { | 
					
						
							| 
									
										
										
										
											2020-03-18 06:25:00 +08:00
										 |  |  | 		if globalCLIContext.Quiet { | 
					
						
							|  |  |  | 			logger.Info(msg) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-22 16:24:32 +08:00
										 |  |  | 		logStartupMessage(msg) | 
					
						
							| 
									
										
										
										
											2018-05-24 08:30:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-31 02:30:14 +08:00
										 |  |  | func printCacheStorageInfo(storageInfo CacheStorageInfo) { | 
					
						
							| 
									
										
										
										
											2019-10-05 01:35:33 +08:00
										 |  |  | 	msg := fmt.Sprintf("%s %s Free, %s Total", color.Blue("Cache Capacity:"), | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 		humanize.IBytes(uint64(storageInfo.Free)), | 
					
						
							|  |  |  | 		humanize.IBytes(uint64(storageInfo.Total))) | 
					
						
							| 
									
										
										
										
											2019-09-22 16:24:32 +08:00
										 |  |  | 	logStartupMessage(msg) | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-15 02:15:59 +08:00
										 |  |  | // Prints the certificate expiry message.
 | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | func printCertificateMsg(certs []*x509.Certificate) { | 
					
						
							| 
									
										
										
										
											2020-05-01 07:15:29 +08:00
										 |  |  | 	for _, cert := range certs { | 
					
						
							|  |  |  | 		logStartupMessage(config.CertificateText(cert)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-14 19:48:08 +08:00
										 |  |  | } |