Skip to content

Commit

Permalink
Enable reading the password from the config file; parse the number of…
Browse files Browse the repository at this point in the history
… rows as a test to determine if gorm could execute the query
  • Loading branch information
gdanko committed Aug 25, 2024
1 parent 1c17807 commit 752801a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/enpass/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,17 @@ func InitializeStore(logger *logrus.Logger, vaultPath string, nonInteractive boo
}

func AssembleVaultCredentials(logger *logrus.Logger, vaultPath string, keyFilePath string, nonInteractive bool, store *unlock.SecureStore) *VaultCredentials {
var (
vaultPassword = os.Getenv("MASTERPW")
vaultPasswordFromConfig = globals.GetConfig().VaultPassword
)
if vaultPasswordFromConfig != "" {
fmt.Println(111)
vaultPassword = vaultPasswordFromConfig
}

credentials := &VaultCredentials{
Password: os.Getenv("MASTERPW"),
Password: vaultPassword,
KeyfilePath: keyFilePath,
}

Expand Down Expand Up @@ -339,11 +348,14 @@ func (v *Vault) Open(credentials *VaultCredentials, logLevel logrus.Level, nocol
result Result
results []Result
)

v.db.Select("name").Table("sqlite_master").Where("type = ?", "table").Where("name = ?", "item").Find(&results)
if len(results) <= 0 {
return errors.New("could not connect to database, please check the database credentials")
}

for _, result = range results {
if result.Name != "item" {
return errors.New("could not connect to database")
return errors.New("could not connect to database, please check the database credentials")
}
}
return nil
Expand Down

0 comments on commit 752801a

Please sign in to comment.