mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-27 13:48:49 +08:00

* Refactor Mainflux go SDK Add structures instead of string parameters. Add offset and limit parameters to things and channels methods. Add better configuration support. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Add new public errors with better error handling Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update SDK to use uint instread of string id Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update cli to use new SDK API Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Remove TLS termination from nginx configuration Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Update SDK documentation and structures Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Refactor things service Decouple HTTP layer from business logic. Remove ID number validation check. Remove models from HTTP requests and responses. Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Reformat tests for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com> * Increase test coverage for things service Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
80 lines
1.4 KiB
Go
80 lines
1.4 KiB
Go
//
|
|
// Copyright (c) 2018
|
|
// Mainflux
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package cli
|
|
|
|
import (
|
|
mfxsdk "github.com/mainflux/mainflux/sdk/go"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var cmdUsers = []cobra.Command{
|
|
cobra.Command{
|
|
Use: "create",
|
|
Short: "create <username> <password>",
|
|
Long: `Creates new user`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if len(args) != 2 {
|
|
logUsage(cmd.Short)
|
|
return
|
|
}
|
|
|
|
user := mfxsdk.User{
|
|
Email: args[0],
|
|
Password: args[1],
|
|
}
|
|
if err := sdk.CreateUser(user); err != nil {
|
|
logError(err)
|
|
return
|
|
}
|
|
|
|
logOK()
|
|
},
|
|
},
|
|
cobra.Command{
|
|
Use: "token",
|
|
Short: "token <username> <password>",
|
|
Long: `Creates new token`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if len(args) != 2 {
|
|
logUsage(cmd.Short)
|
|
return
|
|
}
|
|
|
|
user := mfxsdk.User{
|
|
Email: args[0],
|
|
Password: args[1],
|
|
}
|
|
token, err := sdk.CreateToken(user)
|
|
if err != nil {
|
|
logError(err)
|
|
return
|
|
}
|
|
|
|
flush(token)
|
|
},
|
|
},
|
|
}
|
|
|
|
// NewUsersCmd returns users command.
|
|
func NewUsersCmd() *cobra.Command {
|
|
cmd := cobra.Command{
|
|
Use: "users",
|
|
Short: "users create/token <email> <password>",
|
|
Long: `Manages users in the system (create account or token)`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
logUsage(cmd.Short)
|
|
},
|
|
}
|
|
|
|
for i := range cmdUsers {
|
|
cmd.AddCommand(&cmdUsers[i])
|
|
}
|
|
|
|
return &cmd
|
|
}
|