-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update conceal package to version 4.0.0
- Loading branch information
1 parent
f61d66d
commit 2f438d2
Showing
4 changed files
with
196 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/infamousjoeg/conceal/pkg/conceal" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var installCmd = &cobra.Command{ | ||
Use: "install", | ||
Short: "Install Summon provider wrapper", | ||
Long: `This command creates a wrapper script for using Conceal as a Summon provider. | ||
Example Usage: | ||
$ conceal summon install`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
installWrapper() | ||
}, | ||
} | ||
|
||
func installWrapper() { | ||
// Define the script content | ||
scriptContent := `#!/bin/bash | ||
# Check if the correct number of arguments are provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <secret-id>" | ||
exit 1 | ||
fi | ||
# Call the conceal binary with the get argument and the provided secret ID | ||
conceal summon show "$1" | ||
` | ||
|
||
// Find the full path of the summon executable | ||
summonPath, err := exec.LookPath("summon") | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error finding Summon: %v\n", err) | ||
conceal.PrintInfo("Make sure Summon is installed and available in your PATH.") | ||
os.Exit(1) | ||
} | ||
|
||
// Get the directory where the summon executable is located | ||
summonDir := filepath.Dir(summonPath) | ||
providersPath := filepath.Join(summonDir, "Providers") | ||
scriptFilePath := filepath.Join(providersPath, "conceal_summon") | ||
|
||
// Create the Providers directory | ||
err = os.MkdirAll(providersPath, 0755) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error creating Providers directory: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Write the script content to the file | ||
err = os.WriteFile(scriptFilePath, []byte(scriptContent), 0755) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error creating wrapper script: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
conceal.PrintSuccess("Wrapper script 'conceal_summon' created successfully.") | ||
conceal.PrintInfo("To use: summon --provider conceal_summon ...") | ||
} | ||
|
||
func init() { | ||
summonCmd.AddCommand(installCmd) | ||
} |
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,28 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/infamousjoeg/conceal/pkg/conceal" | ||
"github.com/infamousjoeg/conceal/pkg/conceal/keychain" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// getCmd represents the get command | ||
var showCmd = &cobra.Command{ | ||
Use: "show", | ||
Short: "Retrieves and prints secret value to STDOUT", | ||
Long: `Retrieves and prints secret value to STDOUT. This is mainly used by the Summon conceal-summon provider. | ||
Example Usage: | ||
$ conceal summon show aws/access_key_id`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := keychain.GetSecret(args[0], "stdout") | ||
if err != nil { | ||
conceal.PrintError("Failed to get secret value from keychain.") | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
summonCmd.AddCommand(showCmd) | ||
} |
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" | ||
) | ||
|
||
// getCmd represents the get command | ||
var summonCmd = &cobra.Command{ | ||
Use: "summon", | ||
Short: "Commands related to Summon integration", | ||
Long: `This command group includes commands for integrating Conceal with Summon. | ||
Example Usage: | ||
$ conceal summon install`, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(summonCmd) | ||
} |
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,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"syscall" | ||
|
||
"github.com/infamousjoeg/conceal/pkg/conceal" | ||
"github.com/infamousjoeg/conceal/pkg/conceal/keychain" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/term" | ||
) | ||
|
||
// updateCmd represents the get command | ||
var updateCmd = &cobra.Command{ | ||
Use: "update", | ||
Short: "Updates a secret value in the secret provider", | ||
Long: `Updates a secret value within the secret. | ||
Example Usage: | ||
$ conceal update | ||
$ conceal update aws/access_key_id | ||
$ echo "new_secret_value" | conceal update aws/access_key_id`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Check if secret name is empty | ||
secretName := conceal.GetSecretName(args) | ||
|
||
// Check stdin for secret value | ||
var byteSecretVal []byte | ||
info, err := os.Stdin.Stat() | ||
if err != nil { | ||
conceal.PrintError("An error occurred while checking stdin. Exiting...") | ||
} | ||
|
||
// Update 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 { | ||
// Get secret value from user | ||
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...") | ||
} | ||
} | ||
|
||
// Update secret and secret value in keychain | ||
err = keychain.UpdateSecret(secretName, byteSecretVal) | ||
if err != nil { | ||
conceal.PrintError("Failed to update secret value in keychain.") | ||
} | ||
|
||
conceal.PrintSuccess("Secret value updated successfully.") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(updateCmd) | ||
|
||
// 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") | ||
} |