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"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
|
2016-10-05 21:48:07 +02:00
|
|
|
humanize "github.com/dustin/go-humanize"
|
2016-07-13 08:21:18 +02:00
|
|
|
"github.com/minio/mc/pkg/console"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Documentation links, these are part of message printing code.
|
|
|
|
const (
|
2016-07-27 00:54:11 +02:00
|
|
|
mcQuickStartGuide = "https://docs.minio.io/docs/minio-client-quickstart-guide"
|
2016-07-13 08:21:18 +02:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
// Prints credential, region and browser access.
|
|
|
|
printServerCommonMsg(apiEndPoints)
|
|
|
|
|
|
|
|
// Prints `mc` cli configuration message chooses
|
|
|
|
// first endpoint as default.
|
|
|
|
printCLIAccessMsg(apiEndPoints[0])
|
|
|
|
|
|
|
|
// 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
|
|
|
// Object layer is initialized then print StorageInfo.
|
2016-10-10 08:03:10 +02:00
|
|
|
objAPI := newObjectLayerFn()
|
|
|
|
if objAPI != nil {
|
|
|
|
printStorageInfo(objAPI.StorageInfo())
|
|
|
|
}
|
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 {
|
2016-10-14 20:15:59 +02:00
|
|
|
certs, err := readCertificateChain()
|
|
|
|
fatalIf(err, "Unable to read certificate chain.")
|
2016-10-14 13:48:08 +02:00
|
|
|
printCertificateMsg(certs)
|
|
|
|
}
|
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.
|
|
|
|
cred := serverConfig.GetCredential()
|
|
|
|
|
|
|
|
// Get saved region.
|
|
|
|
region := serverConfig.GetRegion()
|
|
|
|
|
2017-01-11 01:43:48 +01:00
|
|
|
apiEndpointStr := strings.Join(apiEndpoints, " ")
|
2016-07-13 08:21:18 +02:00
|
|
|
// Colorize the message and print.
|
2017-01-11 01:43:48 +01:00
|
|
|
console.Println(colorBlue("\nEndpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(apiEndpointStr), 1), apiEndpointStr)))
|
2016-12-26 19:21:23 +01:00
|
|
|
console.Println(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKey)))
|
|
|
|
console.Println(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretKey)))
|
2016-07-13 23:27:36 +02:00
|
|
|
console.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
|
|
|
|
|
|
|
console.Println(colorBlue("\nBrowser Access:"))
|
2017-01-11 01:43:48 +01:00
|
|
|
console.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
|
|
|
|
}
|
2016-09-14 10:11:03 +02:00
|
|
|
arnMsg := colorBlue("SQS ARNs: ")
|
2017-02-15 19:45:45 +01:00
|
|
|
// Get all configured external notification targets
|
|
|
|
externalTargets := globalEventNotifier.GetAllExternalTargets()
|
|
|
|
if len(externalTargets) == 0 {
|
2016-09-14 10:11:03 +02:00
|
|
|
arnMsg += colorBold(fmt.Sprintf(getFormatStr(len("<none>"), 1), "<none>"))
|
2016-09-13 20:00:40 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
console.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.
|
|
|
|
func printCLIAccessMsg(endPoint string) {
|
|
|
|
// Get saved credentials.
|
|
|
|
cred := serverConfig.GetCredential()
|
|
|
|
|
|
|
|
// Configure 'mc', following block prints platform specific information for minio client.
|
2016-07-13 23:27:36 +02:00
|
|
|
console.Println(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide)
|
2017-01-18 21:24:34 +01:00
|
|
|
if runtime.GOOS == globalWindowsOSName {
|
2016-12-26 19:21:23 +01:00
|
|
|
mcMessage := fmt.Sprintf("$ mc.exe config host add myminio %s %s %s", endPoint, cred.AccessKey, cred.SecretKey)
|
2016-07-13 23:27:36 +02:00
|
|
|
console.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage))
|
2016-07-13 08:21:18 +02:00
|
|
|
} else {
|
2016-12-26 19:21:23 +01:00
|
|
|
mcMessage := fmt.Sprintf("$ mc config host add myminio %s %s %s", endPoint, cred.AccessKey, cred.SecretKey)
|
2016-07-13 23:27:36 +02:00
|
|
|
console.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() {
|
2016-07-13 09:56:00 +02:00
|
|
|
console.Println(colorBlue("\nObject API (Amazon S3 compatible):"))
|
2016-07-13 23:27:36 +02:00
|
|
|
console.Println(colorBlue(" Go: ") + fmt.Sprintf(getFormatStr(len(goQuickStartGuide), 8), goQuickStartGuide))
|
|
|
|
console.Println(colorBlue(" Java: ") + fmt.Sprintf(getFormatStr(len(javaQuickStartGuide), 6), javaQuickStartGuide))
|
|
|
|
console.Println(colorBlue(" Python: ") + fmt.Sprintf(getFormatStr(len(pyQuickStartGuide), 4), pyQuickStartGuide))
|
|
|
|
console.Println(colorBlue(" JavaScript: ") + jsQuickStartGuide)
|
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)
|
|
|
|
if maxDiskFailures := storageInfo.Backend.ReadQuorum - storageInfo.Backend.OfflineDisks; maxDiskFailures >= 0 {
|
|
|
|
diskInfo += fmt.Sprintf("We can withstand [%d] more drive failure(s).", maxDiskFailures)
|
|
|
|
}
|
2016-10-05 21:48:07 +02:00
|
|
|
msg += colorBlue("\nStatus:") + fmt.Sprintf(getFormatStr(len(diskInfo), 8), diskInfo)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints startup message of storage capacity and erasure information.
|
2016-10-10 08:03:10 +02:00
|
|
|
func printStorageInfo(storageInfo StorageInfo) {
|
2016-10-05 21:48:07 +02:00
|
|
|
console.Println()
|
2016-10-10 08:03:10 +02:00
|
|
|
console.Println(getStorageInfoMsg(storageInfo))
|
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) {
|
|
|
|
console.Println(getCertificateChainMsg(certs))
|
2017-03-16 20:21:58 +01:00
|
|
|
|
2016-10-14 13:48:08 +02:00
|
|
|
}
|