1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00

NOISSUE - Add insecure param to cli (#356)

Signed-off-by: drasko <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2018-08-17 04:58:09 +02:00 committed by GitHub
parent 1683d17830
commit af281da430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -30,8 +30,8 @@ var (
) )
// SetServerAddr - set addr using host and port // SetServerAddr - set addr using host and port
func SetServerAddr(host string, port int) { func SetServerAddr(proto string, host string, port int) {
serverAddr = fmt.Sprintf("https://%s", host) serverAddr = fmt.Sprintf("%s://%s", proto, host)
if port != 0 { if port != 0 {
serverAddr = fmt.Sprintf("%s:%s", serverAddr, strconv.Itoa(port)) serverAddr = fmt.Sprintf("%s:%s", serverAddr, strconv.Itoa(port))

View File

@ -10,19 +10,29 @@ import (
func main() { func main() {
conf := struct { conf := struct {
Host string host string
Port int port int
insecure bool
}{ }{
"localhost", "localhost",
0, 0,
false,
} }
// Root // Root
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "mainflux-cli", Use: "mainflux-cli",
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Set HTTP server address var proto string
cli.SetServerAddr(conf.Host, conf.Port)
if conf.insecure {
proto = "http"
} else {
proto = "https"
cli.SetCerts()
}
cli.SetServerAddr(proto, conf.host, conf.port)
}, },
} }
@ -42,9 +52,11 @@ func main() {
// Root Flags // Root Flags
rootCmd.PersistentFlags().StringVarP( rootCmd.PersistentFlags().StringVarP(
&conf.Host, "host", "m", conf.Host, "HTTP Host address") &conf.host, "host", "m", conf.host, "HTTP Host address")
rootCmd.PersistentFlags().IntVarP( rootCmd.PersistentFlags().IntVarP(
&conf.Port, "port", "p", conf.Port, "HTTP Host Port") &conf.port, "port", "p", conf.port, "HTTP Host Port")
rootCmd.PersistentFlags().BoolVarP(
&conf.insecure, "insecure", "i", false, "do not use TLS")
// Client and Channels Flags // Client and Channels Flags
rootCmd.PersistentFlags().IntVarP( rootCmd.PersistentFlags().IntVarP(
@ -52,9 +64,6 @@ func main() {
rootCmd.PersistentFlags().IntVarP( rootCmd.PersistentFlags().IntVarP(
&cli.Offset, "offset", "o", 0, "offset query parameter") &cli.Offset, "offset", "o", 0, "offset query parameter")
// Set TLS certificates
cli.SetCerts()
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
log.Fatal(err) log.Fatal(err)
} }