2016-07-13 02:21:18 -04: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-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-07-13 02:21:18 -04:00
|
|
|
|
|
|
|
import (
|
2016-10-14 07:48:08 -04:00
|
|
|
"crypto/x509"
|
2016-07-13 02:21:18 -04:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2016-10-14 07:48:08 -04:00
|
|
|
"time"
|
2016-07-13 02:21:18 -04:00
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
humanize "github.com/dustin/go-humanize"
|
2016-07-13 02:21:18 -04:00
|
|
|
"github.com/minio/mc/pkg/console"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Documentation links, these are part of message printing code.
|
|
|
|
const (
|
2016-07-26 18:54:11 -04:00
|
|
|
mcQuickStartGuide = "https://docs.minio.io/docs/minio-client-quickstart-guide"
|
2016-07-13 02:21:18 -04: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.
|
|
|
|
func printStartupMessage(endPoints []string) {
|
2016-11-11 19:36:07 -05:00
|
|
|
// If quiet flag is set do not print startup message.
|
|
|
|
if globalQuiet {
|
|
|
|
return
|
|
|
|
}
|
2016-07-13 02:21:18 -04:00
|
|
|
printServerCommonMsg(endPoints)
|
|
|
|
printCLIAccessMsg(endPoints[0])
|
|
|
|
printObjectAPIMsg()
|
2016-10-14 07:48:08 -04:00
|
|
|
|
2016-10-10 02:03:10 -04:00
|
|
|
objAPI := newObjectLayerFn()
|
|
|
|
if objAPI != nil {
|
|
|
|
printStorageInfo(objAPI.StorageInfo())
|
|
|
|
}
|
2016-10-14 07:48:08 -04:00
|
|
|
|
2016-10-14 14:15:59 -04:00
|
|
|
if isSSL() {
|
|
|
|
certs, err := readCertificateChain()
|
|
|
|
fatalIf(err, "Unable to read certificate chain.")
|
2016-10-14 07:48:08 -04:00
|
|
|
printCertificateMsg(certs)
|
|
|
|
}
|
2016-07-13 02:21:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prints common server startup message. Prints credential, region and browser access.
|
|
|
|
func printServerCommonMsg(endPoints []string) {
|
|
|
|
// Get saved credentials.
|
|
|
|
cred := serverConfig.GetCredential()
|
|
|
|
|
|
|
|
// Get saved region.
|
|
|
|
region := serverConfig.GetRegion()
|
|
|
|
|
|
|
|
endPointStr := strings.Join(endPoints, " ")
|
|
|
|
// Colorize the message and print.
|
2016-07-13 17:27:36 -04:00
|
|
|
console.Println(colorBlue("\nEndpoint: ") + colorBold(fmt.Sprintf(getFormatStr(len(endPointStr), 1), endPointStr)))
|
|
|
|
console.Println(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKeyID)))
|
2016-11-11 19:36:07 -05:00
|
|
|
console.Println(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretAccessKey)))
|
2016-07-13 17:27:36 -04:00
|
|
|
console.Println(colorBlue("Region: ") + colorBold(fmt.Sprintf(getFormatStr(len(region), 3), region)))
|
2016-09-14 04:11:03 -04:00
|
|
|
printEventNotifiers()
|
2016-09-13 14:00:40 -04:00
|
|
|
|
|
|
|
console.Println(colorBlue("\nBrowser Access:"))
|
|
|
|
console.Println(fmt.Sprintf(getFormatStr(len(endPointStr), 3), endPointStr))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints bucket notification configurations.
|
|
|
|
func printEventNotifiers() {
|
|
|
|
if globalEventNotifier == nil {
|
|
|
|
// In case initEventNotifier() was not done or failed.
|
|
|
|
return
|
|
|
|
}
|
2016-09-14 04:11:03 -04:00
|
|
|
arnMsg := colorBlue("SQS ARNs: ")
|
2016-10-12 04:03:50 -04:00
|
|
|
if len(globalEventNotifier.external.targets) == 0 {
|
2016-09-14 04:11:03 -04:00
|
|
|
arnMsg += colorBold(fmt.Sprintf(getFormatStr(len("<none>"), 1), "<none>"))
|
2016-09-13 14:00:40 -04:00
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
for queueArn := range globalEventNotifier.external.targets {
|
2016-09-14 04:11:03 -04:00
|
|
|
arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(queueArn), 1), queueArn))
|
2016-09-10 05:23:28 -04:00
|
|
|
}
|
|
|
|
console.Println(arnMsg)
|
2016-07-13 02:21:18 -04: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 17:27:36 -04:00
|
|
|
console.Println(colorBlue("\nCommand-line Access: ") + mcQuickStartGuide)
|
2016-07-13 02:21:18 -04:00
|
|
|
if runtime.GOOS == "windows" {
|
2016-11-11 19:36:07 -05:00
|
|
|
mcMessage := fmt.Sprintf("$ mc.exe config host add myminio %s %s %s", endPoint, cred.AccessKeyID, cred.SecretAccessKey)
|
2016-07-13 17:27:36 -04:00
|
|
|
console.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage))
|
2016-07-13 02:21:18 -04:00
|
|
|
} else {
|
2016-11-11 19:36:07 -05:00
|
|
|
mcMessage := fmt.Sprintf("$ mc config host add myminio %s %s %s", endPoint, cred.AccessKeyID, cred.SecretAccessKey)
|
2016-07-13 17:27:36 -04:00
|
|
|
console.Println(fmt.Sprintf(getFormatStr(len(mcMessage), 3), mcMessage))
|
2016-07-13 02:21:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prints startup message for Object API acces, prints link to our SDK documentation.
|
|
|
|
func printObjectAPIMsg() {
|
2016-07-13 03:56:00 -04:00
|
|
|
console.Println(colorBlue("\nObject API (Amazon S3 compatible):"))
|
2016-07-13 17:27:36 -04: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 02:21:18 -04:00
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
|
|
|
|
// Get formatted disk/storage info message.
|
2016-10-10 02:03:10 -04:00
|
|
|
func getStorageInfoMsg(storageInfo StorageInfo) string {
|
2016-10-16 17:24:15 -04:00
|
|
|
msg := fmt.Sprintf("%s %s Free, %s Total", colorBlue("Drive Capacity:"),
|
|
|
|
humanize.IBytes(uint64(storageInfo.Free)),
|
|
|
|
humanize.IBytes(uint64(storageInfo.Total)))
|
2016-10-05 15:48:07 -04:00
|
|
|
if storageInfo.Backend.Type == XL {
|
2016-10-22 13:36:50 -04: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 15:48:07 -04: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 02:03:10 -04:00
|
|
|
func printStorageInfo(storageInfo StorageInfo) {
|
2016-10-05 15:48:07 -04:00
|
|
|
console.Println()
|
2016-10-10 02:03:10 -04:00
|
|
|
console.Println(getStorageInfoMsg(storageInfo))
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
2016-10-14 07:48:08 -04: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]
|
2016-10-14 14:15:59 -04:00
|
|
|
if cert.NotAfter.Before(time.Now().UTC().Add(globalMinioCertExpireWarnDays)) {
|
2016-10-14 07:48:08 -04: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 14:15:59 -04:00
|
|
|
// Prints the certificate expiry message.
|
2016-10-14 07:48:08 -04:00
|
|
|
func printCertificateMsg(certs []*x509.Certificate) {
|
|
|
|
console.Println(getCertificateChainMsg(certs))
|
|
|
|
}
|