@@ -23,6 +23,7 @@ import (
2323 "log"
2424 "os"
2525 "path/filepath"
26+ "strconv"
2627 "time"
2728
2829 "github.com/go-openapi/loads"
@@ -38,32 +39,37 @@ var serverCmd = cli.Command{
3839 Name : "server" ,
3940 Aliases : []string {"srv" },
4041 Usage : "starts Console server" ,
41- Action : startServer ,
42+ Action : StartServer ,
4243 Flags : []cli.Flag {
4344 cli.StringFlag {
4445 Name : "host" ,
4546 Value : restapi .GetHostname (),
46- Usage : "HTTP server hostname" ,
47+ Usage : "hostname" ,
4748 },
4849 cli.IntFlag {
4950 Name : "port" ,
5051 Value : restapi .GetPort (),
51- Usage : "HTTP Server port" ,
52+ Usage : "HTTP port" ,
5253 },
54+ // This is kept here for backward compatibility,
55+ // hostname's do not have HTTP or HTTPs
56+ // hostnames are opaque so using --host
57+ // works for both HTTP and HTTPS setup.
5358 cli.StringFlag {
54- Name : "tls-host" ,
55- Value : restapi .GetTLSHostname (),
56- Usage : "HTTPS server hostname" ,
59+ Name : "tls-host" ,
60+ Value : restapi .GetHostname (),
61+ Usage : "HTTPS hostname" ,
62+ Hidden : true ,
5763 },
5864 cli.IntFlag {
5965 Name : "tls-port" ,
6066 Value : restapi .GetTLSPort (),
61- Usage : "HTTPS server port" ,
67+ Usage : "HTTPS port" ,
6268 },
6369 cli.StringFlag {
6470 Name : "tls-redirect" ,
6571 Value : restapi .GetTLSRedirect (),
66- Usage : "HTTPS redirect by default " ,
72+ Usage : "toggle HTTP-> HTTPS redirect" ,
6773 },
6874 cli.StringFlag {
6975 Name : "certs-dir" ,
@@ -73,23 +79,23 @@ var serverCmd = cli.Command{
7379 cli.StringFlag {
7480 Name : "tls-certificate" ,
7581 Value : "" ,
76- Usage : "path tls certificate" ,
82+ Usage : "path to TLS public certificate" ,
7783 },
7884 cli.StringFlag {
7985 Name : "tls-key" ,
8086 Value : "" ,
81- Usage : "path tls key" ,
87+ Usage : "path to TLS private key" ,
8288 },
8389 cli.StringFlag {
8490 Name : "tls-ca" ,
8591 Value : "" ,
86- Usage : "path tls ca " ,
92+ Usage : "path to TLS Certificate Authority " ,
8793 },
8894 },
8995}
9096
91- // starts the controller
92- func startServer (ctx * cli.Context ) error {
97+ // StartServer starts the console service
98+ func StartServer (ctx * cli.Context ) error {
9399 swaggerSpec , err := loads .Embedded (restapi .SwaggerJSON , restapi .FlatSwaggerJSON )
94100 if err != nil {
95101 log .Fatalln (err )
@@ -126,7 +132,7 @@ func startServer(ctx *cli.Context) error {
126132 server .Port = ctx .Int ("port" )
127133
128134 restapi .Hostname = ctx .String ("host" )
129- restapi .Port = fmt . Sprintf ( "%v" , ctx .Int ("port" ))
135+ restapi .Port = strconv . Itoa ( ctx .Int ("port" ))
130136
131137 // Set all certs and CAs directories path
132138 certs .GlobalCertsDir , _ = certs .NewConfigDirFromCtx (ctx , "certs-dir" , certs .DefaultCertsDir .Get )
@@ -139,26 +145,28 @@ func startServer(ctx *cli.Context) error {
139145 // load the certificates and the CAs
140146 restapi .GlobalRootCAs , restapi .GlobalPublicCerts , restapi .GlobalTLSCertsManager = certs .GetAllCertificatesAndCAs ()
141147
142- // TLS flags from swagger server, used to support older versions of minio-operator
143- swaggerServerCertificate := ctx .String ("tls-certificate" )
144- swaggerServerCertificateKey := ctx .String ("tls-key" )
145- SwaggerServerCACertificate := ctx .String ("tls-ca" )
146- // load tls cert and key from swagger server tls-certificate and tls-key flags
147- if swaggerServerCertificate != "" && swaggerServerCertificateKey != "" {
148- if errAddCert := certs .AddCertificate (context .Background (), restapi .GlobalTLSCertsManager , swaggerServerCertificate , swaggerServerCertificateKey ); errAddCert != nil {
149- log .Println (errAddCert )
150- }
151- if x509Certs , errParseCert := certs .ParsePublicCertFile (swaggerServerCertificate ); errParseCert == nil {
152- if len (x509Certs ) > 0 {
153- restapi .GlobalPublicCerts = append (restapi .GlobalPublicCerts , x509Certs [0 ])
148+ {
149+ // TLS flags from swagger server, used to support VMware vsphere operator version.
150+ swaggerServerCertificate := ctx .String ("tls-certificate" )
151+ swaggerServerCertificateKey := ctx .String ("tls-key" )
152+ SwaggerServerCACertificate := ctx .String ("tls-ca" )
153+ // load tls cert and key from swagger server tls-certificate and tls-key flags
154+ if swaggerServerCertificate != "" && swaggerServerCertificateKey != "" {
155+ if errAddCert := certs .AddCertificate (context .Background (),
156+ restapi .GlobalTLSCertsManager , swaggerServerCertificate , swaggerServerCertificateKey ); errAddCert != nil {
157+ log .Println (errAddCert )
158+ }
159+ if x509Certs , errParseCert := certs .ParsePublicCertFile (swaggerServerCertificate ); errParseCert == nil {
160+ restapi .GlobalPublicCerts = append (restapi .GlobalPublicCerts , x509Certs ... )
154161 }
155162 }
156- }
157- // load ca cert from swagger server tls-ca flag
158- if SwaggerServerCACertificate != "" {
159- caCert , caCertErr := ioutil .ReadFile (SwaggerServerCACertificate )
160- if caCertErr == nil {
161- restapi .GlobalRootCAs .AppendCertsFromPEM (caCert )
163+
164+ // load ca cert from swagger server tls-ca flag
165+ if SwaggerServerCACertificate != "" {
166+ caCert , caCertErr := ioutil .ReadFile (SwaggerServerCACertificate )
167+ if caCertErr == nil {
168+ restapi .GlobalRootCAs .AppendCertsFromPEM (caCert )
169+ }
162170 }
163171 }
164172
@@ -170,7 +178,7 @@ func startServer(ctx *cli.Context) error {
170178 server .TLSHost = ctx .String ("tls-host" )
171179 // Need to store tls-port, tls-host un config variables so secure.middleware can read from there
172180 restapi .TLSPort = fmt .Sprintf ("%v" , ctx .Int ("tls-port" ))
173- restapi .TLSHostname = ctx .String ("tls- host" )
181+ restapi .Hostname = ctx .String ("host" )
174182 restapi .TLSRedirect = ctx .String ("tls-redirect" )
175183 }
176184
0 commit comments