Skip to content

Commit

Permalink
few Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddheshk02 committed Nov 27, 2023
1 parent 05e8c44 commit 1b2384c
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 79 deletions.
7 changes: 6 additions & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/user"
"path/filepath"
"strings"

"github.com/Siddheshk02/Securelee-cli/lib"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -43,13 +44,17 @@ var createCmd = &cobra.Command{

var userData struct {
UserID string `json:"userID"`
Email string `json:"email"`
}
err = json.Unmarshal(jsonData, &userData)
if err != nil {
log.Fatalln("\033[31m", err.Error(), "\033[0m")
}
email := strings.Replace(userData.Email, "@", "-", -1)
Newemail := strings.Replace(email, ".", "-", -1)
fmt.Println(Newemail)

err = lib.Create(userData.UserID)
err = lib.Create(Newemail)
if err != nil {
log.Fatalln("\033[31m", err.Error(), "\033[0m")
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/user"
"path/filepath"
"strings"

"github.com/Siddheshk02/Securelee-cli/lib"
"github.com/spf13/cobra"
Expand All @@ -22,7 +23,6 @@ var deleteCmd = &cobra.Command{
Short: "Delete a Secret Message or Key.",
Long: `Delete a Secret Message or Key.`,
Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("delete called")
res := lib.Check()
if !res {
fmt.Print("\033[31m", "\n > No User logged in, You must Login to use Securelee Vault Services.\n", "\033[0m")
Expand All @@ -44,12 +44,16 @@ var deleteCmd = &cobra.Command{

var userData struct {
UserID string `json:"userID"`
Email string `json:"email"`
}
err = json.Unmarshal(jsonData, &userData)
if err != nil {
log.Fatal("\033[31m", err, "\033[0m")
}

email := strings.Replace(userData.Email, "@", "-", -1)
Newemail := strings.Replace(email, ".", "-", -1)

var choice uint
fmt.Print("\033[33m", "\n Select any one option: \n", "\033[0m")
fmt.Println("\033[33m", "\n > 1. Delete a Secret", "\033[0m")
Expand All @@ -60,7 +64,7 @@ var deleteCmd = &cobra.Command{
fmt.Println("")

if choice == 1 {
res, err := lib.ListSecrets(userData.UserID)
res, err := lib.ListSecrets(Newemail)
if err != nil {
log.Fatalln("\033[31m", err.Error(), "\033[0m")
}
Expand All @@ -86,7 +90,7 @@ var deleteCmd = &cobra.Command{
}

} else if choice == 2 {
res, err := lib.ListKeys(userData.UserID)
res, err := lib.ListKeys(Newemail)
if err != nil {
log.Fatalln("\033[31m", err.Error(), "\033[0m")
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os/user"
"path/filepath"
"regexp"
"strings"
"time"

"github.com/Siddheshk02/Securelee-cli/lib"
Expand All @@ -26,7 +27,6 @@ var getCmd = &cobra.Command{
Short: "Get a Particular Secret or Key.",
Long: `Get a Particular Secret or Key.`,
Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("get called")
res := lib.Check()
if !res {
fmt.Print("\033[31m", "\n > No User logged in, You must Login to use Securelee Vault Services.\n", "\033[0m")
Expand All @@ -48,6 +48,7 @@ var getCmd = &cobra.Command{

var userData struct {
UserID string `json:"userID"`
Email string `json:"email"`
}
err = json.Unmarshal(jsonData, &userData)
if err != nil {
Expand Down Expand Up @@ -90,8 +91,10 @@ var getCmd = &cobra.Command{
}

}
folderKey := "/" + userData.UserID + "/keys/"
folderSecret := "/" + userData.UserID + "/secrets/"
email := strings.Replace(userData.Email, "@", "-", -1)
Newemail := strings.Replace(email, ".", "-", -1)
folderKey := "/" + Newemail + "/keys/"
folderSecret := "/" + Newemail + "/secrets/"

if resp != nil && *resp.Status == "Success" {
if resp.Result.Folder != folderKey {
Expand Down
18 changes: 6 additions & 12 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/user"
"path/filepath"
"strings"

"github.com/Siddheshk02/Securelee-cli/lib"
"github.com/spf13/cobra"
Expand All @@ -22,7 +23,6 @@ var listCmd = &cobra.Command{
Short: "Get all Secret Messages or Keys.",
Long: `Get all Secret Messages or Keys.`,
Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("list called")
res := lib.Check()
if !res {
fmt.Print("\033[31m", "\n > No User logged in, You must Login to use Securelee Vault Services.\n", "\033[0m")
Expand All @@ -44,11 +44,14 @@ var listCmd = &cobra.Command{

var userData struct {
UserID string `json:"userID"`
Email string `json:"email"`
}
err = json.Unmarshal(jsonData, &userData)
if err != nil {
log.Fatalln("\033[31m", err.Error(), "\033[0m")
}
email := strings.Replace(userData.Email, "@", "-", -1)
Newemail := strings.Replace(email, ".", "-", -1)

var choice int
fmt.Print("\033[33m", "\n Select any one option: \n", "\033[0m")
Expand All @@ -60,25 +63,16 @@ var listCmd = &cobra.Command{
fmt.Println("")

if choice == 1 {
_, err := lib.ListSecrets(userData.UserID)
_, err := lib.ListSecrets(Newemail)
if err != nil {
log.Fatalln("\033[31m", err.Error(), "\033[0m")
}

} else if choice == 2 {
_, err := lib.ListKeys(userData.UserID)
_, err := lib.ListKeys(Newemail)
if err != nil {
log.Fatalln("\033[31m", err.Error(), "\033[0m")
}

// for i := 0; i < count; i++ {
// fmt.Println("\n> ", i+1, " id : ", lists[i].ID)
// fmt.Println(" Name : ", lists[i].Name)
// fmt.Println(" Type : ", lists[i].Type)
// fmt.Println(" Purpose : ", lists[i].Purpose)
// fmt.Println(" Algorithm : ", lists[i].Algorithm)
// }

} else {
fmt.Println("\033[31m", " > Invalid Choice Entered!!, Please try again", "\033[0m")
fmt.Println("")
Expand Down
23 changes: 1 addition & 22 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,18 @@ var loginCmd = &cobra.Command{
fmt.Scanf("%d", &choice)
fmt.Println("")
if choice == 1 {
// c := color.New(color.FgCyan, color.Bold)
// var str any
fmt.Fprintf(out, "%s > Press Enter to Login using Browser%s", yellow, reset)
fmt.Fprintf(out, "%s (You can get back to CLI after Successful Authentication) : %s", magenta, reset)
// fmt.Print("")

_, _ = term.ReadPassword(int(os.Stdin.Fd()))

// _, key, _ := keyboard.GetSingleKey()
fmt.Println("")

// Check if the key is Enter
// if key == keyboard.KeyEnter {
lib.Login()
time.Sleep(25 * time.Second)

fmt.Fprintf(out, "%s\n > Please Enter the Token from the Securelee Authentication Tab: %s", yellow, reset)
fmt.Scan(&token)
// time.Sleep()
// }

if token == "" {
fmt.Fprintf(out, "%s > Invalid Token. Please try again.%s", red, reset)
Expand All @@ -95,7 +87,7 @@ var loginCmd = &cobra.Command{
fmt.Println("")
fmt.Fprintf(out, "%s > Enter your Password %s", yellow, reset)
fmt.Fprintf(out, "\n%s { Password must have \n - at least 8 characters,\n - at least 1 number characters,\n - at least 1 special characters } : %s", magenta, reset)
// fmt.Scan(&password)

password, _ := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println("")
check := lib.IsValidPassword(string(password))
Expand Down Expand Up @@ -146,41 +138,28 @@ var loginCmd = &cobra.Command{
Expiry: parsedTime,
}

// err = mailing.SendMail(info.Name, info.Email)
// if err != nil {
// log.Fatalln("\033[31m", err.Error(), "\033[0m")
// }

if choice == 1 {
// fmt.Fprintf(out, "\n%s > Successfully Logged in as :%s", cyan, reset)
fmt.Println("\033[36m", "\n > Successfully Logged in as ", info.Name, " (", info.Email, ")", "\033[0m")
// fmt.Print(info.Name, info.Email)
fmt.Println("")
} else if choice == 2 {
if usertype == "Old User" {
// fmt.Fprintf(out, "\n%s > Successfully Logged in as :%s", cyan, reset)
fmt.Println("\033[36m", "\n > Successfully Logged in as ", info.Name, " (", info.Email, ")", "\033[0m")
// fmt.Print(info.Name, info.Email)
fmt.Println("")
} else if usertype == "New User" {
// fmt.Fprintf(out, "\n%s > Successfully Created and Logged in as :%s", cyan, reset)
fmt.Println("\033[36m", "\n > Successfully Created and Logged in as ", info.Name, " (", info.Email, ")", "\033[0m")
// fmt.Print(info.Name, info.Email)
fmt.Println("")
}
}

currentUser, err := user.Current()
if err != nil {
// log.Fatal("\033[31m", " > Error occured!, try again.", "\033[0m")
fmt.Fprintf(out, "%s > Error occured!, try again.%s", red, reset)
return
}

path := currentUser.HomeDir + "/Securelee"
err = os.MkdirAll(path, os.ModePerm)
if err != nil {
// log.Fatal("\033[31m", "Error occured!, try again.", "\033[0m")
fmt.Fprintf(out, "%s > Error occured!, try again.%s", red, reset)
return
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ var logoutCmd = &cobra.Command{
Short: "Logout of Securelee Vault.",
Long: `Logout of Securelee Vault.`,
Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("logout called")
err := lib.Logout()
if err != nil {
// log.Fatal(err, "Error, Please try again.")
fmt.Print("\033[31m", "\n > Error, Please try Again\n", "\033[0m")
os.Exit(0)
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/user"
"path/filepath"
"strings"

"github.com/Siddheshk02/Securelee-cli/lib"
"github.com/spf13/cobra"
Expand All @@ -22,7 +23,6 @@ var updateCmd = &cobra.Command{
Short: "Update or Modify a Secret Message or Key.",
Long: `Update or Modify a Secret Message or Key.`,
Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("update called")
res := lib.Check()
if !res {
fmt.Print("\033[31m", "\n > No User logged in, You must Login to use Securelee Vault Services.\n", "\033[0m")
Expand All @@ -44,11 +44,14 @@ var updateCmd = &cobra.Command{

var userData struct {
UserID string `json:"userID"`
Email string `json:"email"`
}
err = json.Unmarshal(jsonData, &userData)
if err != nil {
log.Fatal("\033[31m", err, "\033[0m")
}
email := strings.Replace(userData.Email, "@", "-", -1)
Newemail := strings.Replace(email, ".", "-", -1)

var choice uint
fmt.Print("\033[33m", "\n Select any one option: \n", "\033[0m")
Expand All @@ -60,7 +63,7 @@ var updateCmd = &cobra.Command{
fmt.Println("")

if choice == 1 {
res, err := lib.ListSecrets(userData.UserID)
res, err := lib.ListSecrets(Newemail)
if err != nil {
log.Fatal("\033[31m", err, "\033[0m")
}
Expand All @@ -86,7 +89,7 @@ var updateCmd = &cobra.Command{
}

} else if choice == 2 {
res, err := lib.ListKeys(userData.UserID)
res, err := lib.ListKeys(Newemail)
if err != nil {
log.Fatal("\033[31m", err, "\033[0m")
}
Expand Down
1 change: 0 additions & 1 deletion cmd/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var whoamiCmd = &cobra.Command{
Short: "The Current User of Securelee Vault.",
Long: `The Current User of Securelee Vault.`,
Run: func(cmd *cobra.Command, args []string) {
// fmt.Println("whoami called")
res := lib.Check()
if !res {
fmt.Print("\033[31m", "\n > No User logged in, You must Login to use Securelee Vault Services.\n", "\033[0m")
Expand Down
Loading

0 comments on commit 1b2384c

Please sign in to comment.