NOISSUE - Rename bashflux to cli and fix cert path (#349)

* NOISSUE - rename bashflux to cli and fix cert path

Signed-off-by: drasko <drasko.draskovic@gmail.com>

* Fix pkg name

Signed-off-by: drasko <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2018-08-16 13:41:27 +02:00 committed by GitHub
parent 455fedf075
commit 2c988c19b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 113 additions and 61 deletions

View File

@ -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

View File

@ -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"}' <user_auth_token>`
* Provisioning applications: `bashflux things create '{"type":"app", "name":"nyDevice"}' <user_auth_token>`
* Retrieving all provisioned things: `bashflux things get all --offset=1 --limit=5 <user_auth_token>`
* Retrieving a specific thing: `bashflux things get <thing_id> --offset=1 --limit=5 <user_auth_token>`
* Removing things: ``bashflux things delete <thing_id> <user_auth_token>``
* Provisioning devices: `bashflux channels create '{"name":"nyChannel"}' <user_auth_token>`
* Provisioning applications: `bashflux channels create '{"name":"nyChannel"}' <user_auth_token>`
* Retrieving all provisioned channels: `bashflux channels get all --offset=1 --limit=5 <user_auth_token>`
* Retrieving a specific channel: `bashflux channels get <channel_id> --offset=1 --limit=5 <user_auth_token>`
* Removing channels: `bashflux channels delete <channel_id> <user_auth_token>`
### Access control
* Connect things to a channel: `bashflux things connect <thing_id> <channel_id> <user_auth_token>`
* Disconnect things from channel: `bashflux things disconnect <thing_id> <channel_id> <user_auth_token>`
* Send a message over HTTP: `bashflux msg send <channel_id> '[{"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}]' <thing_auth_token>`

87
cli/README.md Normal file
View File

@ -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"}' <user_auth_token>
```
#### Provision Application
```
mainflux-cli things create '{"type":"app", "name":"nyDevice"}' <user_auth_token>
```
#### Retrieve All Things
```
mainflux-cli things get all --offset=1 --limit=5 <user_auth_token>
```
#### Retrieve Thing By ID
```
mainflux-cli things get <thing_id> --offset=1 --limit=5 <user_auth_token>
```
#### Remove Thing
```
mainflux-cli things delete <thing_id> <user_auth_token>
```
#### Provision Channel
```
mainflux-cli channels create '{"name":"nyChannel"}' <user_auth_token>
```
#### Retrieve All Channels
```
mainflux-cli channels get all --offset=1 --limit=5 <user_auth_token>
```
#### Retrievie Channel By ID
```
mainflux-cli channels get <channel_id> --offset=1 --limit=5 <user_auth_token>
```
#### Remove Channel
```
mainflux-cli channels delete <channel_id> <user_auth_token>
```
### Access control
#### Connect Thing to a Channel
```
mainflux-cli things connect <thing_id> <channel_id> <user_auth_token>
```
#### Disconnect Things from a Channel
```
mainflux-cli things disconnect <thing_id> <channel_id> <user_auth_token>
```
### Messaging
#### Send a message over HTTP
```
mainflux-cli msg send <channel_id> '[{"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}]' <thing_auth_token>
```

View File

@ -1,4 +1,4 @@
package cmd
package cli
import (
"fmt"

View File

@ -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

View File

@ -1,4 +1,4 @@
package cmd
package cli
import (
"net/http"

View File

@ -1,4 +1,4 @@
package cmd
package cli
import (
"fmt"

View File

@ -1,4 +1,4 @@
package cmd
package cli
import (
"fmt"

View File

@ -1,4 +1,4 @@
package cmd
package cli
import (
"fmt"

View File

@ -1,4 +1,4 @@
package cmd
package cli
import (
"fmt"

View File

@ -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)