github.com/minio/console@v1.4.1/api/logs.go (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2021 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  //
    17  
    18  package api
    19  
    20  import (
    21  	"context"
    22  	"errors"
    23  	"log"
    24  	"os"
    25  
    26  	"github.com/minio/cli"
    27  )
    28  
    29  var (
    30  	infoLog  = log.New(os.Stdout, "I: ", log.LstdFlags)
    31  	errorLog = log.New(os.Stdout, "E: ", log.LstdFlags)
    32  )
    33  
    34  func logInfo(msg string, data ...interface{}) {
    35  	infoLog.Printf(msg+"\n", data...)
    36  }
    37  
    38  func logError(msg string, data ...interface{}) {
    39  	errorLog.Printf(msg+"\n", data...)
    40  }
    41  
    42  func logIf(_ context.Context, _ error, _ ...interface{}) {
    43  }
    44  
    45  // globally changeable logger styles
    46  var (
    47  	LogInfo  = logInfo
    48  	LogError = logError
    49  	LogIf    = logIf
    50  )
    51  
    52  // Context captures all command line flags values
    53  type Context struct {
    54  	Host                string
    55  	HTTPPort, HTTPSPort int
    56  	TLSRedirect         string
    57  	// Legacy options, TODO: remove in future
    58  	TLSCertificate, TLSKey, TLSca string
    59  }
    60  
    61  // Load loads api Context from command line context.
    62  func (c *Context) Load(ctx *cli.Context) error {
    63  	*c = Context{
    64  		Host:        ctx.String("host"),
    65  		HTTPPort:    ctx.Int("port"),
    66  		HTTPSPort:   ctx.Int("tls-port"),
    67  		TLSRedirect: ctx.String("tls-redirect"),
    68  		// Legacy options to be removed.
    69  		TLSCertificate: ctx.String("tls-certificate"),
    70  		TLSKey:         ctx.String("tls-key"),
    71  		TLSca:          ctx.String("tls-ca"),
    72  	}
    73  	if c.HTTPPort > 65535 {
    74  		return errors.New("invalid argument --port out of range - ports can range from 1-65535")
    75  	}
    76  	if c.HTTPSPort > 65535 {
    77  		return errors.New("invalid argument --tls-port out of range - ports can range from 1-65535")
    78  	}
    79  	if c.TLSRedirect != "on" && c.TLSRedirect != "off" {
    80  		return errors.New("invalid argument --tls-redirect only accepts either 'on' or 'off'")
    81  	}
    82  	return nil
    83  }