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
func SetServerAddr(host string, port int) {
serverAddr = fmt.Sprintf("https://%s", host)
func SetServerAddr(proto string, host string, port int) {
serverAddr = fmt.Sprintf("%s://%s", proto, host)
if port != 0 {
serverAddr = fmt.Sprintf("%s:%s", serverAddr, strconv.Itoa(port))

View File

@ -10,19 +10,29 @@ import (
func main() {
conf := struct {
Host string
Port int
host string
port int
insecure bool
}{
"localhost",
0,
false,
}
// Root
var rootCmd = &cobra.Command{
Use: "mainflux-cli",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Set HTTP server address
cli.SetServerAddr(conf.Host, conf.Port)
var proto string
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
rootCmd.PersistentFlags().StringVarP(
&conf.Host, "host", "m", conf.Host, "HTTP Host address")
&conf.host, "host", "m", conf.host, "HTTP Host address")
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
rootCmd.PersistentFlags().IntVarP(
@ -52,9 +64,6 @@ func main() {
rootCmd.PersistentFlags().IntVarP(
&cli.Offset, "offset", "o", 0, "offset query parameter")
// Set TLS certificates
cli.SetCerts()
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}