2016-07-13 08:21:18 +02:00
|
|
|
/*
|
2017-03-16 20:21:58 +01:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
2016-07-13 08:21:18 +02: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 01:23:42 +02:00
|
|
|
package cmd
|
2016-07-13 08:21:18 +02:00
|
|
|
|
|
|
|
import (
|
2016-10-14 13:48:08 +02:00
|
|
|
"crypto/x509"
|
2016-07-13 08:21:18 +02:00
|
|
|
"fmt"
|
2017-05-31 18:21:28 +02:00
|
|
|
"net/url"
|
2016-07-13 08:21:18 +02:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
|
2016-10-05 21:48:07 +02:00
|
|
|
humanize "github.com/dustin/go-humanize"
|
2016-07-13 08:21:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Documentation links, these are part of message printing code.
|
|
|
|
const (
|
2017-05-23 22:57:27 +02:00
|
|
|
mcQuickStartGuide = "https://docs.minio.io/docs/minio-client-quickstart-guide"
|
|
|
|
goQuickStartGuide = "https://docs.minio.io/docs/golang-client-quickstart-guide"
|
|
|
|
jsQuickStartGuide = "https://docs.minio.io/docs/javascript-client-quickstart-guide"
|
|
|
|
javaQuickStartGuide = "https://docs.minio.io/docs/java-client-quickstart-guide"
|
|
|
|
pyQuickStartGuide = "https://docs.minio.io/docs/python-client-quickstart-guide"
|
|
|
|
dotnetQuickStartGuide = "https://docs.minio.io/docs/dotnet-client-quickstart-guide"
|
2016-07-13 08:21:18 +02: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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints the formatted startup message.
|
2017-01-11 01:43:48 +01:00
|
|
|
func printStartupMessage(apiEndPoints []string) {
|
2017-04-12 18:22:35 +02:00
|
|
|
|
2017-05-31 18:21:28 +02:00
|
|
|
strippedAPIEndpoints := stripStandardPorts(apiEndPoints)
|
|
|
|
|
2017-12-22 12:28:13 +01:00
|
|
|
// Object layer is initialized then print StorageInfo.
|
|
|
|
objAPI := newObjectLayerFn()
|
|
|
|
if objAPI != nil {
|
|
|
|
printStorageInfo(objAPI.StorageInfo())
|
|
|
|
// Storage class info only printed for Erasure backend
|
|
|
|
if objAPI.StorageInfo().Backend.Type == Erasure {
|
|
|
|
printStorageClassInfoMsg(objAPI.StorageInfo())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 01:43:48 +01:00
|
|
|
// Prints credential, region and browser access.
|
2017-05-31 18:21:28 +02:00
|
|
|
printServerCommonMsg(strippedAPIEndpoints)
|
2017-01-11 01:43:48 +01:00
|
|
|
|
|
|
|
// Prints `mc` cli configuration message chooses
|
|
|
|
// first endpoint as default.
|
2017-06-10 04:50:51 +02:00
|
|
|
printCLIAccessMsg(strippedAPIEndpoints[0], "myminio")
|
2017-01-11 01:43:48 +01:00
|
|
|
|
|
|
|
// Prints documentation message.
|
2016-07-13 08:21:18 +02:00
|
|
|
printObjectAPIMsg()
|
2016-10-14 13:48:08 +02:00
|
|
|
|
2017-01-11 01:43:48 +01:00
|
|
|
// SSL is configured reads certification chain, prints
|
|
|
|
// authority and expiry.
|
2017-01-11 22:59:51 +01:00
|
|
|
if globalIsSSL {
|
2017-03-30 20:21:19 +02:00
|
|
|
printCertificateMsg(globalPublicCerts)
|
2016-10-14 13:48:08 +02:00
|
|
|
}
|
2016-07-13 08:21:18 +02:00
|
|
|
}
|
|
|
|
|
2017-05-31 18:21:28 +02: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 {
|
|
|
|
url, err := url.Parse(apiEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
newAPIEndpoints[i] = apiEndpoint
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
host, port := mustSplitHostPort(url.Host)
|
|
|
|
// For standard HTTP(s) ports such as "80" and "443"
|
|
|
|
// apiEndpoints should only be host without port.
|
|
|
|
switch {
|
|
|
|
case url.Scheme == "http" && port == "80":
|
|
|
|
fallthrough
|
|
|
|
case url.Scheme == "https" && port == "443":
|
|
|
|
url.Host = host
|
|
|
|
newAPIEndpoints[i] = url.String()
|
|
|
|
default:
|
|
|
|
newAPIEndpoints[i] = apiEndpoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newAPIEndpoints
|
|
|
|
}
|
|
|
|
|
2016-07-13 08:21:18 +02:00
|
|
|
// Prints common server startup message. Prints credential, region and browser access.
|
2017-01-11 01:43:48 +01:00
|
|
|
func printServerCommonMsg(apiEndpoints []string) {
|
2016-07-13 08:21:18 +02:00
|
|
|
// Get saved credentials.
|
2017-11-29 22:12:47 +01:00
|
|
|
cred := globalServerConfig.GetCredential()
|
2016-07-13 08:21:18 +02:00
|
|
|
|
|
|
|
// Get saved region.
|
2017-11-29 22:12:47 +01:00
|
|
|
region := globalServerConfig.GetRegion()
|
2016-07-13 08:21:18 +02:00
|
|
|
|
2017-01-11 01:43:48 +01:00
|
|
|
apiEndpointStr := strings.Join(apiEndpoints, " ")
|
2017-05-31 18:21:28 +02:00
|
|
|
|
2016-07-13 08:21:18 +02:00
|
|
|
// Colorize the message and print.
|
2017-06-28 04:46:58 +02:00
|
|
|
log.Println(colorBlue("Endpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr)))
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey)))
|
|
|
|
log.Println(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey)))
|
2017-05-16 03:17:02 +02:00
|
|
|
if region != "" {
|
|
|
|
log.Println(colorBlue("Region: ") + colorBold(fmt.Sprintf(getFormatStr(len(region), 3), region)))
|
|
|
|
}
|
2016-09-14 10:11:03 +02:00
|
|
|
printEventNotifiers()
|
2016-09-13 20:00:40 +02:00
|
|
|
|
2018-01-04 06:30:52 +01:00
|
|
|
if globalIsBrowserEnabled {
|
|
|
|
log.Println(colorBlue("\nBrowser Access:"))
|
|
|
|
log.Println(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 3), apiEndpointStr))
|
|
|
|
}
|
2016-09-13 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prints bucket notification configurations.
|
|
|
|
func printEventNotifiers() {
|
|
|
|
if globalEventNotifier == nil {
|
|
|
|
// In case initEventNotifier() was not done or failed.
|
|
|
|
return
|
|
|
|
}
|
2017-02-15 19:45:45 +01:00
|
|
|
// Get all configured external notification targets
|
|
|
|
externalTargets := globalEventNotifier.GetAllExternalTargets()
|
|
|
|
if len(externalTargets) == 0 {
|
2017-05-16 03:17:02 +02:00
|
|
|
return
|
2016-09-13 20:00:40 +02:00
|
|
|
}
|
2017-05-16 03:17:02 +02:00
|
|
|
arnMsg := colorBlue("SQS ARNs: ")
|
2017-02-15 19:45:45 +01:00
|
|
|
for queueArn := range externalTargets {
|
2016-09-14 10:11:03 +02:00
|
|
|
arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(queueArn), 1), queueArn))
|
2016-09-10 11:23:28 +02:00
|
|
|
}
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(arnMsg)
|
2016-07-13 08:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prints startup message for command line access. Prints link to our documentation
|
|
|
|
// and custom platform specific message.
|
2017-06-10 04:50:51 +02:00
|
|
|
func printCLIAccessMsg(endPoint string, alias string) {
|
2016-07-13 08:21:18 +02:00
|
|
|
// Get saved credentials.
|
2017-11-29 22:12:47 +01:00
|
|
|
cred := globalServerConfig.GetCredential()
|
2016-07-13 08:21:18 +02:00
|
|
|
|
|
|
|
// Configure 'mc', following block prints platform specific information for minio client.
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide)
|
2017-01-18 21:24:34 +01:00
|
|
|
if runtime.GOOS == globalWindowsOSName {
|
2017-06-10 04:50:51 +02:00
|
|
|
mcMessage := fmt.Sprintf("$ mc.exe config host add %s %s %s %s", alias, endPoint, cred.AccessKey, cred.SecretKey)
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage))
|
2016-07-13 08:21:18 +02:00
|
|
|
} else {
|
2017-06-10 04:50:51 +02:00
|
|
|
mcMessage := fmt.Sprintf("$ mc config host add %s %s %s %s", alias, endPoint, cred.AccessKey, cred.SecretKey)
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage))
|
2016-07-13 08:21:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints startup message for Object API acces, prints link to our SDK documentation.
|
|
|
|
func printObjectAPIMsg() {
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(colorBlue("\nObject API (Amazon S3 compatible):"))
|
|
|
|
log.Println(colorBlue(" Go: ") + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide))
|
|
|
|
log.Println(colorBlue(" Java: ") + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide))
|
|
|
|
log.Println(colorBlue(" Python: ") + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide))
|
|
|
|
log.Println(colorBlue(" JavaScript: ") + jsQuickStartGuide)
|
2017-05-23 22:57:27 +02:00
|
|
|
log.Println(colorBlue(" .NET: ") + fmt.Sprintf(getFormatStr(len(dotnetQuickStartGuide), 6), dotnetQuickStartGuide))
|
2016-07-13 08:21:18 +02:00
|
|
|
}
|
2016-10-05 21:48:07 +02:00
|
|
|
|
|
|
|
// Get formatted disk/storage info message.
|
2016-10-10 08:03:10 +02:00
|
|
|
func getStorageInfoMsg(storageInfo StorageInfo) string {
|
2016-10-16 23:24:15 +02:00
|
|
|
msg := fmt.Sprintf("%s %s Free, %s Total", colorBlue("Drive Capacity:"),
|
|
|
|
humanize.IBytes(uint64(storageInfo.Free)),
|
|
|
|
humanize.IBytes(uint64(storageInfo.Total)))
|
2017-02-10 08:26:44 +01:00
|
|
|
if storageInfo.Backend.Type == Erasure {
|
2016-10-22 19:36:50 +02:00
|
|
|
diskInfo := fmt.Sprintf(" %d Online, %d Offline. ", storageInfo.Backend.OnlineDisks, storageInfo.Backend.OfflineDisks)
|
2016-10-05 21:48:07 +02:00
|
|
|
msg += colorBlue("\nStatus:") + fmt.Sprintf(getFormatStr(len(diskInfo), 8), diskInfo)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
2017-12-22 12:28:13 +01:00
|
|
|
func printStorageClassInfoMsg(storageInfo StorageInfo) {
|
|
|
|
standardClassMsg := getStandardStorageClassInfoMsg(storageInfo)
|
|
|
|
rrsClassMsg := getRRSStorageClassInfoMsg(storageInfo)
|
|
|
|
storageClassMsg := fmt.Sprintf(getFormatStr(len(standardClassMsg), 3), standardClassMsg) + fmt.Sprintf(getFormatStr(len(rrsClassMsg), 3), rrsClassMsg)
|
|
|
|
// Print storage class section only if data is present
|
|
|
|
if storageClassMsg != "" {
|
|
|
|
log.Println(colorBlue("Storage Class:"))
|
|
|
|
log.Println(storageClassMsg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStandardStorageClassInfoMsg(storageInfo StorageInfo) string {
|
|
|
|
var msg string
|
|
|
|
if maxDiskFailures := storageInfo.Backend.standardSCParity - storageInfo.Backend.OfflineDisks; maxDiskFailures >= 0 {
|
|
|
|
msg += fmt.Sprintf("Objects with Standard class can withstand [%d] drive failure(s).\n", maxDiskFailures)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRRSStorageClassInfoMsg(storageInfo StorageInfo) string {
|
|
|
|
var msg string
|
|
|
|
if maxDiskFailures := storageInfo.Backend.rrSCParity - storageInfo.Backend.OfflineDisks; maxDiskFailures >= 0 {
|
|
|
|
msg += fmt.Sprintf("Objects with Reduced Redundancy class can withstand [%d] drive failure(s).\n", maxDiskFailures)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
2016-10-05 21:48:07 +02:00
|
|
|
// Prints startup message of storage capacity and erasure information.
|
2016-10-10 08:03:10 +02:00
|
|
|
func printStorageInfo(storageInfo StorageInfo) {
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(getStorageInfoMsg(storageInfo))
|
2017-12-22 12:28:13 +01:00
|
|
|
log.Println()
|
2016-10-05 21:48:07 +02:00
|
|
|
}
|
2016-10-14 13:48:08 +02:00
|
|
|
|
|
|
|
// Prints certificate expiry date warning
|
|
|
|
func getCertificateChainMsg(certs []*x509.Certificate) string {
|
|
|
|
msg := colorBlue("\nCertificate expiry info:\n")
|
|
|
|
totalCerts := len(certs)
|
|
|
|
var expiringCerts int
|
|
|
|
for i := totalCerts - 1; i >= 0; i-- {
|
|
|
|
cert := certs[i]
|
2017-03-18 19:28:41 +01:00
|
|
|
if cert.NotAfter.Before(UTCNow().Add(globalMinioCertExpireWarnDays)) {
|
2016-10-14 13:48:08 +02:00
|
|
|
expiringCerts++
|
|
|
|
msg += fmt.Sprintf(colorBold("#%d %s will expire on %s\n"), expiringCerts, cert.Subject.CommonName, cert.NotAfter)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if expiringCerts > 0 {
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-10-14 20:15:59 +02:00
|
|
|
// Prints the certificate expiry message.
|
2016-10-14 13:48:08 +02:00
|
|
|
func printCertificateMsg(certs []*x509.Certificate) {
|
2017-03-24 00:36:00 +01:00
|
|
|
log.Println(getCertificateChainMsg(certs))
|
2016-10-14 13:48:08 +02:00
|
|
|
}
|