Skip to content

Commit

Permalink
chore: Update conceal version to 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
infamousjoeg committed May 30, 2024
1 parent 5c102f5 commit f61d66d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 37 deletions.
28 changes: 14 additions & 14 deletions cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package cmd

import (
"os"

"github.com/infamousjoeg/conceal/pkg/conceal"
"github.com/infamousjoeg/conceal/pkg/conceal/keychain"
"github.com/spf13/cobra"
)

// getCmd represents the get command
var getCmd = &cobra.Command{
Use: "get",
Short: "Retrieves and copies secret value to clipboard",
Use: "get",
Aliases: []string{"cp", "retrieve"},
Short: "Retrieves and copies secret value to clipboard",
Long: `Retrieves and copies the secret name provided's secret value.
The secret value is copied to the clipboard for 15 seconds.
Example Usage:
$ conceal get aws/access_key_id`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
keychain.GetSecret(args[0])
secretName := conceal.GetSecretName(args)
conceal.PrintInfo("Adding secret value to clipboard for 15 seconds...")
err := keychain.GetSecret(secretName, "clipboard")
if err != nil {
conceal.PrintError("Failed to get secret value from keychain.")
os.Exit(1)
}
conceal.PrintSuccess("Secret cleared from clipboard.")
},
}

func init() {
rootCmd.AddCommand(getCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// getCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// getCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
20 changes: 15 additions & 5 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,33 @@ package cmd
import (
"fmt"

"github.com/infamousjoeg/conceal/pkg/conceal"
"github.com/infamousjoeg/conceal/pkg/conceal/keychain"
"github.com/spf13/cobra"
)

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "List all concealed secret names",
Use: "list",
Aliases: []string{"ls"},
Short: "List all concealed secret names",
Long: `Returns a list of conceal set secret names from the secret provider.
Example Usage:
$ conceal list`,
Run: func(cmd *cobra.Command, args []string) {
// List all secrets in keychain with service label `summon`
accounts := keychain.ListSecrets()
fmt.Println("The following Summon accounts are in keychain:")
for account := range accounts {
fmt.Println(accounts[account])

conceal.PrintInfo("The following Summon/Conceal accounts are in keychain:")

uniqueAccounts := make(map[string]bool)
for _, account := range accounts {
value := account.Account
if !uniqueAccounts[value] {
uniqueAccounts[value] = true
fmt.Println(account.Account)
}
}
},
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ var rootCmd = &cobra.Command{
Use: "conceal",
Short: "Conceal is a command-line utility that eases the interaction between developer and OSX Keychain Access.",
Long: `Conceal is a command-line utility that eases the interaction between
developer and OSX Keychain Access. It is the open-source companion to Summon
developer and the OS secret provider, like MacOS Keychain. It is the open-source companion to Summon
as every secret added using this tool into Keychain is added using
Summon-compliant formatting.
Example Usages:
$ conceal set app/secret
$ conceal unset app/secret
$ conceal update app/secret
$ conceal get app/secret
$ conceal list`,
$ conceal list
$ conceal summon install
$ conceal summon show app/secret`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
56 changes: 44 additions & 12 deletions cmd/set.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,67 @@
package cmd

import (
"bufio"
"fmt"
"log"
"os"
"strings"
"syscall"

"github.com/infamousjoeg/conceal/pkg/conceal"
"github.com/infamousjoeg/conceal/pkg/conceal/keychain"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

// setCmd represents the set command
var setCmd = &cobra.Command{
Use: "set",
Short: "Add a secret name and value to secret provider",
Use: "set",
Aliases: []string{"add", "create"},
Short: "Add a secret name and value to secret provider",
Long: `Sets a given secret name and secret value within the secret provider.
Example Usage:
$ conceal set aws/access_key_id`,
Args: cobra.ExactArgs(1),
$ conceal set aws/access_key_id
$ echo "my_secret_value" | conceal set aws/access_key_id`,
Run: func(cmd *cobra.Command, args []string) {
// Get secret value from STDIN
fmt.Println("Please enter the secret value: ")
byteSecretVal, err := terminal.ReadPassword(int(syscall.Stdin))
// Check if secret name is empty
secretName := conceal.GetSecretName(args)

// Check if secret already exists to save the user time
if keychain.SecretExists(secretName) {
conceal.PrintError("Secret already exists in keychain. Please use `conceal update` instead.")
}

var byteSecretVal []byte
info, err := os.Stdin.Stat()
if err != nil {
log.Fatalln("An error occurred trying to read password from " +
"Stdin. Exiting...")
conceal.PrintError("An error occurred while checking stdin. Exiting...")
}

// Get secret value from STDIN
if (info.Mode() & os.ModeCharDevice) == 0 {
// Reading from STDIN
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
conceal.PrintError("An error occurred while reading stdin. Exiting...")
}
byteSecretVal = []byte(strings.TrimSpace(input))
} else {
fmt.Println("Please enter the secret value: ")
byteSecretVal, err = term.ReadPassword(int(syscall.Stdin))
if err != nil {
conceal.PrintError("An error occurred trying to read password. Exiting...")
}
}

// Add secret and secret value to keychain
keychain.AddSecret(args[0], byteSecretVal)
err = keychain.AddSecret(secretName, byteSecretVal)
if err != nil {
conceal.PrintError("An error occurred while adding secret to keychain.")
}

conceal.PrintSuccess("Secret added to keychain.")
},
}

Expand Down
13 changes: 10 additions & 3 deletions cmd/unset.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package cmd

import (
"github.com/infamousjoeg/conceal/pkg/conceal"
"github.com/infamousjoeg/conceal/pkg/conceal/keychain"
"github.com/spf13/cobra"
)

// unsetCmd represents the unset command
var unsetCmd = &cobra.Command{
Use: "unset",
Short: "Remove a secret from secret provider",
Use: "unset",
Aliases: []string{"rm", "delete"},
Short: "Remove a secret from secret provider",
Long: `Unset removes a secret name and secret value entry from your secret provider.
Example Usage:
$ conceal unset aws/access_key_id`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
keychain.DeleteSecret(args[0])
err := keychain.DeleteSecret(args[0])
if err != nil {
conceal.PrintError("Failed to delete secret from keychain.")
}

conceal.PrintSuccess("Secret successfully deleted from keychain.")
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/conceal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package conceal
import "fmt"

// Version field is a SemVer that should indicate the baked-in version of conceal
var Version = "3.0.0"
var Version = "4.0.0"

// Tag field denotes the specific build type for the broker. It may be replaced by compile-time variables if needed to
// provide the git commit information in the final binary.
Expand Down

0 comments on commit f61d66d

Please sign in to comment.