This commit is contained in:
jake 2025-05-31 10:32:21 -04:00
parent 49c508aae7
commit 5c7c748a69
5 changed files with 13 additions and 11 deletions

View File

@ -14,7 +14,7 @@ import (
*/ */
type Client struct { type Client struct {
cli *mcr.Client cli mcr.Client
} }
type IClient interface { type IClient interface {
@ -25,9 +25,9 @@ type IClient interface {
// creates a new mcr client using saved credentials and decrypted password // creates a new mcr client using saved credentials and decrypted password
func New() (*Client, error) { func New() (*Client, error) {
//grab saved credentials //grab saved credentials
server := viper.Get("server").(string) server := viper.GetString("server")
password := viper.Get("password").(string) password := viper.GetString("password")
port := viper.Get("port").(int) port := viper.GetInt("port")
fmt.Printf("Logging into %s on port %d\n", server, port) fmt.Printf("Logging into %s on port %d\n", server, port)
//decrypt password //decrypt password

View File

@ -24,7 +24,7 @@ var loginCmd = &cobra.Command{
sending commands to server and printing the response.`, sending commands to server and printing the response.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
//grab saved credentials //grab saved credentials
server := viper.Get("server").(string) server := viper.GetString("server")
cli, err := client.New() cli, err := client.New()
cobra.CheckErr(err) cobra.CheckErr(err)
defer cli.Close() defer cli.Close()

View File

@ -8,8 +8,8 @@ import (
) )
func EncryptPassword(b []byte) ([]byte, error) { func EncryptPassword(b []byte) ([]byte, error) {
nonce := viper.Get("nonce").(string) nonce := viper.GetString("nonce")
dev := viper.Get("device").(string) dev := viper.GetString("device")
block, err := aes.NewCipher([]byte(dev)) block, err := aes.NewCipher([]byte(dev))
if err != nil { if err != nil {
@ -29,9 +29,9 @@ func EncryptPassword(b []byte) ([]byte, error) {
} }
func DecryptPassword(b []byte) (string, error) { func DecryptPassword(b []byte) (string, error) {
nonce := viper.Get("nonce").(string) nonce := viper.GetString("nonce")
password := viper.Get("password").(string) password := viper.GetString("password")
dev := viper.Get("device").(string) dev := viper.GetString("device")
block, err := aes.NewCipher([]byte(dev)) block, err := aes.NewCipher([]byte(dev))
if err != nil { if err != nil {

2
go.mod
View File

@ -3,7 +3,7 @@ module code.jakeyoungdev.com/jake/mctl
go 1.24.2 go 1.24.2
require ( require (
github.com/jake-young-dev/mcr v1.3.1 github.com/jake-young-dev/mcr v1.3.3-0.20250531035550-4d1e822a867f
github.com/spf13/cobra v1.9.1 github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1 github.com/spf13/viper v1.20.1
golang.org/x/term v0.31.0 golang.org/x/term v0.31.0

2
go.sum
View File

@ -14,6 +14,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jake-young-dev/mcr v1.3.1 h1:ELJsrJHwQsMiM09o+q8auUaiGXXX3DWIgh/TfZQc0B0= github.com/jake-young-dev/mcr v1.3.1 h1:ELJsrJHwQsMiM09o+q8auUaiGXXX3DWIgh/TfZQc0B0=
github.com/jake-young-dev/mcr v1.3.1/go.mod h1:74yZHGf9h3tLUDUpInA17grKLrNp9lVesWvisCFCXKY= github.com/jake-young-dev/mcr v1.3.1/go.mod h1:74yZHGf9h3tLUDUpInA17grKLrNp9lVesWvisCFCXKY=
github.com/jake-young-dev/mcr v1.3.3-0.20250531035550-4d1e822a867f h1:G0G+K+dtO63jByfA7XDxvP8dCTET5C+CRbJjFCysXwM=
github.com/jake-young-dev/mcr v1.3.3-0.20250531035550-4d1e822a867f/go.mod h1:74yZHGf9h3tLUDUpInA17grKLrNp9lVesWvisCFCXKY=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=