refactor: remove confusing dual ID method pattern from Unlocker interface - Removed redundant ID() method from Unlocker interface - Removed ID field from UnlockerMetadata struct - Modified GetID() to generate IDs dynamically based on unlocker type and data - Updated vault package to create unlocker instances when searching by ID - Fixed all tests and CLI code to remove ID field references - IDs are now consistently generated from unlocker data, preventing redundancy
This commit is contained in:
@@ -131,18 +131,14 @@ func (k *KeychainUnlocker) GetDirectory() string {
|
||||
return k.Directory
|
||||
}
|
||||
|
||||
// GetID implements Unlocker interface
|
||||
// GetID implements Unlocker interface - generates ID from keychain item name
|
||||
func (k *KeychainUnlocker) GetID() string {
|
||||
return k.Metadata.ID
|
||||
}
|
||||
|
||||
// ID implements Unlocker interface - generates ID from keychain item name
|
||||
func (k *KeychainUnlocker) ID() string {
|
||||
// Generate ID using keychain item name
|
||||
keychainItemName, err := k.GetKeychainItemName()
|
||||
if err != nil {
|
||||
// Fallback to metadata ID if we can't read the keychain item name
|
||||
return k.Metadata.ID
|
||||
// Fallback to creation time-based ID if we can't read the keychain item name
|
||||
createdAt := k.Metadata.CreatedAt
|
||||
return fmt.Sprintf("%s-keychain", createdAt.Format("2006-01-02.15.04"))
|
||||
}
|
||||
return fmt.Sprintf("%s-keychain", keychainItemName)
|
||||
}
|
||||
@@ -362,12 +358,8 @@ func CreateKeychainUnlocker(fs afero.Fs, stateDir string) (*KeychainUnlocker, er
|
||||
}
|
||||
|
||||
// Step 9: Create and write enhanced metadata
|
||||
// Generate the key ID directly using the keychain item name
|
||||
keyID := fmt.Sprintf("%s-keychain", keychainItemName)
|
||||
|
||||
keychainMetadata := KeychainUnlockerMetadata{
|
||||
UnlockerMetadata: UnlockerMetadata{
|
||||
ID: keyID,
|
||||
Type: "keychain",
|
||||
CreatedAt: time.Now(),
|
||||
Flags: []string{"keychain", "macos"},
|
||||
|
||||
@@ -14,7 +14,6 @@ type VaultMetadata struct {
|
||||
|
||||
// UnlockerMetadata contains information about an unlocker
|
||||
type UnlockerMetadata struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"` // passphrase, pgp, keychain
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Flags []string `json:"flags,omitempty"`
|
||||
|
||||
@@ -40,7 +40,6 @@ func TestPassphraseUnlockerWithRealFS(t *testing.T) {
|
||||
|
||||
// Set up test metadata
|
||||
metadata := secret.UnlockerMetadata{
|
||||
ID: "test-passphrase",
|
||||
Type: "passphrase",
|
||||
CreatedAt: time.Now(),
|
||||
Flags: []string{},
|
||||
|
||||
@@ -107,13 +107,8 @@ func (p *PassphraseUnlocker) GetDirectory() string {
|
||||
return p.Directory
|
||||
}
|
||||
|
||||
// GetID implements Unlocker interface
|
||||
// GetID implements Unlocker interface - generates ID from creation timestamp
|
||||
func (p *PassphraseUnlocker) GetID() string {
|
||||
return p.Metadata.ID
|
||||
}
|
||||
|
||||
// ID implements Unlocker interface - generates ID from creation timestamp
|
||||
func (p *PassphraseUnlocker) ID() string {
|
||||
// Generate ID using creation timestamp: YYYY-MM-DD.HH.mm-passphrase
|
||||
createdAt := p.Metadata.CreatedAt
|
||||
return fmt.Sprintf("%s-passphrase", createdAt.Format("2006-01-02.15.04"))
|
||||
|
||||
@@ -413,7 +413,6 @@ Passphrase: ` + testPassphrase + `
|
||||
|
||||
// Set up test metadata
|
||||
metadata := secret.UnlockerMetadata{
|
||||
ID: fmt.Sprintf("%s-pgp", keyID),
|
||||
Type: "pgp",
|
||||
CreatedAt: time.Now(),
|
||||
Flags: []string{"gpg", "encrypted"},
|
||||
|
||||
@@ -106,18 +106,14 @@ func (p *PGPUnlocker) GetDirectory() string {
|
||||
return p.Directory
|
||||
}
|
||||
|
||||
// GetID implements Unlocker interface
|
||||
// GetID implements Unlocker interface - generates ID from GPG key ID
|
||||
func (p *PGPUnlocker) GetID() string {
|
||||
return p.Metadata.ID
|
||||
}
|
||||
|
||||
// ID implements Unlocker interface - generates ID from GPG key ID
|
||||
func (p *PGPUnlocker) ID() string {
|
||||
// Generate ID using GPG key ID: <keyid>-pgp
|
||||
gpgKeyID, err := p.GetGPGKeyID()
|
||||
if err != nil {
|
||||
// Fallback to metadata ID if we can't read the GPG key ID
|
||||
return p.Metadata.ID
|
||||
// Fallback to creation time-based ID if we can't read the GPG key ID
|
||||
createdAt := p.Metadata.CreatedAt
|
||||
return fmt.Sprintf("%s-pgp", createdAt.Format("2006-01-02.15.04"))
|
||||
}
|
||||
return fmt.Sprintf("%s-pgp", gpgKeyID)
|
||||
}
|
||||
@@ -290,12 +286,8 @@ func CreatePGPUnlocker(fs afero.Fs, stateDir string, gpgKeyID string) (*PGPUnloc
|
||||
}
|
||||
|
||||
// Step 9: Create and write enhanced metadata
|
||||
// Generate the key ID directly using the GPG key ID
|
||||
keyID := fmt.Sprintf("%s-pgp", gpgKeyID)
|
||||
|
||||
pgpMetadata := PGPUnlockerMetadata{
|
||||
UnlockerMetadata: UnlockerMetadata{
|
||||
ID: keyID,
|
||||
Type: "pgp",
|
||||
CreatedAt: time.Now(),
|
||||
Flags: []string{"gpg", "encrypted"},
|
||||
|
||||
@@ -10,7 +10,6 @@ type Unlocker interface {
|
||||
GetType() string
|
||||
GetMetadata() UnlockerMetadata
|
||||
GetDirectory() string
|
||||
GetID() string
|
||||
ID() string // Generate ID from the unlocker's public key
|
||||
GetID() string // Generate ID based on unlocker type and data
|
||||
Remove() error // Remove the unlocker and any associated resources
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user