From 2c988c19b07ae5f51e64f0dca07b98a49fe5d946 Mon Sep 17 00:00:00 2001 From: Drasko DRASKOVIC Date: Thu, 16 Aug 2018 13:41:27 +0200 Subject: [PATCH] NOISSUE - Rename bashflux to cli and fix cert path (#349) * NOISSUE - rename bashflux to cli and fix cert path Signed-off-by: drasko * Fix pkg name Signed-off-by: drasko --- Makefile | 2 +- bashflux/README.md | 33 ------------- cli/README.md | 87 +++++++++++++++++++++++++++++++++++ {bashflux => cli}/channels.go | 2 +- {bashflux => cli}/http.go | 18 ++++---- {bashflux => cli}/message.go | 2 +- {bashflux => cli}/things.go | 2 +- {bashflux => cli}/users.go | 2 +- {bashflux => cli}/utils.go | 2 +- {bashflux => cli}/version.go | 2 +- cmd/{bashflux => cli}/main.go | 22 ++++----- 11 files changed, 113 insertions(+), 61 deletions(-) delete mode 100644 bashflux/README.md create mode 100644 cli/README.md rename {bashflux => cli}/channels.go (99%) rename {bashflux => cli}/http.go (71%) rename {bashflux => cli}/message.go (98%) rename {bashflux => cli}/things.go (99%) rename {bashflux => cli}/users.go (99%) rename {bashflux => cli}/utils.go (99%) rename {bashflux => cli}/version.go (97%) rename cmd/{bashflux => cli}/main.go (68%) diff --git a/Makefile b/Makefile index d13e8a27..d307a5a4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BUILD_DIR = build -SERVICES = users things http normalizer ws influxdb mongodb-writer mongodb-reader cassandra-writer cassandra-reader +SERVICES = users things http normalizer ws influxdb mongodb-writer mongodb-reader cassandra-writer cassandra-reader cli DOCKERS = $(addprefix docker_,$(SERVICES)) CGO_ENABLED ?= 0 GOOS ?= linux diff --git a/bashflux/README.md b/bashflux/README.md deleted file mode 100644 index c509ea8e..00000000 --- a/bashflux/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Bashflux - Command line interface (CLI) for Mainflux system. -## Quickstart -``` -cd bashflux -go build -``` - -## Usage -### Service -* Get the service verison: `bashflux version` - -### User management -* `bashflux users create john.doe@email.com password` -* `bashflux users token john.doe@email.com password` - -### System provisioning -* Provisioning devices: `bashflux things create '{"type":"device", "name":"nyDevice"}' ` -* Provisioning applications: `bashflux things create '{"type":"app", "name":"nyDevice"}' ` -* Retrieving all provisioned things: `bashflux things get all --offset=1 --limit=5 ` -* Retrieving a specific thing: `bashflux things get --offset=1 --limit=5 ` -* Removing things: ``bashflux things delete `` - -* Provisioning devices: `bashflux channels create '{"name":"nyChannel"}' ` -* Provisioning applications: `bashflux channels create '{"name":"nyChannel"}' ` -* Retrieving all provisioned channels: `bashflux channels get all --offset=1 --limit=5 ` -* Retrieving a specific channel: `bashflux channels get --offset=1 --limit=5 ` -* Removing channels: `bashflux channels delete ` - -### Access control -* Connect things to a channel: `bashflux things connect ` -* Disconnect things from channel: `bashflux things disconnect ` - -* Send a message over HTTP: `bashflux msg send '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]' ` diff --git a/cli/README.md b/cli/README.md new file mode 100644 index 00000000..122cd284 --- /dev/null +++ b/cli/README.md @@ -0,0 +1,87 @@ +# Mainflux CLI +## Build +From the project root: +``` +make cli +``` + +## Usage +### Service +#### Get the service verison +``` +mainflux-cli version +``` + +### User management +#### Create User +``` +mainflux-cli users create john.doe@email.com password +``` + +#### Login User +``` +mainflux-cli users token john.doe@email.com password +``` + +### System Provisioning +#### Provision Device +``` +mainflux-cli things create '{"type":"device", "name":"nyDevice"}' +``` + +#### Provision Application +``` +mainflux-cli things create '{"type":"app", "name":"nyDevice"}' +``` + +#### Retrieve All Things +``` +mainflux-cli things get all --offset=1 --limit=5 +``` + +#### Retrieve Thing By ID +``` +mainflux-cli things get --offset=1 --limit=5 +``` + +#### Remove Thing +``` +mainflux-cli things delete +``` + +#### Provision Channel +``` +mainflux-cli channels create '{"name":"nyChannel"}' +``` + +#### Retrieve All Channels +``` +mainflux-cli channels get all --offset=1 --limit=5 +``` + +#### Retrievie Channel By ID +``` +mainflux-cli channels get --offset=1 --limit=5 +``` + +#### Remove Channel +``` +mainflux-cli channels delete +``` + +### Access control +#### Connect Thing to a Channel +``` +mainflux-cli things connect +``` + +#### Disconnect Things from a Channel +``` +mainflux-cli things disconnect +``` + +### Messaging +#### Send a message over HTTP +``` +mainflux-cli msg send '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]' +``` diff --git a/bashflux/channels.go b/cli/channels.go similarity index 99% rename from bashflux/channels.go rename to cli/channels.go index 0cf357ba..6d2bfb1b 100644 --- a/bashflux/channels.go +++ b/cli/channels.go @@ -1,4 +1,4 @@ -package cmd +package cli import ( "fmt" diff --git a/bashflux/http.go b/cli/http.go similarity index 71% rename from bashflux/http.go rename to cli/http.go index eba383a0..ad899d71 100644 --- a/bashflux/http.go +++ b/cli/http.go @@ -1,4 +1,4 @@ -package cmd +package cli import ( "crypto/tls" @@ -14,21 +14,19 @@ import ( ) const ( - envCertFile = "MF_CERT_FILE" - envKeyFile = "MF_KEY_FILE" - envCaFile = "MF_CA_FILE" + defCertsPath = "/src/github.com/mainflux/mainflux/docker/ssl/certs/" + envCertFile = "MF_CERT_FILE" + envKeyFile = "MF_KEY_FILE" + envCaFile = "MF_CA_FILE" ) var ( httpClient = &http.Client{} serverAddr = fmt.Sprintf("https://%s", "localhost") - defCertFile = fmt.Sprintf("%s%s", os.Getenv("GOPATH"), - "src/github.com/mainflux/mainflux/docker/ssl/certs/mainflux-server.crt") - defKeyFile = fmt.Sprintf("%s%s", os.Getenv("GOPATH"), - "src/github.com/mainflux/mainflux/docker/ssl/certs/mainflux-server.key") - defCaFile = fmt.Sprintf("%s%s", os.Getenv("GOPATH"), - "src/github.com/mainflux/mainflux/docker/ssl/certs/ca.crt") + defCertFile = fmt.Sprintf("%s%s%s", os.Getenv("GOPATH"), defCertsPath, "mainflux-server.crt") + defKeyFile = fmt.Sprintf("%s%s%s", os.Getenv("GOPATH"), defCertsPath, "mainflux-server.key") + defCaFile = fmt.Sprintf("%s%s%s", os.Getenv("GOPATH"), defCertsPath, "ca.crt") ) // SetServerAddr - set addr using host and port diff --git a/bashflux/message.go b/cli/message.go similarity index 98% rename from bashflux/message.go rename to cli/message.go index e75dc346..0920c66e 100644 --- a/bashflux/message.go +++ b/cli/message.go @@ -1,4 +1,4 @@ -package cmd +package cli import ( "net/http" diff --git a/bashflux/things.go b/cli/things.go similarity index 99% rename from bashflux/things.go rename to cli/things.go index f1505d5b..32ade02a 100644 --- a/bashflux/things.go +++ b/cli/things.go @@ -1,4 +1,4 @@ -package cmd +package cli import ( "fmt" diff --git a/bashflux/users.go b/cli/users.go similarity index 99% rename from bashflux/users.go rename to cli/users.go index 2f705404..b5a80c1d 100644 --- a/bashflux/users.go +++ b/cli/users.go @@ -1,4 +1,4 @@ -package cmd +package cli import ( "fmt" diff --git a/bashflux/utils.go b/cli/utils.go similarity index 99% rename from bashflux/utils.go rename to cli/utils.go index 593134df..8382b7d0 100644 --- a/bashflux/utils.go +++ b/cli/utils.go @@ -1,4 +1,4 @@ -package cmd +package cli import ( "fmt" diff --git a/bashflux/version.go b/cli/version.go similarity index 97% rename from bashflux/version.go rename to cli/version.go index 5d85cc48..8d2c7fdc 100644 --- a/bashflux/version.go +++ b/cli/version.go @@ -1,4 +1,4 @@ -package cmd +package cli import ( "fmt" diff --git a/cmd/bashflux/main.go b/cmd/cli/main.go similarity index 68% rename from cmd/bashflux/main.go rename to cmd/cli/main.go index 2e6176bc..3b8b5bae 100644 --- a/cmd/bashflux/main.go +++ b/cmd/cli/main.go @@ -3,7 +3,7 @@ package main import ( "log" - bf "github.com/mainflux/mainflux/bashflux" + "github.com/mainflux/mainflux/cli" "github.com/spf13/cobra" ) @@ -19,19 +19,19 @@ func main() { // Root var rootCmd = &cobra.Command{ - Use: "bashflux", + Use: "mainflux-cli", PersistentPreRun: func(cmd *cobra.Command, args []string) { // Set HTTP server address - bf.SetServerAddr(conf.Host, conf.Port) + cli.SetServerAddr(conf.Host, conf.Port) }, } // API commands - versionCmd := bf.NewVersionCmd() - usersCmd := bf.NewUsersCmd() - thingsCmd := bf.NewThingsCmd() - channelsCmd := bf.NewChannelsCmd() - messagesCmd := bf.NewMessagesCmd() + versionCmd := cli.NewVersionCmd() + usersCmd := cli.NewUsersCmd() + thingsCmd := cli.NewThingsCmd() + channelsCmd := cli.NewChannelsCmd() + messagesCmd := cli.NewMessagesCmd() // Root Commands rootCmd.AddCommand(versionCmd) @@ -48,12 +48,12 @@ func main() { // Client and Channels Flags rootCmd.PersistentFlags().IntVarP( - &bf.Limit, "limit", "l", 100, "limit query parameter") + &cli.Limit, "limit", "l", 100, "limit query parameter") rootCmd.PersistentFlags().IntVarP( - &bf.Offset, "offset", "o", 0, "offset query parameter") + &cli.Offset, "offset", "o", 0, "offset query parameter") // Set TLS certificates - bf.SetCerts() + cli.SetCerts() if err := rootCmd.Execute(); err != nil { log.Fatal(err)