Skip to content

Commit

Permalink
chore: removed home-dir flag from keyring options
Browse files Browse the repository at this point in the history
  • Loading branch information
ironman0x7b2 committed Sep 16, 2024
1 parent 29da382 commit a398789
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
12 changes: 0 additions & 12 deletions flags/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
const (
DefaultKeyringAppName = "sentinel"
DefaultKeyringBackend = "test"
DefaultKeyringHomeDir = ""
)

// GetKeyringAppName retrieves the "keyring.app-name" flag value from the command.
Expand All @@ -21,11 +20,6 @@ func GetKeyringBackend(cmd *cobra.Command) (string, error) {
return cmd.Flags().GetString("keyring.backend")
}

// GetKeyringHomeDir retrieves the "keyring.home-dir" flag value from the command.
func GetKeyringHomeDir(cmd *cobra.Command) (string, error) {
return cmd.Flags().GetString("keyring.home-dir")
}

// SetFlagKeyringAppName adds the "keyring.app-name" flag to the command.
func SetFlagKeyringAppName(cmd *cobra.Command) {
cmd.Flags().String("keyring.app-name", DefaultKeyringAppName, "Name of the application.")
Expand All @@ -36,14 +30,8 @@ func SetFlagKeyringBackend(cmd *cobra.Command) {
cmd.Flags().String("keyring.backend", DefaultKeyringBackend, "Keyring backend to use.")
}

// SetFlagKeyringHomeDir adds the "keyring.home-dir" flag to the command.
func SetFlagKeyringHomeDir(cmd *cobra.Command) {
cmd.Flags().String("keyring.home-dir", DefaultKeyringHomeDir, "Directory to store keys.")
}

// AddKeyringFlags adds keyring-related flags to the given cobra command.
func AddKeyringFlags(cmd *cobra.Command) {
SetFlagKeyringAppName(cmd)
SetFlagKeyringBackend(cmd)
SetFlagKeyringHomeDir(cmd)
}
12 changes: 2 additions & 10 deletions options/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ import (

// Keyring represents options for keyring creation.
type Keyring struct {
Input io.Reader // Input is the source of passphrase input.
HomeDir string // HomeDir is the directory where keys are stored.
Input io.Reader // Input is the source of passphrase input.

AppName string `json:"app_name" toml:"app_name"` // AppName is the name of the application.
Backend string `json:"backend" toml:"backend"` // Backend specifies the keyring backend to use.
HomeDir string `json:"home_dir" toml:"home_dir"` // HomeDir is the directory where keys are stored.
}

// NewKeyring creates a new Keyring instance with default values.
func NewKeyring() *Keyring {
return &Keyring{
AppName: flags.DefaultKeyringAppName,
Backend: flags.DefaultKeyringBackend,
HomeDir: flags.DefaultKeyringHomeDir,
}
}

Expand Down Expand Up @@ -146,17 +145,10 @@ func NewKeyringFromCmd(cmd *cobra.Command) (*Keyring, error) {
return nil, err
}

// Retrieve the home directory flag value from the command.
homeDir, err := flags.GetKeyringHomeDir(cmd)
if err != nil {
return nil, err
}

// Return a new Keyring instance populated with the retrieved flag values.
return &Keyring{
AppName: appName,
Backend: backend,
HomeDir: homeDir,
Input: cmd.InOrStdin(), // Use the command's input or standard input as the passphrase source.
}, nil
}

0 comments on commit a398789

Please sign in to comment.