-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
users and groups commands: added subcommands to be prepared for editi…
…ng capabilities later
- Loading branch information
Showing
11 changed files
with
254 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"bisecur/cli" | ||
"bisecur/sdk" | ||
"github.com/spf13/viper" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
groupsCmd := &cobra.Command{ | ||
Use: GroupsCmdName, | ||
Short: "Manages users defined in your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
PreRunE: preRunFuncs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// TODO implement query user list and rights, add and delete user, password change of an already existing user | ||
|
||
deviceMac := viper.GetString(ArgNameDeviceMac) | ||
host := viper.GetString(ArgNameHost) | ||
port := viper.GetInt(ArgNamePort) | ||
token := viper.GetUint32(ArgNameToken) | ||
|
||
mac, err := cli.ParesMacString(deviceMac) | ||
if err != nil { | ||
log.Fatalf("%v", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = listGroups(localMac, mac, host, port, token) | ||
if err != nil { | ||
log.Fatalf("%v", err) | ||
os.Exit(2) | ||
} | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(groupsCmd) | ||
var groupsCmd = &cobra.Command{ | ||
Use: GroupsCmdName, | ||
Short: "Manages doors defined in your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
PreRunE: preRunFuncs, | ||
Run: nil, | ||
} | ||
|
||
func listGroups(localMac [6]byte, mac [6]byte, host string, port int, token uint32) error { | ||
client := sdk.NewClient(log, localMac, mac, host, port, token) | ||
err := client.Open() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
err2 := client.Close() | ||
if err2 != nil { | ||
log.Errorf("%v", err) | ||
} | ||
}() | ||
|
||
var groups *sdk.Groups | ||
err = retry(func() error { | ||
var err2 error | ||
groups, err2 = client.GetGroups() | ||
return err2 | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Infof("Groups: %s", groups.String()) | ||
|
||
return nil | ||
func init() { | ||
rootCmd.AddCommand(groupsCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var groupsCreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new gateway group", | ||
Long: `Create a new gateway group`, | ||
PreRunE: preRunFuncs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Fatalf("Not implemented yet") | ||
}, | ||
} | ||
|
||
func init() { | ||
groupsCmd.AddCommand(groupsCreateCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var groupsDeleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete a gateway group", | ||
Long: `Delete a gateway group`, | ||
PreRunE: preRunFuncs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Fatalf("Not implemented yet") | ||
}, | ||
} | ||
|
||
func init() { | ||
groupsCmd.AddCommand(groupsDeleteCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cmd | ||
|
||
import ( | ||
"bisecur/cli" | ||
"bisecur/sdk" | ||
"github.com/spf13/viper" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var groupsListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List current gateway groups", | ||
Long: `List current gateway groups`, | ||
PreRunE: preRunFuncs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
deviceMac := viper.GetString(ArgNameDeviceMac) | ||
host := viper.GetString(ArgNameHost) | ||
port := viper.GetInt(ArgNamePort) | ||
token := viper.GetUint32(ArgNameToken) | ||
|
||
mac, err := cli.ParesMacString(deviceMac) | ||
if err != nil { | ||
log.Fatalf("%v", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = listGroups(localMac, mac, host, port, token) | ||
if err != nil { | ||
log.Fatalf("%v", err) | ||
os.Exit(2) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
groupsCmd.AddCommand(groupsListCmd) | ||
} | ||
|
||
func listGroups(localMac [6]byte, mac [6]byte, host string, port int, token uint32) error { | ||
client := sdk.NewClient(log, localMac, mac, host, port, token) | ||
err := client.Open() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
err2 := client.Close() | ||
if err2 != nil { | ||
log.Errorf("%v", err) | ||
} | ||
}() | ||
|
||
var groups *sdk.Groups | ||
err = retry(func() error { | ||
var err2 error | ||
groups, err2 = client.GetGroups() | ||
return err2 | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Infof("Groups: %s", groups.String()) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// passwordChangeCmd represents the passwordChange command | ||
var passwordChangeCmd = &cobra.Command{ | ||
Use: "passwordChange", | ||
Short: "Change password of a gateway user", | ||
Long: `Change password of a gateway user`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Fatalf("Not implemented yet") | ||
}, | ||
} | ||
|
||
func init() { | ||
usersCmd.AddCommand(passwordChangeCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"bisecur/cli" | ||
"bisecur/sdk" | ||
"github.com/spf13/viper" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
usersCmd := &cobra.Command{ | ||
Use: UsersCmdUse, | ||
Short: "Manages users defined in your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
PreRunE: preRunFuncs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// TODO implement query user list and rights, add and delete user, password change of an already existing user | ||
|
||
deviceMac := viper.GetString(ArgNameDeviceMac) | ||
host := viper.GetString(ArgNameHost) | ||
port := viper.GetInt(ArgNamePort) | ||
token := viper.GetUint32(ArgNameToken) | ||
|
||
mac, err := cli.ParesMacString(deviceMac) | ||
if err != nil { | ||
log.Fatalf("%v", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = listUsers(localMac, mac, host, port, token) | ||
if err != nil { | ||
log.Fatalf("%v", err) | ||
os.Exit(2) | ||
} | ||
}, | ||
} | ||
|
||
rootCmd.AddCommand(usersCmd) | ||
var usersCmd = &cobra.Command{ | ||
Use: UsersCmdUse, | ||
Short: "Manages users defined in your Hörmann BiSecur gateway.", | ||
Long: ``, | ||
PreRunE: preRunFuncs, | ||
Run: nil, | ||
} | ||
|
||
func listUsers(localMac [6]byte, mac [6]byte, host string, port int, token uint32) error { | ||
client := sdk.NewClient(log, localMac, mac, host, port, token) | ||
err := client.Open() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer func() { | ||
err2 := client.Close() | ||
if err2 != nil { | ||
log.Errorf("%v", err) | ||
} | ||
}() | ||
|
||
var users *sdk.Users | ||
err = retry(func() error { | ||
var err2 error | ||
users, err2 = client.GetUsers() | ||
return err2 | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Infof("Users: %s", users.String()) | ||
|
||
return nil | ||
func init() { | ||
rootCmd.AddCommand(usersCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var usersCreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a new gateway user", | ||
Long: `Create a new gateway user`, | ||
PreRunE: preRunFuncs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Fatalf("Not implemented yet") | ||
}, | ||
} | ||
|
||
func init() { | ||
usersCmd.AddCommand(usersCreateCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var usersDeleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete a gateway user", | ||
Long: `Delete a gateway user`, | ||
PreRunE: preRunFuncs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Fatalf("Not implemented yet") | ||
}, | ||
} | ||
|
||
func init() { | ||
usersCmd.AddCommand(usersDeleteCmd) | ||
} |
Oops, something went wrong.